poi读取excel模板,修正内容之后,如何另存为新excel?

2024-11-20 18:29:57
推荐回答(2个)
回答1:

File fi=new File("D:\\20110221144419.xls");
System.out.println(11);
//创建一个工作薄
POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream(fi));
HSSFWorkbook wb=new HSSFWorkbook(fs);
int i = 0;
HSSFSheet hsheet = wb.getSheetAt(i);
if(hsheet==null)
hsheet = wb.createSheet("Sheet"+(i)+"");
HSSFPatriarch patriarch = hsheet.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0,0,512,255,(short) 1,1,(short)10,20);
patriarch.createPicture(anchor , wb.addPicture(byteArrayOut.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
fileOut= new FileOutputStream(fi);
//写入excel文件
wb.write(fileOut);
fileOut.close();

回答2:

新建一个File对象写进去