i system write excel

Here write excel using the POI tool. Reported in the excel table there are two, one is xls, one is xlsl.
Define an interface 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 Screenshot 20190606151030.png

Plant as follows

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();
    }
}

Other details of that achieved in writefile method XlsWriterUtil class, write excel files, but reports that are divided into two kinds, the basic table, the table becomes longer, but also consider the table kind of things, the details of a bunch of things, but also pit lot.

Reproduced in: https: //www.jianshu.com/p/67e2708ab3c9

Guess you like

Origin blog.csdn.net/weixin_34268579/article/details/91074317