简体   繁体   English

如何将saveAs更改为下载文件[Microsoft.Office.Interop.Excel] C#

[英]How to change saveAs to be Download file [Microsoft.Office.Interop.Excel] C#

I have success create excel file using interop from dataset. 我已经成功地使用数据集的互操作创建了excel文件。 But I create save as using hardcode Url. 但是我使用硬编码网址创建另存为。 I want make saveAs Url to be download file showing popup windows openWith and save file file. 我想让saveAs Url是显示弹出窗口openWith的下载文件并保存文件。 And when saveAs file save to download folder. 并且当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();
....

Please help me to solve this. 请帮我解决这个问题。

You can use the 'Path' property to get the right path. 您可以使用“路径”属性来获取正确的路径。

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

Hope this helps! 希望这可以帮助!

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用 Microsoft.Office.Interop.Excel 库的情况下在 C# 中读取 excel 文件 - How to read an excel file in C# without using Microsoft.Office.Interop.Excel libraries COMException C#Microsoft.Office.Interop.Excel - COMException C# Microsoft.Office.Interop.Excel C#MergeArea错误Microsoft.office.interop.excel - C# MergeArea Error Microsoft.office.interop.excel C# microsoft.office.interop.excel 添加图表 - C# microsoft.office.interop.excel Add Chart 使用 Microsoft.Office.Interop.Excel SaveAs 错误导出到 .xlsx - Exporting to .xlsx using Microsoft.Office.Interop.Excel SaveAs Error 如何使用C#,Microsoft.Office.Interop.Excel格式化Excel文本框以更改字体样式,大小,名称 - How to format the text box of excel to change the font style,size,name using c#,Microsoft.Office.Interop.Excel C# (Microsoft.Office.Interop.Excel),将数据另存为 Excel 2003 文件(xls) - C# (Microsoft.Office.Interop.Excel), Save Data as Excel 2003 File(xls) 如何在 C# 中使用 Microsoft.Office.Interop.Excel 在 Excel 中的矩形内写入文本 - How to write a text inside a rectangle in excel using Microsoft.Office.Interop.Excel in c# 如何从C#(Microsoft.Office.Interop.Excel)中的数据透视表对象获取可见的PivotField对象 - How to get Visible PivotField Object from a PivotTable object in C#(Microsoft.Office.Interop.Excel) 如何在 C# 中使用 Microsoft.Office.Interop.Excel 添加数据透视表过滤器 - How to add pivot table filters with Microsoft.Office.Interop.Excel in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM