生成EXCEL(不使用模板)

2021-10-23 16:24:17 字數 1471 閱讀 6406

public static void main(string args) throws exception   

private static void createfirstsheet(hssfworkbook workbook)

// 設定excel第一行(標題行)

settitle(sheet, workbook);

// 設定excel第二行(字段行)

setcolumn(sheet, workbook);

} private static void createsecondsheet(hssfworkbook workbook)

} public static cellstyle gettitletyle(hssfworkbook workbook)

public static cellstyle getcolumnstyle(hssfworkbook workbook, boolean isred)

// 設定字型加粗

font.setboldweight(hssffont.boldweight_bold);

// 設定樣式;

cellstyle style = workbook.createcellstyle();

// 在樣式用應用設定的字型;

style.setfont(font);

// 設定自動換行;

style.setwraptext(false);

// 設定水平對齊的樣式為居中對齊;

style.setalignment(hssfcellstyle.align_center);

// 設定垂直對齊的樣式為居中對齊;

style.setverticalalignment(hssfcellstyle.vertical_center);

return style;

} public static cellstyle getsecondsheetstyle(hssfworkbook workbook)

public static string getexpresscompanynames() ;

return expresscompanynames;

} private static void settitle(sheet sheet, hssfworkbook workbook)

private static void setcolumn(sheet sheet, hssfworkbook workbook) ;

row columnrow = sheet.createrow(1);

columnrow.setheight((short) 480);

for (int i = 0; i < columnnames.length; i++) else

} }

生成EXCEL(不使用模板)

public static void main string args throws exception private static void createfirstsheet hssfworkbook workbook 設定excel第一行 標題行 settitle sheet,workbook...

使用jxls生成Excel模板

使用jxls生成excel模板 首先匯入依賴 net.sf.jxls jxls core 1.0.6 然後製作excel模板,list迴圈標籤處需要注意,不要把該行合併單元格 邏輯實現部分 建立乙個map用來存放實體類,或者屬性,或者list mapmap new hashmap 16 map.pu...

java poi 生成excel模板

一 手動生產excel模板 最笨的一種實現方式,不推薦使用 建立excel hssfworkbook wb new hssfworkbook 建立工作簿 hssfsheet sheet wb.createsheet title 建立表單 sheet.setdefaultcolumnwidth sho...