java生成excel设置列宽,汉字问题
如下代码XSSFWorkbookworkbook=newXSSFWorkbook();XSSFSheetsheet=workbook.createSheet("test"...
如下代码
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("test");
XSSFRow row = sheet.createRow(0);
for (int i = 0; i < map.size(); i++) {
row.createCell(i).setCellValue(map.get(i) + "\r\n" + "qweqwe");
sheet.setColumnWidth((short) i,(short) (map.get(i).length() *256));
}
里面sheet.setColumnWidth((short) i,(short) (map.get(i).length() *256));为设置excel列宽随map.get(i) + "\r\n" + "qweqwe"的长度而改变,但是他是依据map.get(i).length()给出的长度,我的map.get(i)里面含有汉字,所以sheet.setColumnWidth((short) i,(short) (map.get(i).length() *256))就比实际的长度短一些,有没有办法才能让他正好是map.get(i) + "\r\n" + "qweqwe"长度呢 展开
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("test");
XSSFRow row = sheet.createRow(0);
for (int i = 0; i < map.size(); i++) {
row.createCell(i).setCellValue(map.get(i) + "\r\n" + "qweqwe");
sheet.setColumnWidth((short) i,(short) (map.get(i).length() *256));
}
里面sheet.setColumnWidth((short) i,(short) (map.get(i).length() *256));为设置excel列宽随map.get(i) + "\r\n" + "qweqwe"的长度而改变,但是他是依据map.get(i).length()给出的长度,我的map.get(i)里面含有汉字,所以sheet.setColumnWidth((short) i,(short) (map.get(i).length() *256))就比实际的长度短一些,有没有办法才能让他正好是map.get(i) + "\r\n" + "qweqwe"长度呢 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询