asp.net中利用NPOI匯出資料到excel中
asp.net中利用NPOI實現匯出DataSet到Excel中,首先下載對應的dll,下載地址:http://download.csdn.net/detail/taomanman/8865699
將其新增到專案引用中。
下面給出一個方法NPOIHelper.cs,程式碼如下:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Reflection;
using System.Text;
using NPOI;
using NPOI.HPSF;
using NPOI.HSSF;
using NPOI.SS.UserModel;
using NPOI.HSSF.UserModel;
using NPOI.SS.Util;
using NPOI.POIFS;
using NPOI.Util;
using NPOI.HSSF.Util;
using NPOI.XSSF.UserModel;
/// <summary>
///NPOIHelper 的摘要說明
/// </summary>
public class NPOIHelper
{
#region 由DataSet、DataTable匯出Excel
/// <summary>
/// 由DataSet匯出Excel,被外界呼叫的方法
/// </summary>
/// <param name="sourceTable">要匯出資料的DataTable</param>
/// <param name="fileName">指定Excel工作表名稱</param>
/// <param name="fileName">strType=0:普通格式 1有格式化的形式</param>
/// <returns>Excel工作表</returns>
public static void ExportDataSetToExcel(DataSet sourceDs, string fileName, string sheetName, string strType)
{
MemoryStream ms = null;
if (strType == "0")
{
ms = ExportDataSetToBasicExcel(sourceDs, sheetName) as MemoryStream;
}
else
{
ms = ExportDataSetToFormatExcel(sourceDs, sheetName) as MemoryStream;
}
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8) + ".xls");
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
HttpContext.Current.Response.End();
ms.Close();
ms = null;
}
/// <summary>
/// 由DataSet匯出Excel(基本形式)
/// </summary>
/// <param name="sourceTable">要匯出資料的DataTable</param>
/// <param name="sheetName">工作表名稱</param>
/// <returns>Excel工作表</returns>
private static Stream ExportDataSetToBasicExcel(DataSet sourceDs, string sheetName)
{
HSSFWorkbook workbook = new HSSFWorkbook();
MemoryStream ms = new MemoryStream();
string[] sheetNames = sheetName.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); //分割符
for (int i = 0; i < sheetNames.Length; i++)
{
HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet(sheetNames[i]);
// handling value.
int rowIndex = 0;
int sheetnum = 1;
foreach (DataRow row in sourceDs.Tables[i].Rows)
{
#region 建立表頭
if (rowIndex == 65535 || rowIndex == 0)
{
if (rowIndex != 0)
{
sheetnum++;
sheet = (HSSFSheet)workbook.CreateSheet(sheetNames[i] + "-" + sheetnum.ToString());
}
var headerRow = sheet.CreateRow(0);
var headStyle = workbook.CreateCellStyle();
headStyle.Alignment = HorizontalAlignment.CENTER;
var font = workbook.CreateFont();
font.FontHeightInPoints = 10;
font.Boldweight = 700;
headStyle.SetFont(font);
foreach (DataColumn column in sourceDs.Tables[i].Columns)
headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);
rowIndex = 1;
}
#endregion
#region 建立內容
HSSFRow dataRow = (HSSFRow)sheet.CreateRow(rowIndex);
foreach (DataColumn column in sourceDs.Tables[i].Columns)
{
dataRow.CreateCell(column.Ordinal).SetCellValue(row[column].ToString());
}
rowIndex++;
#endregion
}
}
workbook.Write(ms);
ms.Flush();
ms.Position = 0;
workbook = null;
return ms;
}
/// <summary>
/// 由DataSet匯出Excel(帶有格式)
/// </summary>
/// <param name="sourceTable">要匯出資料的DataTable</param>
/// <param name="sheetName">工作表名稱</param>
/// <returns>Excel工作表</returns>
private static Stream ExportDataSetToFormatExcel(DataSet sourceDs, string sheetName)
{
HSSFWorkbook workbook = new HSSFWorkbook();
MemoryStream ms = new MemoryStream();
string[] sheetNames = sheetName.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); //分割符
for (int i = 0; i < sheetNames.Length; i++)
{
HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet(sheetNames[i]);
var dateStyle = workbook.CreateCellStyle();
var format = workbook.CreateDataFormat();
dateStyle.DataFormat = format.GetFormat("yyyy-mm-dd");
//取得列寬
int[] arrColWidth = new int[sourceDs.Tables[i].Columns.Count];
foreach (DataColumn item in sourceDs.Tables[i].Columns)
{
arrColWidth[item.Ordinal] = Encoding.GetEncoding(936).GetBytes(item.ColumnName.ToString()).Length;
}
for (int k = 0; k < sourceDs.Tables[i].Rows.Count; k++)
{
for (int j = 0; j < sourceDs.Tables[i].Columns.Count; j++)
{
int intTemp = Encoding.GetEncoding(936).GetBytes(sourceDs.Tables[i].Rows[k][j].ToString()).Length;
if (intTemp > arrColWidth[j])
{
arrColWidth[j] = intTemp;
}
}
}
int rowIndex = 0;
int sheetnum = 1;
foreach (DataRow row in sourceDs.Tables[i].Rows)
{
#region 建立表頭
if (rowIndex == 65535 || rowIndex == 0)
{
if (rowIndex != 0)
{
sheetnum++;
sheet = (HSSFSheet)workbook.CreateSheet(sheetNames[i] + "-" + sheetnum.ToString());
}
var headerRow = sheet.CreateRow(0);
var headStyle = workbook.CreateCellStyle();
headStyle.Alignment = HorizontalAlignment.CENTER;
var font = workbook.CreateFont();
font.FontHeightInPoints = 10;
font.Boldweight = 700;
headStyle.SetFont(font);
//設定邊框
headStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
headStyle.BottomBorderColor = HSSFColor.BLACK.index;
headStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;
headStyle.LeftBorderColor = HSSFColor.GREEN.index;
headStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;
headStyle.RightBorderColor = HSSFColor.BLUE.index;
headStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;
headStyle.TopBorderColor = HSSFColor.ORANGE.index;
//設定背景色
headStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.LIME.index;
headStyle.FillPattern = NPOI.SS.UserModel.FillPatternType.BIG_SPOTS;
headStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.LIGHT_GREEN.index;
foreach (DataColumn column in sourceDs.Tables[i].Columns)
{
headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);
headerRow.GetCell(column.Ordinal).CellStyle = headStyle;
//設定列寬
sheet.SetColumnWidth(column.Ordinal, (arrColWidth[column.Ordinal] + 1) * 256);
}
rowIndex = 1;
}
#endregion
#region 建立內容
var dataRow = sheet.CreateRow(rowIndex);
foreach (DataColumn column in sourceDs.Tables[i].Columns)
{
var newCell = dataRow.CreateCell(column.Ordinal);
string drValue = row[column].ToString();
switch (column.DataType.ToString())
{
case "System.String"://字串型別
newCell.SetCellValue(drValue);
break;
case "System.DateTime"://日期型別
case "MySql.Data.Types.MySqlDateTime": //MySql型別
if (drValue == "0000/0/0 0:00:00" || String.IsNullOrEmpty(drValue))
{
//當時間為空,防止生成的execl 中是一串“#######”號,所有賦值為空字串
newCell.SetCellValue("");
}
else
{
DateTime dateV;
DateTime.TryParse(drValue, out dateV);
newCell.SetCellValue(dateV);
newCell.CellStyle = dateStyle;//格式化顯示
}
break;
case "System.Boolean"://布林型
bool boolV = false;
bool.TryParse(drValue, out boolV);
newCell.SetCellValue(boolV);
break;
case "System.Int16"://整型
case "System.Int32":
case "System.Int64":
case "System.Byte":
int intV = 0;
int.TryParse(drValue, out intV);
newCell.SetCellValue(intV);
break;
case "System.Decimal"://浮點型
case "System.Double":
double doubV = 0;
double.TryParse(drValue, out doubV);
newCell.SetCellValue(doubV);
break;
case "System.DBNull"://空值處理
newCell.SetCellValue("");
break;
default:
newCell.SetCellValue("");
break;
}
}
#endregion
rowIndex++;
}
//設定首行首列凍結
//第一個參數列示要凍結的列數
//第二個參數列示要凍結的行數
//第三個參數列示右邊區域可見的首列序號,從1開始計算
//第四個參數列示下邊區域可見的首行序號,也是從1開始計算
sheet.CreateFreezePane(1, 1, 0, 10);
}
workbook.Write(ms);
ms.Flush();
ms.Position = 0;
workbook = null;
return ms;
}
/// <summary>
/// 由DataTable匯出Excel,基本方法
/// </summary>
/// <param name="sourceTable">要匯出資料的DataTable</param>
/// <returns>Excel工作表</returns>
private static Stream ExportDataTableToBasicExcel(DataTable sourceTable, string sheetName)
{
HSSFWorkbook workbook = new HSSFWorkbook();
MemoryStream ms = new MemoryStream();
var sheet = workbook.CreateSheet(sheetName);
int rowIndex = 0;
int sheetnum = 1;
foreach (DataRow row in sourceTable.Rows)
{
#region 建立表頭
if (rowIndex == 65535 || rowIndex == 0)
{
if (rowIndex != 0)
{
sheetnum++;
sheet = workbook.CreateSheet(sheetName + "-" + sheetnum.ToString());
}
var headerRow = sheet.CreateRow(0);
var headStyle = workbook.CreateCellStyle();
headStyle.Alignment = HorizontalAlignment.CENTER;
var font = workbook.CreateFont();
font.FontHeightInPoints = 10;
font.Boldweight = 700;
headStyle.SetFont(font);
foreach (DataColumn column in sourceTable.Columns)
headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);
rowIndex = 1;
}
#endregion
HSSFRow dataRow = (HSSFRow)sheet.CreateRow(rowIndex);
foreach (DataColumn column in sourceTable.Columns)
{
dataRow.CreateCell(column.Ordinal).SetCellValue(row[column].ToString());
}
rowIndex++;
}
workbook.Write(ms);
ms.Flush();
ms.Position = 0;
sheet = null;
workbook = null;
return ms;
}
/// <summary>
/// 帶格式化的
/// </summary>
/// <param name="dtSource">資料來源</param>
/// <param name="sheetName">建立的Sheet名稱</param>
/// <returns></returns>
private static Stream ExportDataTableToFormatExcel(DataTable dtSource, string sheetName)
{
HSSFWorkbook workbook = new HSSFWorkbook();
var sheet = workbook.CreateSheet(sheetName);
var dateStyle = workbook.CreateCellStyle();
var format = workbook.CreateDataFormat();
dateStyle.DataFormat = format.GetFormat("yyyy-mm-dd");
//取得列寬
int[] arrColWidth = new int[dtSource.Columns.Count];
foreach (DataColumn item in dtSource.Columns)
{
arrColWidth[item.Ordinal] = Encoding.GetEncoding(936).GetBytes(item.ColumnName.ToString()).Length;
}
for (int i = 0; i < dtSource.Rows.Count; i++)
{
for (int j = 0; j < dtSource.Columns.Count; j++)
{
int intTemp = Encoding.GetEncoding(936).GetBytes(dtSource.Rows[i][j].ToString()).Length;
if (intTemp > arrColWidth[j])
{
arrColWidth[j] = intTemp;
}
}
}
int rowIndex = 0;
int sheetnum = 1;
foreach (DataRow row in dtSource.Rows)
{
#region 新建表,填充表頭,填充列頭,樣式
if (rowIndex == 65535 || rowIndex == 0)
{
if (rowIndex != 0)
{
sheetnum++;
sheet = workbook.CreateSheet(sheetName + "-" + sheetnum.ToString());
}
#region 列頭及樣式
{
var headerRow = sheet.CreateRow(0);
var headStyle = workbook.CreateCellStyle();
headStyle.Alignment = HorizontalAlignment.CENTER;
var font = workbook.CreateFont();
font.FontHeightInPoints = 10;
font.Boldweight = 700;
headStyle.SetFont(font);
//設定背景色
headStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.WHITE.index;
headStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.RED.index;
foreach (DataColumn column in dtSource.Columns)
{
headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);
headerRow.GetCell(column.Ordinal).CellStyle = headStyle;
//設定列寬
sheet.SetColumnWidth(column.Ordinal, (arrColWidth[column.Ordinal] + 1) * 256);
}
}
#endregion
rowIndex = 1;
}
#endregion
#region 填充內容
var dataRow = sheet.CreateRow(rowIndex);
foreach (DataColumn column in dtSource.Columns)
{
var newCell = dataRow.CreateCell(column.Ordinal);
string drValue = row[column].ToString();
switch (column.DataType.ToString())
{
case "System.String"://字串型別
newCell.SetCellValue(drValue);
break;
case "System.DateTime"://日期型別
case "MySql.Data.Types.MySqlDateTime": //MySql型別
if (drValue == "0000/0/0 0:00:00" || String.IsNullOrEmpty(drValue))
{
//當時間為空,防止生成的execl 中是一串“#######”號,所有賦值為空字串
newCell.SetCellValue("");
}
else
{
DateTime dateV;
DateTime.TryParse(drValue, out dateV);
newCell.SetCellValue(dateV);
newCell.CellStyle = dateStyle;//格式化顯示
}
break;
case "System.Boolean"://布林型
bool boolV = false;
bool.TryParse(drValue, out boolV);
newCell.SetCellValue(boolV);
break;
case "System.Int16"://整型
case "System.Int32":
case "System.Int64":
case "System.Byte":
int intV = 0;
int.TryParse(drValue, out intV);
newCell.SetCellValue(intV);
break;
case "System.Decimal"://浮點型
case "System.Double":
double doubV = 0;
double.TryParse(drValue, out doubV);
newCell.SetCellValue(doubV);
break;
case "System.DBNull"://空值處理
newCell.SetCellValue("");
break;
default:
newCell.SetCellValue("");
break;
}
}
#endregion
rowIndex++;
}
using (MemoryStream ms = new MemoryStream())
{
workbook.Write(ms);
ms.Flush();
ms.Position = 0;
return ms;
}
}
/// <summary>
/// 由DataTable匯出Excel
/// </summary>
/// <param name="sourceTable">要匯出資料的DataTable</param>
/// <param name="fileName">指定Excel工作表名稱</param>
/// <param name="sheetName">指定Sheet名稱</param>
/// <param name="strType">strType=0:基本的,1:帶有格式的</param>
/// <returns>Excel工作表</returns>
public static void ExportDataTableToExcel(DataTable sourceTable, string fileName, string sheetName, string strType)
{
MemoryStream ms = null;
if (strType == "0")
{
ms = ExportDataTableToBasicExcel(sourceTable, sheetName) as MemoryStream;
}
else
{
ms = ExportDataTableToFormatExcel(sourceTable, sheetName) as MemoryStream;
}
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8) + ".xls");
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
HttpContext.Current.Response.End();
ms.Close();
ms = null;
}
/// <summary>
/// 由DataTable匯出Excel(適應於基本的模版匯出,且不超過65535條)
/// </summary>
/// <param name="sourceTable">要匯出資料的DataTable</param>
/// <param name="modelpath">模版檔案實體路徑</param>
/// <param name="modelName">模版檔名稱</param>
/// <param name="fileName">指定Excel工作表名稱</param>
/// <param name="sheetName">作為模型的Excel</param>
/// <param name="rowindex">從第幾行開始寫入資料(此為行索引,若為1則從第2行開始寫入資料)</param>
/// <returns>Excel工作表</returns>
public static void ExportDataTableToExcelModel(DataTable sourceTable, string modelpath, string modelName, string fileName, string sheetName, int rowIndex)
{
int colIndex = 0;
FileStream file = new FileStream(modelpath + "/" + modelName, FileMode.Open, FileAccess.Read);//讀入excel模板
HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);
HSSFSheet sheet1 = (HSSFSheet)hssfworkbook.GetSheet(sheetName);
if (sourceTable.Rows.Count + rowIndex > 65535)
{
throw new ArgumentException("資料太多,系統尚不支援,請縮小查詢範圍!");
}
foreach (DataRow row in sourceTable.Rows)
{ //雙迴圈寫入sourceTable中的資料
colIndex = 0;
HSSFRow xlsrow = (HSSFRow)sheet1.CreateRow(rowIndex);
foreach (DataColumn col in sourceTable.Columns)
{
xlsrow.CreateCell(colIndex).SetCellValue(row[col.ColumnName].ToString());
colIndex++;
}
rowIndex++;
}
sheet1.ForceFormulaRecalculation = true;
//CS專案適用胡方法
//FileStream fileS = new FileStream(modelpath + fileName + ".xls", FileMode.Create);//儲存
//hssfworkbook.Write(fileS);
//fileS.Close();
MemoryStream ms = new MemoryStream();
hssfworkbook.Write(ms);
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8) + ".xls");
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
HttpContext.Current.Response.End();
ms.Close();
ms = null;
}
#endregion
#region 從Excel中讀資料到DataTable
/// <summary>
/// 從Excel中獲取資料到DataTable
/// </summary>
/// <param name="strFileName">Excel檔案全路徑(伺服器路徑)</param>
/// <param name="extension">Excel檔案的副檔名</param>
/// <param name="SheetName">要獲取資料的工作表名稱</param>
/// <param name="HeaderRowIndex">工作表標題行所在行號(從0開始)</param>
/// <returns></returns>
public static DataTable RenderDataTableFromExcel(string strFileName, string extension, string SheetName, int HeaderRowIndex)
{
using (FileStream file = new FileStream(strFileName, FileMode.Open, FileAccess.Read))
{
IWorkbook workbook = null;
if (extension.Equals(".xls") || extension.Equals(".XLS"))
{
workbook = new HSSFWorkbook(file);
}
else
{
workbook = new XSSFWorkbook(file);
}
return RenderDataTableFromExcel(workbook, SheetName, HeaderRowIndex);
}
}
/// <summary>
/// 從Excel中獲取資料到DataTable
/// </summary>
/// <param name="strFileName">Excel檔案全路徑(伺服器路徑)</param>
/// <param name="extension">Excel檔案的副檔名</param>
/// <param name="SheetIndex">要獲取資料的工作表序號(從0開始)</param>
/// <param name="HeaderRowIndex">工作表標題行所在行號(從0開始)</param>
/// <returns></returns>
public static DataTable RenderDataTableFromExcel(string strFileName, string extension, int SheetIndex, int HeaderRowIndex)
{
using (FileStream file = new FileStream(strFileName, FileMode.Open, FileAccess.Read))
{
IWorkbook workbook = null;
if (extension.Equals(".xls") || extension.Equals(".XLS"))
{
workbook = new HSSFWorkbook(file);
}
else
{
workbook = new XSSFWorkbook(file);
}
string SheetName = workbook.GetSheetName(SheetIndex);
return RenderDataTableFromExcel(workbook, SheetName, HeaderRowIndex);
}
}
/// <summary>
/// 從Excel中獲取資料到DataTable
/// </summary>
/// <param name="ExcelFileStream">Excel檔案流</param>
/// <param name="SheetName">要獲取資料的工作表名稱</param>
/// <param name="HeaderRowIndex">工作表標題行所在行號(從0開始)</param>
/// <returns></returns>
public static DataTable RenderDataTableFromExcel(Stream ExcelFileStream, string SheetName, int HeaderRowIndex)
{
IWorkbook workbook = new HSSFWorkbook(ExcelFileStream);
ExcelFileStream.Close();
return RenderDataTableFromExcel(workbook, SheetName, HeaderRowIndex);
}
/// <summary>
/// 從Excel中獲取資料到DataTable
/// </summary>
/// <param name="ExcelFileStream">Excel檔案流</param>
/// <param name="SheetIndex">要獲取資料的工作表序號(從0開始)</param>
/// <param name="HeaderRowIndex">工作表標題行所在行號(從0開始)</param>
/// <returns></returns>
public static DataTable RenderDataTableFromExcel(Stream ExcelFileStream, int SheetIndex, int HeaderRowIndex)
{
IWorkbook workbook = new HSSFWorkbook(ExcelFileStream);
ExcelFileStream.Close();
string SheetName = workbook.GetSheetName(SheetIndex);
return RenderDataTableFromExcel(workbook, SheetName, HeaderRowIndex);
}
/// <summary>
/// 從Excel中獲取資料到DataTable
/// </summary>
/// <param name="workbook">要處理的工作薄</param>
/// <param name="SheetName">要獲取資料的工作表名稱</param>
/// <param name="HeaderRowIndex">工作表標題行所在行號(從0開始)</param>
/// <returns></returns>
public static DataTable RenderDataTableFromExcel(IWorkbook workbook, string SheetName, int HeaderRowIndex)
{
ISheet sheet = workbook.GetSheet(SheetName);
DataTable table = new DataTable();
try
{
IRow headerRow = sheet.GetRow(HeaderRowIndex);
int cellCount = headerRow.LastCellNum;
for (int i = headerRow.FirstCellNum; i < cellCount; i++)
{
DataColumn column = new DataColumn(headerRow.GetCell(i).StringCellValue);
table.Columns.Add(column);
}
int rowCount = sheet.LastRowNum;
#region 迴圈各行各列,寫入資料到DataTable
for (int i = (sheet.FirstRowNum + 1); i < sheet.LastRowNum; i++)
{
IRow row = sheet.GetRow(i);
DataRow dataRow = table.NewRow();
for (int j = row.FirstCellNum; j < cellCount; j++)
{
ICell cell = row.GetCell(j);
if (cell == null)
{
dataRow[j] = null;
}
else
{
switch (cell.CellType)
{
case CellType.BLANK:
dataRow[j] = null;
break;
case CellType.BOOLEAN:
dataRow[j] = cell.BooleanCellValue;
break;
case CellType.NUMERIC:
dataRow[j] = cell.ToString();
break;
case CellType.STRING:
dataRow[j] = cell.StringCellValue;
break;
case CellType.ERROR:
dataRow[j] = cell.ErrorCellValue;
break;
case CellType.FORMULA:
default:
dataRow[j] = "=" + cell.CellFormula;
break;
}
}
}
table.Rows.Add(dataRow);
//dataRow[j] = row.GetCell(j).ToString();
}
#endregion
}
catch (System.Exception ex)
{
table.Clear();
table.Columns.Clear();
table.Columns.Add("出錯了");
DataRow dr = table.NewRow();
dr[0] = ex.Message;
table.Rows.Add(dr);
return table;
}
finally
{
//sheet.Dispose();
workbook = null;
sheet = null;
}
#region 清除最後的空行
for (int i = table.Rows.Count - 1; i > 0; i--)
{
bool isnull = true;
for (int j = 0; j < table.Columns.Count; j++)
{
if (table.Rows[i][j] != null)
{
if (table.Rows[i][j].ToString() != "")
{
isnull = false;
break;
}
}
}
if (isnull)
{
table.Rows[i].Delete();
}
}
#endregion
return table;
}
#endregion
}
aspx頁面中某個按鈕的點選事件程式碼如下呼叫:
DataSet ds = XXXX(); //用於獲取資料庫資料
NPOIHelper.ExportDataSetToExcel(ds, "統計報表" + DateTime.Now.ToString("yyyyMMddHHmmss"), "統計表", "0");
相關文章
- ASP.NET 匯出gridview中的資料到Excel表中,並對指定單元格換行操作ASP.NETViewExcel
- 利用Excel匯入資料到SAP C4CExcel
- Vue匯出資料到Excel電子表格VueExcel
- NPOI匯出和匯入Excel,Word和PDFExcel
- C# 實現NPOI的Excel匯出C#Excel
- 基於NPOI封裝匯出Excel方法封裝Excel
- C#快速匯出百萬級資料到Excel方法C#Excel
- .NET Core使用NPOI將Excel中的資料批量匯入到MySQLExcelMySql
- 利用跳板機連線mysql,匯出資料到csvMySql
- 基於EPPlus和NPOI實現的Excel匯入匯出Excel
- Python批量匯入Excel資料到MySQLPythonExcelMySql
- 基於Vue + axios + WebApi + NPOI匯出Excel檔案VueiOSWebAPIExcel
- Mvc 5中匯出ExcelMVCExcel
- SQLServer匯出匯入資料到MySQLServerMySql
- Python匯出資料到Excel表格-NotImplementedError: formatting_info=True not yet implementedPythonExcelErrorORM
- 分享:一個基於NPOI的excel匯入匯出元件(強型別)Excel元件型別
- .Net Core Excel匯入匯出神器Npoi.MapperExcelAPP
- 關於java中Excel的匯入匯出JavaExcel
- 將資料庫中資料匯出為excel表格資料庫Excel
- Sqoop匯出ClickHouse資料到HiveOOPHive
- NPOI建立並匯出word
- 使用Excel匯入資料到SAP Cloud for Customer系統ExcelCloud
- C#中DataGrid匯出Excel檔案C#Excel
- SpringBoot利用java反射機制,實現靈活讀取Excel表格中的資料和匯出資料至Excel表格Spring BootJava反射Excel
- 海量資料Excel報表利器——EasyExcel(一 利用反射機制匯出Excel)Excel反射
- vue + element UI 中 el-table 資料匯出Excel表格VueUIExcel
- 如何批次匯出地圖上商家店鋪資料到手機電腦excel表格地圖Excel
- vue+element + table將選中的資料匯出為excel(匯出的是當前頁選中的資料)VueExcel
- Java 匯入資料到Excel並提供檔案下載介面JavaExcel
- excel導資料到PostgresqlExcelSQL
- 【python】python初學 讀取map檔案資料到excel中PythonExcel
- waterdrop匯出hdfs資料到clickhouse(text,csv,json)JSON
- EasyPoi, Excel資料的匯入匯出Excel
- Vue中級指南-01 如何在Vue專案中匯出ExcelVueExcel
- 匯出excelExcel
- NPOI 在指定單元格匯入匯出圖片
- vue excel匯入匯出VueExcel
- Laravel5.6中使用Laravel/Excel實現Excel檔案匯出功能LaravelExcel
- Java匯出ExcelJavaExcel