• linux poi生成excel demo调试附调用代码


    1.下载poi-3.9-20121203.jar包

    2.java code

    package com.userpackage;
    
    import java.io.FileOutputStream;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    
    
    public class ExcelDemo {
    	public static void main(String[] args) {
    		final HSSFWorkbook wb = new HSSFWorkbook();
    		for (int i = 0; i < 5; i++) {
    			final HSSFSheet sheet = wb.createSheet("result" + "_" + i);
    			HSSFRow row;
    			for (int rowId = 0; rowId < 10; rowId++) {
    				row = sheet.createRow(rowId);
    				HSSFCell cell = null;
    				for (int colId = 0; colId < 10; colId++) {
    					cell = row.createCell(colId);
    					cell.setCellValue("row" + rowId + "col" + colId);
    				}
    			}
    		}
    
    		final SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHH24mmssSSS");
    		final String formatStr = formatter.format(new Date());
    
    		final String fileName = "exceldemo" + formatStr + ".xls";
    		try {
    			final FileOutputStream xlsStream = new FileOutputStream(fileName);
    			wb.write(xlsStream);
    			xlsStream.flush();
    			xlsStream.close();
    		} catch (final Exception e) {
    			e.printStackTrace();
    		}
    
    	}
    }
    

     3.调用代码

    mc11>java -cp /home/ap/user/webproject/web.war/WEB-INF/lib/*:. com.userpackage.ExcelDemo
    

     说明:/home/ap/user/webproject/web.war/WEB-INF/lib/ 放poi包的目录,多个目录用冒号分隔,最后一个圆点表示当前路径

    当前路径:/home/ap/user/webproject/web.war/WEB-INF/classes

    ExcelDemo路径:/home/ap/user/webproject/web.war/WEB-INF/classes/com/userpackage/ExcelDemo

    生成excel文件路径:/home/ap/user/webproject/web.war/WEB-INF/classes/exceldemo20100805.xls

  • 相关阅读:
    JS 深拷贝方法
    数字图像处理中的混叠
    RoIAlign理解
    关于python项目vscode 提示import could not be resolved的问题解决
    HTTPS网站证书申请,HTTPS的安全特性
    使用多域名SSL证书 一种免费的证书申请方式
    During secondary validation: DNS problem: query timed out looking up CAA for ***
    The Next Gen Database Servers Powering Let's Encrypt
    Jenkins 构建及回滚任务
    Go优雅追踪堆栈错误包
  • 原文地址:https://www.cnblogs.com/pu20065226/p/9804195.html
Copyright © 2020-2023  润新知