org.apache.poigroupid>
poiartifactid>
3.14-beta1version>
dependency>
public
private string headtextname;//列頭(標題)名
private string propertyname;//對應欄位名
private integer cols;//合併單元格數
private xssfcellstyle cellstyle;//單元格樣式
}this.headtextname = headtextname;
this.propertyname = propertyname;
}super();
this.headtextname = headtextname;
this.propertyname = propertyname;
this.cols = cols;
}....//get、set方法
}
/**
* 多列頭建立excel
* *@param sheetname 工作簿名稱
*@param clazz 資料來源model型別
*@param objs excel標題列以及對應model欄位名
*@param map 標題列行數以及cell字型樣式
*@return
*@throws illegalargumentexception
*@throws illegalacces***ception
*@throws invocationtargetexception
*@throws classnotfoundexception
*@throws introspectionexception
*@throws parseexception
*/public
invocationtargetexception, classnotfoundexception, introspectionexception, parseexception
public static void createfont(xssfworkbook workbook)
propertydescriptor獲取get、set詳解/**
* * @param sheet
* 工作簿
* @param map
* 每行每個單元格對應的列頭資訊
*/public
int startindex=0;//cell起始位置
int endindex=0;//cell終止位置
xssfrow row = sheet.createrow(entry.getkey());
for (int x = 0; x < excels.size(); x++) else
xssfcell cell = row.createcell(startindex-excels.get(x).getcols());
cell.setcellvalue(excels.get(x).getheadtextname());// 設定內容
if (excels.get(x).getcellstyle() != null)
cell.setcellstyle(fontstyle);
}else
cell.setcellstyle(fontstyle);}}
}}
/**
* *@param sheet
*@param map
*@param objs
*@param clazz
*/@suppresswarnings("rawtypes")
public
static
throws illegalargumentexception, illegalacces***ception, invocationtargetexception, introspectionexception,
classnotfoundexception, parseexception
}ems = map.get(maxkey);
listwidths = new arraylist(ems.size());
for (object obj : objs) else
}xssfcell cell = row.createcell(i);
if (null != fontstyle2)
cell.setcellvalue(value);
cell.setcelltype(xssfcell.cell_type_string);
cell.setcellstyle(fontstyle4);
// 獲得最大列寬
int width = value.getbytes().length * 300;
// 還未設定,設定當前
if (widths.size() <= i)
// 比原來大,更新資料
if (width > widths.get(i))
}rowindex++;
}// 設定列寬
for (int index = 0; index < widths.size(); index++)
}
public xssfworkbook exportworkbook(usermodel model) throws commonexception
map<
string, list
> resultmap = usermodel.getresultmap();//多列標題頭情況
list
new arraylist<>();
map<
integer, list
map=
new linkedhashmap<>();
xssfworkbook book =
null;
// 新增列頭資訊
map.put(0, ems);
// 新增第二列頭資訊
return resultrender.renderresult("匯出成功");
POI匯入匯出Excel
public class excelutils sheet sheet null row row null cell cell null list new arraylist 遍歷excel中所有的sheet for int i 0 i wb.getnumberofsheets i 遍歷當前shee...
POI 匯入 匯出Excel
使用form表單 enctype multipart form data 上傳excel檔案,後台接收multipartfile檔案格式。讀取excel private static final string excel xls xls private static final string exc...
POI匯入匯出Excel模板
hssfworkbook 是操作excel2003以前 包括2003 的版本,副檔名是.xls xssfworkbook 是操作excel2007的版本,副檔名是.xlsx 以xssfworkbook為例 匯出 public void getexcelbyboiler catch filenotfo...