一般Excel匯出功能

2021-07-24 18:45:57 字數 3638 閱讀 5241

public class excelutil 

// 產生**標題行

hssfrow row = sheet.createrow(0);

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

if (null == datalist)

for (int i = 0; i < datalist.size(); i++) else }}

workbook.write(os);

} catch (exception e) finally catch (ioexception e) }}

/***

* @param datalist 資料列表

* @param headers 表頭

* @param os 輸出流

*/public static void collectexport(list> datalist, string title, string headers, outputstream os)

hssfrow row1 = sheet.createrow(0);

sheet.addmergedregion(new cellrangeaddress(0, 0, 0, headers.length - 2));

hssfcell cel1 = row1.createcell(0);

cel1.setcellstyle(style);

cel1.setcellvalue(title);

// 產生**標題行

hssfrow row = sheet.createrow(1);

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

if (null == datalist)

for (int i = 0; i < datalist.size(); i++) else }}

workbook.write(os);

} catch (exception e) finally catch (ioexception e) }}

/*** 從物件中取出展示的值

* @param fieldnames

* @param list

* @param cls

* @return

*/public static list> transobjtostring(string fieldnames, listlist, class<?> cls)

list> datalist = new arraylist>();

for (int j = 0; j < list.size(); j++) catch (exception e)

}datalist.add(data);

}return datalist;

}/**

* 獲取物件的特定值

* @param gbm

* @param fieldname

* @param cls

* @return

* @throws exception

*/private static string getvalues(object gbm, string fieldname, class<?> cls) throws exception

if (null != o && o instanceof sysorgperson)

if (null != o && o instanceof sysorgelement)

if (o != null && o instanceof org.hibernate.collection.persistentbag)

if (obj instanceof sysorgperson) }}

returnvalue = o == null ? "" : returnvalue;

return returnvalue;

} catch (exception e)

}/**

* 根據屬性名獲取屬性

* @param fields

* @param fieldname

* @return

*/public static field findfield(field fields, string fieldname)

}return field;

}/**

* 過濾掉非form屬性

* @param fields

* @return

*/public static field filterfield(field fields)

}fields = new field[count];

for (int i = 0; i < count; i++)

return fields;

}/**

* 獲取form屬性名

* @param fields

* @return

*/public static string filednames(field fields)

string filednames = new string[fields.length];

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

return filednames;

}/**

* 獲取國際化資源中類屬性名對應的值

data1.add("張三");

data1.add("男");

data1.add("1989-11-12");

data1.add("88");

listdata2 = new arraylist();

data2.add("李四");

data2.add("男");

data2.add("1992-02-23");

data2.add("75");

list> list = new arraylist>();

list.add(data1);

list.add(data2);

outputstream os = null;

try catch (filenotfoundexception e)

collectexport(list, "彙總", headers, os);

}}

excel匯出功能

1 pom.xml匯入依賴 org.apache.poi poi org.apache.poi poi ooxml 本地倉庫位置 2 controller apioperation value 分析資料 匯出 httpmethod get notes 說明 匯出csv格式資料 response st...

poi 生成excel報表一般步驟

表題 表頭 資料 合併區域 是否顯示網格線 行號 外邊框加粗 內邊框普通 設定列印區域 列印設定 public static workbook getworkbook projectstatreporter reporter y資料 for int i 0 i 合併區域 sheet.addmerge...

delphi對於excel的一般操作

單元格設定 1.設定單元格線框 excel.activesheet.range b10 c13 borders n linestyle xlnone excel.activesheet.range b10 c13 borders n weight xlthin 邊框的型別 borders n xle...