npoi匯出excel(居中,合併單元格),excel表頭作為引數傳入
bll層:
usingsystem;
using
system.collections.generic;
using
npoi.ss.usermodel;
using
npoi.xssf.usermodel;
using
npoi.hssf.usermodel;
using
system.io;
using
system.data;
using
npoi.ss.util;
namespace
business
//////
datatable資料匯入到excel
/// ///
excel表頭陣列
///datatable資料
//////
public
int datatabletoexcel(string title, datatable data, string
sheetname)
else
//excel表頭
irow rowtitle = sheet.createrow(0
);
for (var j = 0; j < title.length; ++j)
//data
for (var i = 0; i < data.rows.count; ++i)
++count;
}workbook.write(fs);
//寫入到excel
return
count;
}catch
(exception ex)
}//////
datatable資料匯出到excel
/// ///
多表頭二維陣列
///dt資料
//////
public
int datatabletoexcel(string[,] title,datatable data, string
sheetname)
else
//表頭
for (var k = 0; k < title.getlength(0); k++)
sheet.addmergedregion(
new cellrangeaddress(0, 0, 8, 10
)); sheet.addmergedregion(
new cellrangeaddress(0, 0, 11, 14
)); }
}//data
count = title.getlength(0
);
for (var i = 0; i < data.rows.count; ++i)
++count;
}workbook.write(fs);
//寫入到excel
return
count;
}catch
(exception ex)
}}
controller**:
publicstring
createprojectexcel()
path = path +filename;
datatable data = querydata(9
);
string title = new
string ;
using (excelhelper eh = new
excelhelper(path))
return
filename;
}public
string
createexcel_tdjbqk()
,};string filename = utils.getcurrenttime() + "
.xls";
datatable dt = querydata(16
);
~/") + "
temp\\";
if (!system.io.directory.exists(path))
path = path +filename;
using (excelhelper eh = new
excelhelper(path))
return
filename;
}
html中:
$("#btn_op_search
").click(function () );
});
NPOI高效匯出Excel
using system.collections.generic using system.data using system.io using system.linq using npoi.hssf.usermodel using npoi.ss.usermodel using npoi.xssf...
NPOI匯出EXCEL樣式
public void export datarequestrequest,dataresponseresponse endregion region 單元格列值屬性樣式 for int jj 0 jj row1.cells.count jj style endregion cell.setcell...
npoi匯入匯出excel
1.匯入 將datatable資料匯入到excel中 要匯入的資料 datatable的列名是否要匯入 要匯入的excel的sheet的名稱 匯入資料行數 包含列名那一行 public int datatabletoexcel datatable data,string sheetname,bool...