java—从文本文件中读取泰语字符并使用ApachePOI写入excel

qncylg1j  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(273)

我正在阅读包含英文和泰语字符的.txt文件,并在excel中编写这些行。但有些行中泰语字符正在excel中打印垃圾值。由于将有多个文件,我正在阅读将其添加到arraylist(稍后将更改为treemap)的特定内容,并使用apachepoi在excel上编写这些arraylist。下面是示例文件内容、java代码和excel屏幕截图。谢谢你的帮助。
示例文件内容:D000003001101449620876436327 siriyakon tri 24112024112006100000037343atm
D00000310101154449620641542361107นางสุชาวดี กระเทศ 650283977 24112024112003900000059064csh公司
代码:

File folder = new File("D:\\Files");
            File[] listOfFiles = folder.listFiles();
            for (File file : listOfFiles) {
                FileInputStream fis = new FileInputStream(file);
                 InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
            BufferedReader br = new BufferedReader(isr); }
                 else
                 { if (line.startsWith("D"))
                         {
                            String str = line.substring(21,31);
                            subscribernolist.add(str);
                            custnolist.add(line.substring(76,85));
                            customernamelist.add((String) line.substring(36,49));
                         }
 }                   
            }                
            }               
             int currentRow = 0;
                Workbook workbook=new XSSFWorkbook();
                Sheet sheet = workbook.createSheet("Merge Data");
                Row rowheader = sheet.createRow(currentRow);
                Row row;
   rowheader.getCell(0).setCellValue("CUST NO.");
  rowheader.getCell(1).setCellValue("SUBSCRIBER NO.");
rowheader.getCell(2).setCellValue("CUST NAME");       
                    currentRow++;

                for (int counter = 0; counter < customernamelist.size(); counter++) {
                     row = sheet.createRow(currentRow);
                    row.createCell(0).setCellValue(custnolist.get(counter));
                    row.createCell(1).setCellValue(subscribernolist.get(counter));
                    row.createCell(2).setCellValue(customernamelist.get(counter));
                    currentRow++;
                }
                sheet.autoSizeColumn(3);
                FileOutputStream fileOut = new FileOutputStream(new File ("D:\\Files\\merge.xlsx"));
                workbook.write(fileOut);
                fileOut.close();
                workbook.close();
}

excel编写如下

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题