我在用C#生成excel文档时,最后执行到
sheet.SaveAs("C:\\files\123.xls",Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,);时,
出现了“无法访问文件。请尝试下列方法之一:
      确认所指定的文件夹已存在。
      确认文件所在的文件夹不是只读的。
      确认给出的文件名不包含下列字符:<>?[]:Sheet1.xls或*。
      确认文件/路径名长度不超过218个字符。”
的错误提示,请高手指教这是什么问题呢?该如何解决?急~~谢谢!

解决方案 »

  1.   

     文件名换:  @"C:\files\123.xls"
      

  2.   

    sheet.SaveAs("C:\\files\\123.xls",Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,);时, 
      

  3.   

     using newExcel = Microsoft.Office.Interop.Excel;
     newExcel.Application myErrorBill = new newExcel.ApplicationClass();
     newExcel.Workbook ErrorBillBook = myErrorBill.Workbooks.Add(true);
     newExcel.Worksheet worksheet = myErrorBill.Sheets[1] as newExcel.Worksheet; string ErrorResult =@"c:\123.XLS";
     worksheet.SaveAs(ErrorResult, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
     ErrorBillBook.Save();
      

  4.   

    我试了一下,好像是excel在保存的时候会判断文件夹的属性,如果文件夹是只读的就会出现这个错误,我是通过语句创建的文件夹,所以自动被设置为只读了,请问在怎样创建文件夹的时候能让该文件夹不是只读的呢?