[英]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.