相同的 Apache poi (excel) 代码根据系统类型(32 位、64 位)表现不同 [英] Same Apache poi (excel) code acting differently depending on system types (32bit, 64bit)

查看:26
本文介绍了相同的 Apache poi (excel) 代码根据系统类型(32 位、64 位)表现不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 apache poi 3.10 成功生成了一个 excel 文件,该程序只能在 32 位系统上按预期运行.

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

但是当试图在 64 位系统上运行它时,大部分单元数据都被遗漏了,它们根本不显示(但相同的代码在 32 位系统上也能正常工作).我该怎么做才能使所有生成的单元格数据即使在 64 位系统上也能显示?

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();

谢谢!

推荐答案

将一些评论推广到一个答案 - Java 应该与平台和架构无关.除非您正在执行特定于平台的代码,例如 AWT 或 Swing,否则运行时平台之间应该没有任何区别

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

然而,机器之间可能不同的一件事是类路径.确保您在两台机器上确实拥有相同的代码和相同的 jar!

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!

一个令人遗憾的常见问题是运行时、框架等在不告诉您的情况下悄悄捆绑过时的 Apache POI 副本.如果您使用 Apache POI FAQ Entry 中包含的代码,您可以检查您在运行时真正使用了哪些 POI jar.

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.

根据评论,这些罐子不是您认为正在使用的罐子.根据 其他 POI 常见问题,不支持在版本之间混合 POI jar.删除已识别的旧 POI jar,因此您只使用最新的 POI jar,您的代码将正确运行

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

这篇关于相同的 Apache poi (excel) 代码根据系统类型(32 位、64 位)表现不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆