[英]Excel cannot access the file when saving file
I am trying to save my Excel file that I created in c#. 我正在尝试保存在c#中创建的Excel文件。 I added a
DateTime.Now
to the title and made sure the characters where compatible. 我在标题中添加了
DateTime.Now
并确保字符兼容。 Now I have the above error when the folder exists. 现在当文件夹存在时出现以上错误。 I have posted what it says could be the error but none apply.
我已经发布了它说的可能是错误,但均不适用。 Also when I get the error it tells me the
DateTime.Now
portion is say for todays date and time started was 5/9/8E017700. 另外,当我收到错误消息时,它告诉我
DateTime.Now
部分表示今天的日期和开始时间是5/9 / 8E017700。 That is not not a date or time for year and time. 那不是年份和时间的日期或时间。 I think that maybe the problem but I am unsure as to why it is altered when I never change the variable for name.
我认为可能是问题所在,但是我不确定为什么在从不更改名称变量的情况下会更改它。 How can I get this problem resolved?
如何解决此问题?
• The file name or path does not exist. •文件名或路径不存在。
• The file is being used by another program. •该文件正在被另一个程序使用。
• The workbook you are trying to save has the same name as a currently open workbook. •您要保存的工作簿与当前打开的工作簿具有相同的名称。
string date = DateTime.Now.ToString().Replace(":", ".");
string filename = "IncomingProduct-" + date + ".xls";
string subPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/Documents/Reports/";
bool isExists = Directory.Exists(subPath);
if (!isExists)
Directory.CreateDirectory(subPath);
xlWorkBook.SaveAs(subPath + filename);//error here
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
System.Diagnostics.Process.Start(subPath + filename);
您不能使用带斜杠的文件名,因此,如果日期带有斜杠,将无法保存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.