如何使用java中的poi在excel中编写日语字符?
我正在使用POI编写excel工作表,但当我尝试在excel中编写日文字符时遇到了问题。将打印一些ascii字符而不是日文字符。我试过很多方法来解决这个问题,但我做不到。有人能帮我吗 这是我的密码如何使用java中的poi在excel中编写日语字符?,java,excel,character-encoding,apache-poi,Java,Excel,Character Encoding,Apache Poi,我正在使用POI编写excel工作表,但当我尝试在excel中编写日文字符时遇到了问题。将打印一些ascii字符而不是日文字符。我试过很多方法来解决这个问题,但我做不到。有人能帮我吗 这是我的密码 public void readExcel() throws IOException { workbook = new HSSFWorkbook(); worksheet = workbook.createSheet("FieldCount"); HSSFFont font =
public void readExcel() throws IOException {
workbook = new HSSFWorkbook();
worksheet = workbook.createSheet("FieldCount");
HSSFFont font = workbook.createFont();
font.setColor(HSSFFont.COLOR_RED);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
// Create the style
HSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFont(font);
HSSFRow row1 = worksheet.createRow(0);
HSSFCell cellA1 = row1.createCell((short)0);
cellA1.setCellStyle(cellStyle);
cellA1.setCellValue("Object Type");
HSSFCell cellA2 = row1.createCell((short)1);
cellA2.setCellStyle(cellStyle);
cellA2.setCellValue("Object Name");
HSSFCell cellA3 = row1.createCell((short)2);
cellA3.setCellStyle(cellStyle);
cellA3.setCellValue("Script");
HSSFCell cellA4 = row1.createCell((short)3);
cellA4.setCellStyle(cellStyle);
cellA4.setCellValue("Available Script");
HSSFCell cellA5 = row1.createCell((short)4);
cellA5.setCellStyle(cellStyle);
cellA5.setCellValue("Caption");
i = 1;
}
public void writexsl(Fields fields) {
System.out.println("\n" + i + "\n");
try {
HSSFRow row1 = worksheet.createRow(i);
HSSFCell cellA1 = row1.createCell((short)0);
cellA1.setCellValue(fields.ObjectType);
HSSFCell cellA2 = row1.createCell((short)1);
cellA2.setCellValue(fields.ObjectName);
HSSFCell cellA3 = row1.createCell((short)2);
cellA3.setCellValue(fields.Script);
HSSFCell cellA4 = row1.createCell((short)3);
cellA4.setCellValue(fields.ScriptValue);
HSSFCell cellA5 = row1.createCell((short)4);
//fields.Cation = URLEncoder.encode(fields.Cation, "UTF-8");
//fields.Cation = URLDecoder.decode(fields.Cation, "UTF-8");
cellA5.setCellValue(fields.Cation);
System.out.println("Caption Japanese" + cellA5.getStringCellValue());
i++;
System.out.println("write columns");
}
catch (Exception e) {
System.out.println("error" + e);
}
}
我用
使用此技术创建的excel文件确实包含UTF-16字符。是否确保使用最新版本的Apache POI?你确保日语字符正确地进入你的Java代码了吗?是的,我知道了。将poi版本升级到v3.9后,我在excel中获得了日文字符。谢谢你。。
HSSFRichTextString s = new HSSFRichTextString(str);
cell.setCellValue(s);