2
我从数据库中提取俄语字符并生成一个Excel表单。但不幸的是,在提取的Excel表格中,我必须手动将字符集更改为“UNICODE(UTF-8)”,否则我无法看到俄语字符。有没有人知道如何通过java更新这个字符集(我不是要求转换值)?如何通过Java更新Excel表单的字符集
让我知道是否需要从我的结尾提供任何东西。
我从数据库中提取俄语字符并生成一个Excel表单。但不幸的是,在提取的Excel表格中,我必须手动将字符集更改为“UNICODE(UTF-8)”,否则我无法看到俄语字符。有没有人知道如何通过java更新这个字符集(我不是要求转换值)?如何通过Java更新Excel表单的字符集
让我知道是否需要从我的结尾提供任何东西。
是Apache POI
的一个选项吗?
Apache POI为您管理编码。返回的所有文字是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/