java日语字符在ReadOnlySharedStringsTable中未正确显示
我在读取Excel文件中的日语字符时遇到问题。读者的构造函数是:
public XExcelFileReader(final String excelPath) throws Exception {
this.opcPkg = OPCPackage.open(excelPath, PackageAccess.READ);
this.stringsTable = new ReadOnlySharedStringsTable(this.opcPkg);
XSSFReader xssfReader = new XSSFReader(this.opcPkg);
XMLInputFactory factory = XMLInputFactory.newInstance();
InputStream inputStream = xssfReader.getSheetsData().next();
this.xmlReader = factory.createXMLStreamReader(inputStream);
while (this.xmlReader.hasNext()) {
this.xmlReader.next();
if (this.xmlReader.isStartElement()) {
if (this.xmlReader.getLocalName().equals("sheetData"))
break;
}
}
}
此时,stringsTable具有诸如予算ヨサン
之类的日语字符,但在Excel文件中,它仅读取为予算
。有些显示在Excel文件中,但有些不显示。我不确定哪里出错了,编码是UTF-8
我正在阅读一个大的Excel文件,我尝试创建一个工作簿,但它会导致内存错误,所以不能使用它
知道哪里会出错吗
# 1 楼答案
找到了答案。将构造函数修改为:
并将stringsTable更改为SharedStringsTable。我真的不知道为什么XSSFReader必须先去。任何能解释的人都非常欢迎