How to write Japanese characters in excel using poi in java? -
i using poi write excel sheet facing trouble when try write japanese character in excel.some ascii characters printed instead of japanese . tried in many way solve can't. can 1 me.
here code.
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 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"); = 1; } public void writexsl(fields fields) { system.out.println("\n" + + "\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); } }
i use
hssfrichtextstring s = new hssfrichtextstring(str); cell.setcellvalue(s);
and excel files created using technique contain utf-16 characters.
Comments
Post a Comment