0
我设法将数据写入单个列。 我的要求是将数据写入下一个相邻列,而不会覆盖第一列中的数据。 有什么帮助吗?使用apache poi将数据导出到excel表栏明智吗?
InputStream inp;
try {
inp = new FileInputStream("D:\\test.xls");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = null;
Cell c = null;
int rowNum=0;
Set<String> keySet = new HashSet<String>();
keySet = tushMap.keySet();
for (Entry<String, String> entry : tushMap.entrySet()) {
row=sheet.createRow((short) (sheet.getLastRowNum() + 1));
System.out.println((short) (sheet.getLastRowNum() + 1));
c = row.createCell(0);
c.setCellValue("fff");
System.out.println("fff");
System.out.println(entry.getKey() + "/" + entry.getValue());
rowNum++;
}
FileOutputStream fileOut = new FileOutputStream("D:\\test.xls");
wb.write(fileOut);
fileOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
这是写入填充第1列的代码。 填充第二列覆盖拳头1 .. PLS提出一些解决方案.. 预先感谢。
做过desierd输出that..also改变sheet.getLastRowNum()+ 1到片.getFirstRowNum()+1(+1以跳过列标题) – 2012-04-07 08:20:15
编辑是否有帮助? – 2012-04-07 08:31:33
谢谢尼廷,帮助:) – 2012-04-07 11:42:57