我已经使用 Export Excel Cocept 将我的数据从数据表和数据集中提取到 Excel 工作表中,对于每个数据表和数据集,我都准备好了一个 Excel 工作表。有什么方法可以让我使用 (c#) 在单个 Excel 工作簿中获取所有工作表
protected void UploadDataTableToExcel(DataTable dtEmp, string filename)
{
string attachment = "attachment; filename=" + filename;
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = string.Empty;
foreach (DataColumn dtcol in dtEmp.Columns)
{
Response.Write(tab + dtcol.ColumnName);
tab = "\t";
}
Response.Write("\n");
foreach (DataRow dr in dtEmp.Rows)
{
tab = "";
for (int j = 0; j < dtEmp.Columns.Count; j++)
{
Response.Write(tab + Convert.ToString(dr[j]));
tab = "\t";
}
Response.Write("\n");
}
Response.End();
}
protected void lnkExport_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataSet ds = new DataSet();
string funcName = (string)ViewState["Reports"];
if (funcName == "DataTable1")
dt = DbAccess.GetDataTable1();
else if (funcName == "DataTable2")
dt = DbAccess.GetDataTable2();
if (ds.Tables.Count > 0)
{
string strFilename = funcName + ".xls";
UploadDataSetToExcel(ds, strFilename);
}
else
{
string strFilenames = funcName + ".xls";
UploadDataTableToExcel(dt, strFilenames);
}