POI向已有的Excel模版写入数据

package test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;


public class Test11 {




  public static void main(String[] args) throws Exception {
  FileInputStream fs=new FileInputStream("d:/workbook.xls");
  POIFSFileSystem ps=new POIFSFileSystem(fs);
  HSSFWorkbook wb=new HSSFWorkbook(ps);
  HSSFSheet sheet=wb.getSheetAt(0);
  HSSFRow row=sheet.getRow(0);
          System.out.println(sheet.getLastRowNum()+"  "+row.getLastCellNum());
          FileOutputStream out=new FileOutputStream("d:/workbook.xls");
  row=sheet.createRow((short)(sheet.getLastRowNum()+1));   
  row.createCell((short)0).setCellValue(22);
  row.createCell((short)1).setCellValue(11);
  row.createCell((short)2).setCellValue(11);
  row.createCell((short)3).setCellValue(11);
  row.createCell((short)4).setCellValue(11);
  row.createCell((short)5).setCellValue(11);
  row.createCell((short)6).setCellValue(11);
  row.createCell((short)7).setCellValue(11);
  row.createCell((short)8).setCellValue(11);
  row.createCell((short)9).setCellValue(33);
  out.flush();
  wb.write(out);
  out.close();
  System.out.println(row.getPhysicalNumberOfCells()+"  "+row.getLastCellNum());
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值