i系统写excel

这里写excel采用了POI工具。表报导出excel有二种,一种是xls,一种是xlsl。
定义一个接口 ReportsToExcel


public interface ReportsToExcel {
    
    /**
     * 设置sheet的命名规则
     * @param sheetNameRule
     */
    public void setSheetNameRule(String sheetNameRule);
    
    /**
     * 将指定报表导出为excel
     * @param ReportsToExcelParameters 设置导出的参数
     * @return 返回值为zip包地址
     * @throws IOException 
     */
    public String exportToExcel(ReportsToExcelParameters reportsToExcelParameters) throws Exception;
    
    /**
     * 导出指定userdata的数据为excel
     * @param task
     * @param reports
     * @param userdata
     * @param out
     * @throws Exception
     */
    public void exportToExcel(Task task, String[] reports, UserData userdata, OutputStream out) throws Exception;
    
}
4976516-4b416e43ec10f68f.png
TIM截图20190606151030.png

工厂方法如下

public class ReportsToExcelFactory {
    public final static String EXCEL2003 = "xls";

    public final static String EXCEL2007 = "xlsx";

    public static ReportsToExcel create(String excelType) {
        if (EXCEL2003.equalsIgnoreCase(excelType)) {
            return createReportsToExcel2003();
        }
        else if (EXCEL2007.equalsIgnoreCase(excelType)) {
            return createReportsToExcel2007();
        }
        return null;
    }

    public static ReportsToExcel createReportsToExcel2003() {
        return new ReportsToExcelImplXls();
    }

    public static ReportsToExcel createReportsToExcel2007() {
        return new ReportsToExcelImplXlsx();
    }
}

其它就是细节性的实现了,在XlsWriterUtil 类的writefile方法中,写excel文件,不过表报分二种,基本表,变长表,同时还要考虑表样的东西,细节东西一堆,坑也不少。

转载于:https://www.jianshu.com/p/67e2708ab3c9

猜你喜欢

转载自blog.csdn.net/weixin_34268579/article/details/91074317
今日推荐