zoukankan      html  css  js  c++  java
  • POI根据EXCEL模板,修改内容导出新EXCEL (只支持HSSF)

    package excelPoiTest;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;
    
    /**
     * @author Gerrard
     * @Discreption 根据已有的Excel模板,修改模板内容生成新Excel
     */
    public class CreateExcel {
    
    	public static void main(String[] args) throws IOException {
    		
    		//excel模板路径
    		File fi=new File("D:\test.xls");
    		POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(fi));
    		//读取excel模板
    		HSSFWorkbook wb = new HSSFWorkbook(fs);
    		//读取了模板内所有sheet内容
    		HSSFSheet sheet = wb.getSheetAt(0);
    		//在相应的单元格进行赋值
    		HSSFCell cell = sheet.getRow(1).getCell(3);
    		cell.setCellValue("测试");
    		HSSFCell cell2 = sheet.getRow(3).getCell(3);
    		cell2.setCellValue("数据");
    		HSSFCell cell3 = sheet.getRow(0).getCell(0);
    		cell3.setCellValue("大标题");	
    		//修改模板内容导出新模板
    		FileOutputStream out = new FileOutputStream("D:/export.xls");
    		wb.write(out);
    		out.close();
    	}
    }
    

     模板风格不变,只是修改内容,生成新EXCEL,原模板不变

  • 相关阅读:
    jquery动画效果---animate()--滚屏
    一个前端的自我修养
    开发和测试
    jquery.find()
    c99和c++11的差异之一
    容器经典图
    C/C++中的##用法
    【心学.悟道】千圣皆过影,良知乃吾师
    memcpy, memset代码改写的方式
    三大软件原则
  • 原文地址:https://www.cnblogs.com/toSeeMyDream/p/4702795.html
Copyright © 2011-2022 走看看