【问题标题】:How to change saveAs to be Download file [Microsoft.Office.Interop.Excel] C#如何将 saveAs 更改为下载文件 [Microsoft.Office.Interop.Excel] C#
【发布时间】:2017-06-24 13:51:35
【问题描述】:

我已成功使用数据集中的互操作创建 excel 文件。但我使用硬编码网址创建另存为。我想让 saveAs Url 成为显示弹出窗口的下载文件 openWith 并保存文件文件。当 saveAs 文件保存到下载文件夹时。

....
xlWorkBook.SaveAs("d:\\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
        xlApp.Quit();
....

请帮我解决这个问题。

【问题讨论】:

    标签: c# excel dataset excel-interop downloadfile


    【解决方案1】:

    您可以使用“路径”属性来获取正确的路径。

    private void WorkbookSaveAs()
    {
        if (this.FileFormat == Excel.XlFileFormat.xlWorkbookNormal)
        {
            this.SaveAs(this.Path + @"\XMLCopy.xls",
            Excel.XlFileFormat.xlXMLSpreadsheet, missing, missing,
            false, false, Excel.XlSaveAsAccessMode.xlNoChange,
            missing, missing, missing, missing, missing);
    }
    }
    

    希望这会有所帮助!

    【讨论】:

    • 对不起它没有运行 if 子句@DirkHubregtse
    【解决方案2】:
    private void button1_Click(object sender, EventArgs e)
    {
        SaveFileDialog savefile = new SaveFileDialog();
        if (savefile.ShowDialog() == DialogResult.OK)
        {
            xlWorkBook.SaveAs("" + savefile.FileName + ".xlsx");
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
            xlWorkSheet = null;
            xlWorkBook = null;
            xlApp = null;
            GC.Collect();
        }
    }
    

    【讨论】:

    • 抱歉这段代码没有显示弹出保存窗口,也没有将我的 excel 保存到@imsome1
    • 我更改了代码以添加 SaveFileDialog,请立即检查该代码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-01
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    相关资源
    最近更新 更多