// Create a new workbook Workbook workbook = new Workbook(); workbook.getActiveSheet().getRange("A:B").setColumnWidth(35); workbook.getActiveSheet().getRange("A2:B2").setHorizontalAlignment(HorizontalAlignment.Right); //Number of times to read data. int count = 10; //importData //Create a new workbook. IWorkbook importDataWorkbook = new Workbook(); //Total time consumed to import data "count-2" times. long importDataTotalTimeConsumed = 0; long importDatasw = 0; long importDataew = 0; for (int i = 0; i < count; i++) { InputStream importDataFileStream = this.getResourceStream("xlsx\\AgingReport.xlsx"); //Start time to read Excel data. importDatasw = System.currentTimeMillis(); //Import data of the range from the fileStream. Object[][] data = Workbook.importData(importDataFileStream, "Aging Report", 8, 2, 21, 7); // Assign the data to current workbook. importDataWorkbook.getWorksheets().get(0).getRange(0, 0, 21, 7).setValue(data); //End time to read Excel data. importDataew = System.currentTimeMillis(); //The operating system has a cache to open the file, and it takes time to open the file for the first time. //For the accuracy of statistics, the time of the first and last time is removed. if (i > 0 && i < count - 1) { importDataTotalTimeConsumed += (importDataew - importDatasw); } } //Average time consumed to read data using "importData" method. double importDataTimeConsumed = importDataTotalTimeConsumed / (count - 2); //Save to an excel file. (replace ByteArrayOutputStream with your file stream) importDataWorkbook.save(new ByteArrayOutputStream()); //open //Create a new workbook. IWorkbook openWorkbook = new Workbook(); //Total time consumed to open Excel file "count-2" times. long openTotalTimeConsumed = 0; long opensw = 0; long openew = 0; for (int i = 0; i < count; i++) { InputStream openFileStream = this.getResourceStream("xlsx\\AgingReport.xlsx"); //Start time to read Excel data. opensw = System.currentTimeMillis(); //Import Excel data using "open" method. openWorkbook.open(openFileStream); //End time to read Excel data. openew = System.currentTimeMillis(); //The operating system has a cache to open the file, and it takes time to open the file for the first time. //For the accuracy of statistics, the time of the first and last time is removed. if (i > 0 && i < count - 1) { openTotalTimeConsumed += (openew - opensw); } } //Average time consumed to import Excel data using "open" method. double openTimeConsumed = openTotalTimeConsumed / (count - 2); //Save to an excel file. (replace ByteArrayOutputStream with your file stream) importDataWorkbook.save(new ByteArrayOutputStream()); workbook.getActiveSheet().getRange("A1").setValue("Time consumed by ImportData method"); workbook.getActiveSheet().getRange("B1").setValue("Time consumed by Open method"); //Store the time information of ImportData mehod in cell A2. workbook.getActiveSheet().getRange("A2").setValue(importDataTimeConsumed + "ms"); //Store the time information of Open mehod in cell B2. workbook.getActiveSheet().getRange("B2").setValue(openTimeConsumed + "ms"); // Save to an excel file workbook.save("ImportDataForRange.xlsx");