小编use*_*370的帖子

如何使用POI解析Excel文件中的UTF-8字符

我一直在使用POI成功解析XLS和XLSX文件.但是,我无法从Excel电子表格中正确提取特殊字符,如中文或日文等UTF-8编码字符.我已经想出如何从UTF-8编码的csv或制表符分隔文件中提取数据,但是Excel文件没有运气.有人可以帮忙吗?

(编辑: 评论中的代码段)

HSSFSheet sheet = workbook.getSheet(worksheet); 
HSSFEvaluationWorkbook ewb = HSSFEvaluationWorkbook.create(workbook); 
while (rowCtr <= lastRow && !rowBreakOut) 
{ 
    Row row = sheet.getRow(rowCtr);//rows.next(); 
    for (int col=firstCell; col<lastCell && !breakOut; col++) { 
      Cell cell; 
      cell = row.getCell(col,Row.RETURN_BLANK_AS_NULL); 
      if (ctype == Cell.CELL_TYPE_STRING) { 
         sValue = cell.getStringCellValue(); 
         log.warn("String value = "+sValue); 
         String encoded = URLEncoder.encode(sValue, "UTF-8"); 
         log.warn("URL-encoded with UTF-8: " + encoded); 
         ....
Run Code Online (Sandbox Code Playgroud)

java excel utf-8 cjk apache-poi

7
推荐指数
2
解决办法
4万
查看次数

标签 统计

apache-poi ×1

cjk ×1

excel ×1

java ×1

utf-8 ×1