我成功使用数据集中的interop创建excel文件。但我创建另存为使用硬编码Url。我想让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();
....
请帮我解决这个问题。
答案 0 :(得分:0)
您可以使用'路径'财产以获得正确的道路。
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);
}
}
希望这有帮助!
答案 1 :(得分:0)
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();
}
}