[英]How to properly save excel file, which was generated using c#?
So I use standard interface. 所以我使用标准接口。
using Excel = Microsoft.Office.Interop.Excel;
// file save function //文件保存功能
xlWorkBook.SaveAs("Bar Charts.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
Everything is fine, but file appears here C:\\Users\\Dex\\Documents
. 一切都很好,但是文件出现在这里C:\\Users\\Dex\\Documents
。 How can I change file destination true way? 如何更改文件目标的真实方式? Don't want to move it after all. 毕竟不想移动它。
Function described here http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.saveas.aspx , but there is no such parameter. 此处描述的功能http://msdn.microsoft.com/zh-cn/library/microsoft.office.tools.excel.workbook.saveas.aspx ,但是没有这样的参数。
The link you provided contains the answer: 您提供的链接包含答案:
Filename
The name of the file to be saved. 要保存的文件名。 You can include a full path; 您可以包括完整路径; if you do not, Microsoft Office Excel saves the file in the current folder. 如果不这样做,Microsoft Office Excel会将文件保存在当前文件夹中。
Use @"C:\\Another\\Folder\\Bar Charts.xls"
instead of just "Bar Charts.xls"
. 使用@"C:\\Another\\Folder\\Bar Charts.xls"
而不只是"Bar Charts.xls"
。 You can also use the Path.Combine
if you already have your folder in another string: 如果已经在另一个字符串中包含文件夹,则也可以使用Path.Combine
:
xlWorkBook.SaveAs(Path.Combine(folder, "Bar Charts.xls"), ...
Try This : 尝试这个 :
xlWorkBook.SaveAs(@"YourPath" + "\Bar Charts.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.