C NPIO匯出 動態匯出為Excel公升級版

2021-10-09 02:00:16 字數 3625 閱讀 3876

之前的動態匯出,當資料大於xls的最大行數時回出現錯誤

我在之前的基礎上進行了改進

using npoi.hssf.usermodel;

using npoi.ss.usermodel;

using npoi.ss.util;

using system;

using system.collections.generic;

using system.data;

using system.io;

using system.linq;

using system.text;

using system.web;

///

/// exclehelper 的摘要說明

///

public

class

exclehelper

///

/// 檔名稱

///

public

string filename

///

/// sheet,列,資料來源

///

public list sheetcolumnlist

///

/// 匯出excle

///

//public string excle(string filepath,string filename, listsheetcolumnlist)

public

string

excle

(string filename, list sheetcolumnlist)

//設定新建檔案路徑及名稱

var newfile = path + filename +

".xls"

;using

(var fs =

newfilestream

(newfile, filemode.create, fileaccess.write)

) sheetlist.

add(shee)

;// sheet = shee;

}//int sheet_i = (j / 65335);

int sheet_i = sheetlist.

count()

-1; j++

;isheet sheet = sheetlist[sheet_i]

;//獲取最後應該sheet

int rounumber = j % rowmax;

if(rounumber==0)

irow row =

(hssfrow)sheet.

createrow

(rounumber)

;//建立資料行

//迴圈填充列

for(

var i =

0; i < columnlist.count; i++)}

for(

var i =

0; i < columnlist.count; i++)}

} workbook.

write

(fs)

;return newfile;}}

//public

///

/// 自適應寬度

///

///

///

public

void

selfwidth

(isheet sheet,

int columnnum)

} sheet.

setcolumnwidth

(columnnum, columnwidth *

256);}

///

/// 自適應高度

///

///

public

void

selfheight

(isheet sheet)}}

///

/// 乙個sheet和這個sheet的列

///

public

class

exclesheetcolumndata

///

/// 展示得列

///

public list columnlist

///

/// 資料來源

///

public

dataset datalist

}///

/// 列

///

public

class

exclecolumn

///

/// 列名

///

public

string columnvalue

}

exclehelper excle =

newexclehelper()

; list sheetcolumns =

newlist

<

exclesheetcolumndata

>()

;//乙個exclesheet代表乙個sheet

exclesheetcolumndata exclesheet =

newexclesheetcolumndata()

; exclesheet.sheetname =

"第乙個sheet1"

; exclesheet.datalist =

new().

(bind()

);//當前這個sheet所展示的資料 所繫結的是乙個dataset

list columns =

newlist

<

exclecolumn

>()

; exclecolumn() );

columns.

add(

newexclecolumn()

);columns.

add(

newexclecolumn()

);columns.

add(

newexclecolumn()

);columns.

add(

newexclecolumn()

);columns.

add(

newexclecolumn()

);exclesheet.columnlist = columns;

sheetcolumns.

add(exclesheet)

;//exclesheetcolumndata exclesheet2 = new exclesheetcolumndata();

//.....

//....

//返回的是文件的儲存的位置(路徑)

string filepath = excle.

excle

("有效專利彙總"

, sheetcolumns)

;outputexcel

(filepath)

;

C NPIO匯出 動態匯出為Excel

using npoi.hssf.usermodel using npoi.ss.usermodel using system using system.collections.generic using system.data using system.io using system.linq us...

springboot JXL實現匯出excel

一.新增匯出工具類 二.controller層 匯出返傭日誌資訊,前端傳exporttype 1,2,3 或者直接寫乙個方法,只匯出一種型別 param response param record return 匯出返傭日誌資訊 三.service層 匯出返傭日誌資訊 匯出返傭日誌明細資訊 匯出返傭...

把GridView中選中的行匯出為Excel檔案

01 datatable dt new datatable 02 dt.columns.add empid 03 dt.columns.add empname 04foreach gridviewrow row in gridview1.rows 05 17 18 gridview gridview...