我有一个图像按钮,它将从数据库中提取数据并使用EPPlus将其保存到Excel文件中。当用户单击该按钮时,将触发脚本以使用OnClientClick隐藏按钮,并在保存文件后重新显示一个按钮。最初的隐藏部分正在工作,但再次使其可见不起作用。
然而,我后来发现如果我注释掉函数DumpToExcel,这是将数据表传输到Excel的函数,该按钮会再次显示。
有谁能告诉我这个问题导致了什么问题?谢谢!
DumpToExcel
private void DumpToExcel(DataSet dsReorder, DataSet dsShipment)
{
try
{
using (ExcelPackage pck = new ExcelPackage())
{
List<string> dateColumns = new List<string>()
{
"LoadingDt",
"ETAPortDt",
"ROGDate",
"DateRecd",
"ExpectedShipDt",
"LoadingDt",
"RequestDate",
"ShipDate",
"PromiseDate"
};
ExcelWorksheet ws1 = pck.Workbook.Worksheets.Add(dsReorder.Tables[0].TableName);
ws1.Cells["A1"].LoadFromDataTable(dsReorder.Tables[0], true);
using (ExcelRange rng = ws1.Cells["A1:AG1"])
{
rng.Style.Font.Bold = true;
}
ExcelWorksheet ws2 = pck.Workbook.Worksheets.Add(dsShipment.Tables[0].TableName);
ws2.Cells["A1"].LoadFromDataTable(dsShipment.Tables[0], true);
FormatWorksheetData(dateColumns, dsShipment.Tables[0], ws2);
using (ExcelRange rng = ws2.Cells["A1:AG1"])
{
rng.Style.Font.Bold = true;
}
ExcelWorksheet ws3 = pck.Workbook.Worksheets.Add(dsShipment.Tables[1].TableName);
ws3.Cells["A1"].LoadFromDataTable(dsShipment.Tables[1], true);
FormatWorksheetData(dateColumns, dsShipment.Tables[1], ws3);
using (ExcelRange rng = ws3.Cells["A1:AG1"])
{
rng.Style.Font.Bold = true;
}
ExcelWorksheet ws4 = pck.Workbook.Worksheets.Add(dsShipment.Tables[2].TableName);
ws4.Cells["A1"].LoadFromDataTable(dsShipment.Tables[2], true);
FormatWorksheetData(dateColumns, dsShipment.Tables[2], ws4);
using (ExcelRange rng = ws4.Cells["A1:AG1"])
{
rng.Style.Font.Bold = true;
}
string fileName = "RP_DataPull.xlsx";
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
Response.BinaryWrite(pck.GetAsByteArray());
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
btn_OnClick
protected void ibtnPullData_Click(object sender, ImageClickEventArgs e)
{
//Acquire "DataTable"
string cnAPStr = System.Configuration.ConfigurationManager.ConnectionStrings["conAP_SQLWeb"].ConnectionString; ;
string queryReorder = "exec uspDataPull_ReorderPointInfo";
string queryShipment = "exec uspDataPull_ShipmentsInfo";
SqlConnection cn = new SqlConnection(cnAPStr);
//ReorderPointInfo
SqlDataAdapter daReorder = new SqlDataAdapter(queryReorder, cn);
DataSet dsReorder = new DataSet();
daReorder.Fill(dsReorder);
dsReorder.Tables[0].TableName = "Reorder Point";
//ShipmentsInfo
SqlDataAdapter daShipment = new SqlDataAdapter(queryShipment, cn);
DataSet dsShipment = new DataSet();
daShipment.Fill(dsShipment);
dsShipment.Tables[0].TableName = "Items in Shipment";
dsShipment.Tables[1].TableName = "Open POs";
dsShipment.Tables[2].TableName = "Open Sos";
this.ibtnPullData.Style.Add("display", "inherit");
DumpToExcel(dsReorder, dsShipment);
}