JExcel中的编码问题
我正在使用 JExcel 在 GAE/Java 应用程序中加载一个 excel 文件,如下所示:
上传文件的 html 表单是这样的:
<form id="" action="/save" method="post" enctype="multipart/form-data" accept-charset="ISO-8859-1">
<input name="file" type="file" value="load"/>
<input type="submit"value="load excel"/>
</form>
在服务器中我有:
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream stream = item.openStream();
if (!item.isFormField()) {
//if it's not a form field it's a file
Workbook workbook = Workbook.getWorkbook(stream);
...
String name = sheet.getCell(COL_NUMBER, row).getContents();
}
}
问题是,如果我在单元格中写入类似 ' city ó',当它在服务器中读取变量名称为“city ?”时。编码不正确。
我尝试更改accept-charset =“ISO-8859-1”(将其设置为utf-8或将其删除)但没有成功。
谁能告诉我如何解决这个问题。
谢谢
I am loading an excel file in an GAE/Java application with JExcel like this:
The html form to upload the file islike this:
<form id="" action="/save" method="post" enctype="multipart/form-data" accept-charset="ISO-8859-1">
<input name="file" type="file" value="load"/>
<input type="submit"value="load excel"/>
</form>
and in the server I have:
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream stream = item.openStream();
if (!item.isFormField()) {
//if it's not a form field it's a file
Workbook workbook = Workbook.getWorkbook(stream);
...
String name = sheet.getCell(COL_NUMBER, row).getContents();
}
}
The problem is that if I write in the cell something like 'city ó' when it reads in the server the variable name is ' city ?'. The encoding is not OK.
I've tried to change accept-charset="ISO-8859-1" (setting it to utf-8 or removing it) but with no success.
Can anyone tell me how could I solve this problem.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,我通过这样做得到了它:
OK, I got it by doing this:
WorkbookSettings 将查找系统属性 jxl.encoding
如果您无法轻松访问 WorkbookSettings(即来自 Drools- ExcelParser),您可能会发现这更好。
WorkbookSettings will look for system property jxl.encoding
If you don't have easy access to WorkbookSettings (i.e. coming from Drools- ExcelParser) you might find this preferable.
首先,确保您使用的是最新版本的 POI(例如 3.7 或 3.8 beta 2)。非常旧的 POI 版本确实存在编码问题,但只要您使用的是新版本,那么这就不应该是您的问题。
接下来,在本地计算机上,针对该文件运行 org.apache.poi.hssf.extractor.ExcelExtractor 之类的内容。这将让您确认 POI 正在正确处理编码。运行它
假设工作正常,那么您就知道您的问题出在 Google App Engine 中。
First up, make sure you're using a recent version of POI (something like 3.7 or 3.8 beta 2). Very old versions of POI did have encoding problems, but as long as you're on a new one then that shouldn't be your issue.
Next, on your local machine, run something like org.apache.poi.hssf.extractor.ExcelExtractor against the file. This will let you confirm that POI is handling the encoding correctly. Run it with
Assuming that works fine, then you know your issue is within Google App Engine.