Same Apache poi (excel) code acting differently de

2019-08-22 05:13发布

问题:

I have successfully generated an excel file using apache poi 3.10, the program only runs as expected on 32bit systems.

BUT when tried to run it on 64bit systems, most of the cells data are left out, they simply don't show up (but the same code will work just fine on 32bit systems). what can I do so that all the generated cell data can show even on 64bit systems?

HSSFWorkbook my_xls_workbook = new HSSFWorkbook(input_document);
HSSFSheet my_worksheet = my_xls_workbook.getSheetAt(0);

Cell cell = null;
cell = my_worksheet.getRow(0).getCell(10);
cell.setCellValue(nme.getText());                              
cell = my_worksheet.getRow(3).getCell(6);
cell.setCellValue(frm.getText);
cell = my_worksheet.getRow(4).getCell(3);
cell.setCellValue(empid);

//Closing InputStream
input_document.close();

FileOutputStream output_file =new FileOutputStream(new File("C:PayslipG.xls"));

//write data
my_xls_workbook.write(output_file);
//closing stream
output_file.close();

Thanks!

回答1:

Promoting some comments to an answer - Java should be platform and architecture agnostic. Unless you're doing platform-specific code, eg AWT or Swing, there shouldn't be any differences between runtime platforms

The one thing the can differ between machines, however, is the classpath. Make sure you really have the same code and the same jars on both machines!

A sadly common problem is for runtimes, frameworks etc to silently bundle outdated copies of Apache POI without telling you. If you make use of the code included in the Apache POI FAQ Entry, you can check which POI jars you are really using at runtime.

As per the comments, those jars aren't the ones you think you are using. As per this other POI FAQ, mixing POI jars between versions isn't supported. Remove the older POI jars as identified, so you only use the latest ones, and your code will behave correctly