如题,
利用POI向带有表头的excel模板里写入数据,
hsWorkbook.write(fos);
fos.close();
执行完后就把表头置空了,请问各位高手怎么处理?
谢谢大家。

解决方案 »

  1.   

    FileInputStream file = new FileInputStream("SampleTest.xls");
    HSSFWorkbook hsWorkbook = new HSSFWorkbook(new POIFSFileSystem(file));
    HSSFSheet hssheet = hsWorkbook.getSheetAt(0);//0页
    HSSFRow rowno = hssheet.createRow(1);//取得第一行
    HSSFCell cell = null;
    cell = rowno.createCell((short)1);
    cell.setCellValue(Integer.valueOf(1036052));
    cell = rowno.createCell((short)2);
    cell.setEncoding(HSSFCell.ENCODING_UTF_16);
    cell.setCellValue("电解\\CD110-25V-47u-M\\JC\\ROH");
    cell = rowno.createCell((short)3);
    // formating
    HSSFCellStyle cellStyle = null;
    HSSFDataFormat format = null;
    cellStyle = hsWorkbook.createCellStyle();
    format = hsWorkbook.createDataFormat();
    cellStyle.setDataFormat(format.getFormat("0.0"));
    cell.setCellStyle(cellStyle);

    cell.setCellValue(Double.valueOf(1.0));
    System.out.println("getValueJCJCJC::::"+cell.getNumericCellValue());
    cell = rowno.createCell((short)5);
    cell.setCellValue("C1");
    cell = rowno.createCell((short)4);
    cell.setCellValue(10);
    先读出来后写就行了,别创建