Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.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# 如何插入excel并在web服务器文件夹中另存为excel_C#_Asp.net_Webserver - Fatal编程技术网

C# 如何插入excel并在web服务器文件夹中另存为excel

C# 如何插入excel并在web服务器文件夹中另存为excel,c#,asp.net,webserver,C#,Asp.net,Webserver,我有一个excel模板文件保存在web服务器文件夹中 在单击一个按钮的情况下,我希望插入带有datatbale详细信息的excel文件,并将其另存为具有不同名称的同一文件夹中(例如使用invoicenumber)。因此,每当我选择新发票编号并单击该按钮时,应更新excel模板并将其另存为文件夹中的模板 我是这样做的: protected void Button1_Click(object sender, EventArgs e) { string invoicenum

我有一个excel模板文件保存在web服务器文件夹中

在单击一个按钮的情况下,我希望插入带有datatbale详细信息的excel文件,并将其另存为具有不同名称的同一文件夹中(例如使用invoicenumber)。因此,每当我选择新发票编号并单击该按钮时,应更新excel模板并将其另存为文件夹中的模板

我是这样做的:

  protected void Button1_Click(object sender, EventArgs e)
    {
        string invoicenumber =textbox1.text;
        string saveasfilename = "Bulkexcel" + invoicenumber +  ".xlsx";

              string connStr = "provider=Microsoft.Jet.OLEDB.4.0;Data Source='App_Data/exceltemplate.xls';Extended Properties=Excel 8.0;";
        OleDbConnection MyConnection;
        OleDbCommand MyCommand = new OleDbCommand();
        MyConnection = new OleDbConnection(connStr);
        MyConnection.Open();
        MyCommand.Connection = MyConnection;
        string sql = "Insert into [Sheet1$] (id,name) values('3','c')";
        MyCommand.CommandText = sql;
        MyCommand.ExecuteNonQuery();
        MyConnection.Close();

                   'App_Data/exceltemplate.xls'.SaveAs(MapPath("App_Data/" +  saveasfilename ))


        Label1.Text = "data inserted successfully !! ";


    }
我可以将数据插入excel模板,但无法将其保存为运行时在服务器文件夹中提供的名称


请帮帮我。

什么是“App_Data/exceltemplate.xls”。SaveAs(MapPath(“App_Data/”+saveasfilename));它向我显示了一个错误?它是保存在App_Data文件夹中的exceltemplatefile。将数据插入到此文件后,应将其另存为运行时在同一文件夹中给定的名称。实际上,您应先复制模板,然后再插入复制的模板中。否则您将修改模板。如何复制模板并将其另存为同一文件夹