【问题标题】:Could not find a part of the path excel error找不到部分路径excel错误
【发布时间】:2016-04-12 11:42:38
【问题描述】:

我想将datatable 绑定到excel。我为此编写了以下代码

public void ExportExcel()
{
   string str_lwpc_query = string.Empty;
   str_lwpc_query = "select company_name 'COMPANY NAME',Deputed_Company_Name 'DEPUTED COMPANY NAME',emp_card_no 'EMP CODE',emp_name 'EMPLOYEE NAME',LWP,'' Remarks,  " +
                    "Adj_Days Gain_Loss_LOP_Days, VAL_DAY LOP_Days_Desc, month, year from XXACL_EMP_INFO_LWP_OTDAYS_HRS_V " +
                     "where emp_type='C' and month = '3' and year = '2015'";

     DataTable Dt_lwpc = new DataTable();
     //DT_Overdue.TableName = "Daily Lead";
     Dt_lwpc = CF.ExecuteDT(str_lwpc_query);
     DataSet DS_lwpc = new DataSet();
     DS_lwpc.Tables.Add(Dt_lwpc);
     DS_lwpc.Tables[0].TableName = "Employee loss of pay for consultant Details";
     ExcelLibrary.DataSetHelper.CreateWorkbook("~/Attachment/Employee_lwpc_Details.xls", DS_lwpc);

}

但我收到错误

找不到路径“C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\~\Attachment\Employee_lwpc_Details.xls”的一部分。

在最后一行。不知道为什么

【问题讨论】:

    标签: c# asp.net excel


    【解决方案1】:

    用户 Server.MapPath 并获取与您的网站运行位置相关的目录。

    var directory = Server.MapPath("~/Attachment/");
    ExcelLibrary.DataSetHelper.CreateWorkbook(directory + "Employee_lwpc_Details.xls", DS_lwpc);
    

    这假设附件目录存在,否则您可能需要创建它。

    【讨论】:

    • 问一个新问题,但它可能会因为它不是编程问题而被关闭:)
    猜你喜欢
    • 1970-01-01
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    • 2017-09-10
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    相关资源
    最近更新 更多