將資料庫查詢的資訊匯出到Excel

2021-09-29 08:00:14 字數 1818 閱讀 6259

生成excel及資料

public

class

exportexcel

}}else}}

}catch

(exception e)

finally

trycatch

(ioexception e)

finally

catch

(ioexception e)}}

}}

將資料寫入到excel
public

}

生成excel和一種字型
private hssfcellstyle gethssfcellstyleone

(hssfworkbook workbook)

生成excel表及表頭資料
private hssfsheet gethssfsheet

(string title, string[

] headers, hssfworkbook workbook, hssfcellstyle style)

生成字型
private hssfcellstyle gethssfcellstyletwo

(hssfworkbook workbook)

生成**標題行
private hssfrow getrows

(string[

] headers, hssfcellstyle style, hssfsheet sheet)

return row;

}

設定每一行中的列
private

void

setcellvalue

(hssfcellstyle style2, t t, field field, hssfrow row,

int index, hssffont font3)

else}if

(textvalue != null)

else

}}

反射對映資料集欄位
private object invoke

(t t, field field)

catch

(exception e)

}

使用例項
exportexcel《要匯出的類》 exportexcel =

newexportexcel

<

>()

;string[

] headers =

newstring

;list

beans = arrays.

aslist

("要匯出的類的字段"

,"位置和上面對應"

,"一一對應"

,"字段");

//如果需要全部匯出,則不需要寫beans,下面把beans置為null即可

exportexcel.

writeexcel

("給excel取個名字"

, headers, list, beans, response)

;

C 將DateTable表資料匯出到Excel中

在visual c 中呼叫excel 並不像讀取excel 中的資料那麼容易了,因為在visual c 中呼叫excel 要使用到excel的com元件。以vs2005為例,首先新增引用 在com選項中,新增microsfot excel 11.0 objet library。然後在程式中引入命名空...

將資料庫記錄匯出到Excel模板

public class wasteexcel tabledatalist.add sheet1 getxlsx sheet1,pp 2019 10 133 public static string getxlsx listtable1,string mdlpath,string filename,...

將oracle資料庫表結構匯出到word文件

select 欄位名稱 資料型別 長度 是否為空 字段說明 預設值 from select t1.table name as 表名稱 t3.comments as 表說明 t1.column name as 欄位名稱 t1.data type as 資料型別 t1.data length as 長度...