none
xlWorkBook.SaveAs throwing error while saving RRS feed

  • Question

  • I tried to save an .xls(XMLSpreadsheet Format) to .Xlsx format using c#.It's throwing an error.Any help appreciated.

    xlWorkBook.SaveAs(

    @"C:\GROUPM_MASTERComp.xls",52,"", "", "", "", Excel.XlSaveAsAccessMode.xlNoChange, "", "", "", "", "");

    I am getting error in the above Code.


    sathish kumar
    Thursday, June 16, 2011 6:36 AM

Answers

  • I found out,

     

    xlWorkBook1.SaveAs(

    "c:\\1.xlsx", Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);

     

    You can save using the above vode.


    sathish kumar
    • Marked as answer by jamoon Thursday, June 16, 2011 9:04 AM
    Thursday, June 16, 2011 9:04 AM

All replies

  • I hope this helps

    http://msdn.microsoft.com/en-us/library/h1e33e36(v=VS.90).aspx

     


    http://vsto.tistory.com
    Thursday, June 16, 2011 7:34 AM
  • No it doesn't work


    sathish kumar
    Thursday, June 16, 2011 8:13 AM
  • I found out,

     

    xlWorkBook1.SaveAs(

    "c:\\1.xlsx", Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);

     

    You can save using the above vode.


    sathish kumar
    • Marked as answer by jamoon Thursday, June 16, 2011 9:04 AM
    Thursday, June 16, 2011 9:04 AM
  • I hope this helps

       static void Main(string[] args)
        {
          object mis = Type.Missing;
          Excel.Application xlApp = new Excel.Application();
          Excel.Workbook xlWorkBook = xlApp.Workbooks.Open(@"c:\temp\test.xls", mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis);
          xlWorkBook.SaveAs(@"c:\temp\test.xlsx", Excel.XlFileFormat.xlOpenXMLWorkbook, mis, mis, mis, mis, Excel.XlSaveAsAccessMode.xlNoChange, mis, mis, mis, mis, mis);
          //Excel.Worksheet xlWorkSheet = xlWorkBook.Worksheets[1] as Excel.Worksheet;
    
          //int[] i = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
          //xlWorkSheet.get_Range("a1:j1", Type.Missing).Value2 = i;
    
          xlWorkBook.Close(mis, mis, mis);
          xlApp.Quit();
    
          //releaseObject(xlWorkSheet);
          releaseObject(xlWorkBook);
          releaseObject(xlApp);    
        }
    
        private static void releaseObject(object obj)
        {
          try
          {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
            obj = null;
          }
          catch
          {
            obj = null;        
          }
          finally
          {
            GC.Collect();
          }
        }

     

    Thursday, June 16, 2011 9:06 AM
  • Thanx a Lot for your reply.

    The above Code Works With "Excel.XlFileFormat.xlOpenXMLWorkbook" but it will fail when you specify Normal template "XlFileFormat.xlWorkbookNormal" it will fail.The one i posted above works for the conversion.


    sathish kumar
    Thursday, June 16, 2011 9:17 AM
  • Hello,

    Could you post up your source you found out, if you don't mind?

     When I used below source from you, it occured error.

    I think the reason why I have the problem is that saving path is root.

    xlWorkBook1.SaveAs(

     

    "c:\\1.xlsx", Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);


    http://vsto.tistory.com
    Thursday, June 16, 2011 3:51 PM
  • Hi,

     

    Please find the Code below.If you have any problem in executing it.Kindly Let me Know

     

    static

     

    void Main(string

    [] args)

    {

    Excel.

    Application

    xlApp;

    Excel.

    Workbook

    xlWorkBook;

     

    //object misValue = System.Reflection.Missing.Value;

    xlApp =

    new Excel.ApplicationClass

    ();

    xlWorkBook = xlApp.Workbooks.Open(

    "c:\\33.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true

    , 1, 0); //This Workbook is an xmlSpreadSheet Format

    xlApp.DisplayAlerts =

    false

    ;

     

    //xlWorkBook.SaveAs("c:\\22.xls", Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);

    xlWorkBook.SaveAs(

    "c:\\33.xlsx",51, null, null, false, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null

    ); //It will save as a normal ExcelTemplate Format

    xlApp.Quit();

    releaseObject(xlWorkBook);

    }

     

    private static void releaseObject(object

    obj)

    {

     

    try

    {

    System.Runtime.InteropServices.

    Marshal

    .ReleaseComObject(obj);

    obj =

    null

    ;

    }

     

    catch (Exception

    ex)

    {

    obj =

    null

    ;

    }

     

    finally

    {

     

    GC

    .Collect();

    }

    

    Thanks

    }


    sathish kumar
    Friday, June 17, 2011 5:19 AM