I am creating an Excel file based on a CSV file. To read the CSV file, I use the Opencsv API and Apache POI. My csv contains line 65537.
class Test {
public static void main(String[] args) throws IOException {
Workbook wb = new HSSFWorkbook();
CreationHelper helper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("new sheet");
CSVReader reader = new CSVReader(new FileReader("SampleData.csv"));
String[] line;
int r = 0;int count=0;
while ((line = reader.readNext()) != null) {
Row row = sheet.createRow((short) r++);
count=count+1;
System.out.println("count-"+count);
for (int i = 0; i < line.length; i++)
row.createCell(i)
.setCellValue(helper.createRichTextString(line[i]));
}
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}}
when I run this program, it gives me the following error:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid row number (-32768) outside allowable range (0..65535)at org.apache.poi.hssf.usermodel.HSSFRow.setRowNum(HSSFRow.java:232)
at org.apache.poi.hssf.usermodel.HSSFRow.<init>(HSSFRow.java:86)
at org.apache.poi.hssf.usermodel.HSSFRow.<init>(HSSFRow.java:70)
at org.apache.poi.hssf.usermodel.HSSFSheet.createRow(HSSFSheet.java:205)
at org.apache.poi.hssf.usermodel.HSSFSheet.createRow(HSSFSheet.java:71)
at com.arosys.utilityclasses.Test.main(Test.java:23)Java Result: 1
I tried to track how many lines it supports, I found that it only supports 32768, and also tried for fewer lines, it works fine and creates an excel file.
please help me deal with this problem, if my csv contains line 65536, then how can I write an excel (Xls) file.
thank
source
share