如何通过Java更新Excel表格的字符集

我从数据库中提取俄罗斯字符,并生成一个Excel表。 但不幸的是,在提取excel表中,我必须手动将字符集更改为“UNICODE(UTF-8)”,否则我无法看到俄罗斯字符。 有没有人知道如何通过Java更新这个字符集(我不是要求转换的价值)?

让我知道是否需要从我的结尾提供任何东西。

Apache POI是一个选项吗?
Apache POI为您pipe理编码。 所有返回的文本是Java Unicode格式(我相信是UTF-16,而不是UTF-8)

以下是您如何阅读POI中的Excel工作表:

 try { FileInputStream file = new FileInputStream(new File("C:\\test.xls")); //Get the workbook instance for XLS file HSSFWorkbook workbook = new HSSFWorkbook(file); //Get first sheet from the workbook HSSFSheet sheet = workbook.getSheetAt(0); //Iterate through each rows from first sheet Iterator<Row> rowIterator = sheet.iterator(); while(rowIterator.hasNext()) { Row row = rowIterator.next(); //For each row, iterate through each columns Iterator<Cell> cellIterator = row.cellIterator(); while(cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch(cell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: System.out.print(cell.getBooleanCellValue() + "\t\t"); break; case Cell.CELL_TYPE_NUMERIC: System.out.print(cell.getNumericCellValue() + "\t\t"); break; case Cell.CELL_TYPE_STRING: System.out.print(cell.getStringCellValue() + "\t\t"); break; } } System.out.println(""); } file.close(); FileOutputStream out = new FileOutputStream(new File("C:\\test.xls")); workbook.write(out); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } 

资料来源: http : //viralpatel.net/blogs/java-read-write-excel-file-apache-poi/