如何将saveAs更改为下载文件[Microsoft.Office.Interop.Excel]C#
我已成功使用数据集的互操作创建excel文件。但我使用硬代码Url创建另存为。我想使saveAs Url成为显示弹出窗口的下载文件openWith并保存文件。并在另存为文件时保存到下载文件夹如何将saveAs更改为下载文件[Microsoft.Office.Interop.Excel]C#,c#,excel,dataset,excel-interop,downloadfile,C#,Excel,Dataset,Excel Interop,Downloadfile,我已成功使用数据集的互操作创建excel文件。但我使用硬代码Url创建另存为。我想使saveAs Url成为显示弹出窗口的下载文件openWith并保存文件。并在另存为文件时保存到下载文件夹 .... xlWorkBook.SaveAs("d:\\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExc
....
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();
....
请帮助我解决此问题。您可以使用“路径”属性获取正确的路径
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);
}
}
希望这有帮助 抱歉,如果子句@Dirkhubregtse未运行,则此代码未显示弹出的保存窗口,且未将我的excel保存到@imsome1I。我已将代码更改为添加保存文件对话框,请立即检查该代码
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();
}
}