日语字符未在 ReadOnlySharedStringsTable 中正确显示

Japanese characters not displayed properly in ReadOnlySharedStringsTable

我在阅读 Excel 文件中的日文字符时遇到问题。 reader 的构造函数是:

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 必须先走。任何可以解释的人都非常欢迎。