我开发了一个 java 应用程序,它将读取包含中文字符的 excel 文件并将其转换为多个 CSV 文件。该文件如下:
public class SplitterBean {
public static final Logger LOGGER = LoggerFactory.getLogger(SplitterBean.class);
public List<Map<String, String>> splitBody(XSSFWorkbook workbook) {
LOGGER.info("Inside SplitterBean, splitting: " + workbook.getNumberOfSheets());
Map<String, String> sheetMap = null;
List<Map<String, String>> sheetList = new ArrayList<Map<String,String>>();
int numberOfSheets = workbook.getNumberOfSheets();
XSSFFormulaEvaluator.evaluateAllFormulaCells(workbook);
for (int i = 0; i < numberOfSheets; i++) {
StringBuilder sb = new StringBuilder();
sheetMap = new HashMap<String, String>();
XSSFSheet sheet = workbook.getSheetAt(i);
String sheetName = sheet.getSheetName();
for (Row row : sheet) {
for (Cell cell : row) {
String cellValue = null;
LOGGER.info("Cell type is: " + cell.getCellType());
switch (cell.getCellType()) {
case NUMERIC:
cellValue = Double.toString(cell.getNumericCellValue());
break;
case STRING:
cellValue = cell.getStringCellValue();
break;
case BLANK:
cellValue = "";
break;
case FORMULA:
LOGGER.info("Reached formula cell, cell type is: " + cell.getCellType().toString());
switch (cell.getCellType()) {
case NUMERIC:
cellValue = Double.toString(cell.getNumericCellValue());
break;
case STRING:
cellValue = cell.getStringCellValue();
break;
case BLANK:
cellValue = "";
break;
default:
cellValue = "";
break;
}
default:
cellValue = "";
break;
}
sb.append(cellValue).append(",");
}
sb.append("\n");
}
sheetMap.put(sheetName, sb.toString());
sheetList.add(sheetMap);
}
return sheetList;
}
}
我们将项目部署为 Wildfly 17.0.1.FINAL 中的 war 文件。但是当生成 CSV 文件时,中文字符会被扭曲。我想这是由于我需要更改为 UTF-8 的服务器编码。谁能建议我如何更改 Wildfly 17.0.1.FINAL 中的服务器编码或如何解决此问题?