Java 在ReadOnlySharedStringsTable中未正确显示日语字符
我在读取Excel文件中的日语字符时遇到问题。读者的构造函数是:Java 在ReadOnlySharedStringsTable中未正确显示日语字符,java,excel,character-encoding,character,Java,Excel,Character Encoding,Character,我在读取Excel文件中的日语字符时遇到问题。读者的构造函数是: public XExcelFileReader(final String excelPath) throws Exception { this.opcPkg = OPCPackage.open(excelPath, PackageAccess.READ); this.stringsTable = new ReadOnlySharedStringsTable(this.opcPkg); XSSFReader
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文件,我尝试创建一个工作簿,但它会导致内存错误,所以不能使用它
知道哪里会出错吗?找到了答案。将构造函数修改为:
public XExcelFileReader(final String excelPath) throws Exception {
this.opcPkg = OPCPackage.open(excelPath, PackageAccess.READ);
XSSFReader xssfReader = new XSSFReader(this.opcPkg);
this.stringsTable = xssfReader.getSharedStringsTable();
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更改为SharedStringsTable。我真的不知道为什么XSSFReader必须先走一步。欢迎任何能解释的人解释。对此表示抱歉。这是Java。谢谢你的注意。介意给我上一课吗?:)