Hi,
I want to read approximately 3500 Lines, each Line 4 Cells in a Workbook, this take about 8 seconds here. Is there a way to improve this performance.Here an outline of my sourcecode:
Application myApplication = new Application();
Workbook myWorkbook = myApplication.openWorkbook(myTempFile);
Worksheet sheet = myWorkbook.getWorksheet("Outputs");
final int rowCount = sheet.getUsedRange().getRowCount();
for (int i = 9; i < rowCount; i++) {
String value = sheet.getCell(i, 7).getString();
if (value != null && !value.equals("-")) {
IDMParameter p = new IDMParameter();
p.setName(sheet.getCell(i, 2).getString());
p.setDescription(sheet.getCell(i, 1).getString());
p.setValue(value);
p.setUnit(sheet.getCell(i, 5).getString());
p.setRowId(i);
parameters.add(p);
}
}
Hi Heinrich,
Please try the new build of JExcel: ftp://ftp.teamdev.com/updates/jexcel-1.2.902.jar In this update we have added new methods in Range class that you can use to improve the reading performance:
/**
* Bulk operation method. It allows fast values extraction
* from worksheet range as a 2D Variant array [cols][rows]
*
* @return array of Variants from the range
*/
public Variant[][] getValues()
The usage of this new function is quite simple:
Application myApplication = new Application();
Workbook myWorkbook = myApplication.openWorkbook(myTempFile);
Worksheet sheet = myWorkbook.getWorksheet("Outputs");
Range range = sheet.getUsedRange();
Variant[][] values = range.getValue();
Then you will need to iterate by this 2-dimensional array and get the values from Variant objects. The value of Variant object depends on the cell type. But the general approach is following:
Variant[][] values = ;
Variant variant = values+[j];
String stringPresentation = variant.getValue().toString()
Please try this solution and let us know the results.
-Serge
Thanks, this improves the performance by a factor of approximately 5. Is there also the complete Excel API available in this version (including MsoAutomationSecurity )?
Yes, here it is: ftp://ftp.teamdev.com/updates/jexcel-1.2-full.902.jar
Please let me know if you have any further questions.
-Serge