CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Posts
    2

    I cant save xls file

    Hi,

    thanks in advanced.

    i have a problem to save xls file, I think it permission problem or something I dont know.

    i get this error when i try to :

    myExcelWorkbook.Close(true, null, null); // close and save !!!!!

    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.

    can someone knows this issue???

  2. #2
    Join Date
    Sep 2010
    Posts
    2

    Re: I cant save xls file

    Quote Originally Posted by nana2010 View Post
    Hi,

    thanks in advanced.

    i have a problem to save xls file, I think it permission problem or something I dont know.

    i get this error when i try to :

    myExcelWorkbook.Close(true, null, null); // close and save !!!!!

    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.

    can someone knows this issue???
    this is my code:
    Excel.Application myExcelApp;
    Excel.Workbooks myExcelWorkbooks;
    Excel.Workbook myExcelWorkbook;

    object misValue = System.Reflection.Missing.Value;

    myExcelApp = new Excel.ApplicationClass();
    myExcelApp.Visible = false;
    myExcelWorkbooks = myExcelApp.Workbooks;
    String fileName = "C:\\excel\\data.xls";// \\ set this to your file you want
    myExcelWorkbook = myExcelWorkbooks.Open(fileName, misValue, false, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);

    Excel.Worksheet myExcelWorksheet = (Excel.Worksheet)myExcelWorkbook.ActiveSheet;

    String cellFormulaAsString = myExcelWorksheet.get_Range("A2", misValue).Formula.ToString();// \\ this puts the formula in Cell A2 or text depending whats in it in the string.

    myExcelWorksheet.get_Range("C22", misValue).Formula = "New Value"; //\\ this changes the cell value in C2 to "New Value" }

    myExcelWorkbook.Close(true, null, null);
    myExcelApp.Quit();

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: I cant save xls file

    Also ensure that the file doesn't remain opened in the Excel.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured