I am trying to use jexcelAPI to programmatically convert a csv file to an excel file.
I am doing so using this method: (the CSVParser class is from: import com.Ostermiller.util.CSVParser)
public File convert2Excel(File csvFile) {
InputStream in;
File excelFile = null;
if (csvFile.exists()) {
if (csvFile.canRead()) {
in = new FileInputStream(csvFile);
} else {
throw new IOException("Could not open " + csvFile.getName());
}
} else {
throw new IOException("Could not find " + csvFile.getName());
}
String fileName = csvFile.getName().substring(0,
csvFile.getName().length() - 4);
excelFile = new File(fileName + ".xls");
WritableWorkbook workbook = Workbook.createWorkbook(excelFile);
WritableSheet sheet = workbook.createSheet(fileName, 0);
CSVParser p = new CSVParser(in);
p.setCommentStart("#;!");
p.setEscapes("nrtf", "\n\r\t\f");
String[] rowValues;
Label label = null;
int rowCount = -1;
// Performance inquery needed
while ((rowValues = p.getLine()) != null) {
rowCount++;
for (int i = 0; i < rowValues.length; i++) {
label = new Label(i, rowCount, rowValues);
sheet.addCell(label);
}
}
System.out.println("rowCount: " + rowCount);
workbook.write();
workbook.close();
return excelFile;
}
When I use this method the the xls generation goes all well. But when the number of records is set to somewhere above 300 then the resulting xls cant be opened I Excel 2003.
I receive this error from excel 2003: Excel cannot complete this task with available resources. Choose less data or close other applications.
Do you have any suggestions? Is it an issue with the jexcelAPI? Do you know of any alternative way to correctly and effectively transform a csv file to an xls?
Best regards,
Jazzmind