从C#将.xls文件保存到.xlsx的问题

时间:2019-10-01 12:56:12

标签: excel c#-4.0 crystal-reports-2008

仅当我尝试将c#中的.xls中的文件另存为.xlsx时,才出现此错误。仅当我尝试从IIS 7.0运行时才会发生


The file could not be accessed. Try one of the following:

• Make sure the specified folder exists. 

• Make sure the folder that contains the file is not read-only.

• Make sure the file name does not contain any of the following characters:  <  >  ?  [  ]  :  | or  *

• Make sure the file/path name doesn't contain more than 218 characters.

The file could not be accessed. Try one of the following:

根据我的情况,该路径存在,文件夹和文件不是只读的,不包含任何这些字符,并且不超过218个字符。

当我在本地运行具有以下文件路径和文件名的项目时,它可以工作

"\\localhost\inetpub\wwwroot\ABC\GeneratedReports\Financial\Ageing_XXXX XXXX XXXXXX XXXXXX XXX_10_15548312.xls"

如果将路径再次更改为以下,则会出现该错误

"C:\inetpub\wwwroot\ABC\Generatedreports\Financial\Ageing_XXXX XXXX XXXXXX XXXXXX XXX_10_15548312.xls"

这是我用来转换这些excel文件的代码段

Excel.Application excelApp = new Excel.Application();
Excel.Workbook xlWorkbook_temp = excelApp.Workbooks.Open(strSavePath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);

xlWorkbook_temp.SaveAs(Filename: strSavePath2, FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook);
xlWorkbook_temp.Close();

0 个答案:

没有答案