Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用带空格的EPPlus工作表名称导出到Excel_C#_Asp.net_Excel_Epplus - Fatal编程技术网

C# 使用带空格的EPPlus工作表名称导出到Excel

C# 使用带空格的EPPlus工作表名称导出到Excel,c#,asp.net,excel,epplus,C#,Asp.net,Excel,Epplus,我有一个工作程序,可以从数据库中提取数据,并使用EPPlus导出到Excel。但是,用户明确要求名称完全符合他们的要求,工作表名称中包含空格。 目前,我的工作表名为“Reorder_Point”,程序运行正常,但如果我将其更改为“Reorder Point”,则会出错。有人知道怎么做吗?谢谢 string cnAPStr = System.Configuration.ConfigurationManager.ConnectionStrings["conAP_SQLWeb"].Connection

我有一个工作程序,可以从数据库中提取数据,并使用EPPlus导出到Excel。但是,用户明确要求名称完全符合他们的要求,工作表名称中包含空格。 目前,我的工作表名为“Reorder_Point”,程序运行正常,但如果我将其更改为“Reorder Point”,则会出错。有人知道怎么做吗?谢谢

string cnAPStr = System.Configuration.ConfigurationManager.ConnectionStrings["conAP_SQLWeb"].ConnectionString; ;
string queryReorder = "exec uspDataPull_ReorderPointInfo";
SqlConnection cn = new SqlConnection(cnAPStr);

SqlDataAdapter daReorder = new SqlDataAdapter(queryReorder, cn);
DataSet dsReorder = new DataSet();
daReorder.Fill(dsReorder);
dsReorder.Tables[0].TableName = "Reorder_Point";

DumpToExcel(dsReorder);

private void DumpToExcel(DataSet dsReorder)
{
    try
    {
        using (ExcelPackage pck = new ExcelPackage())
        {
            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;
            }

            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);
    }
}

您可以为工作表指定一个名称,而不依赖于源列名

ws1.Name = "Reorder Point";

出于某种奇怪的原因,我所做的实际上是有效的,无论如何谢谢你的回复!