fix this error for me

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ram712
    New Member
    • Jan 2010
    • 4

    #1

    fix this error for me

    hi,
    i am trying to create a blank workbook consisting many worksheets.i am able to create the new workbook, but when i am trying to hide thw particular worksheet i am finding error such as "the name Globals doesnot exist in the current context" can u help me in fixing this.
    here is my code what i wrote ..

    Code:
     Excel.Application xlApp;
                Excel.Workbook xlWorkBook;
                Excel.Worksheet xlWorkSheet;
                object misValue = System.Reflection.Missing.Value;
                xlApp = new Excel.ApplicationClass();
                xlWorkBook = xlApp.Workbooks.Add(misValue);
                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    
                xlWorkSheet.Cells[5, 5] = "Sharma";
              //  xlWorkBook.Worksheets.get_Item(1).Visible = Excel.XlSheetVisibility.xlSheetVeryHidden;
                         
    
                xlWorkBook.SaveAs("c:\\TC\\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
    
                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();
                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);
                MessageBox.Show("Excel file created , you can find the file c:\\TC\\csharp-Excel.xls");
                
              [B] ((Excel.Worksheet)Globals.ThisWorkbook.Sheets[3]).Visible = Excel.XlSheetVisibility.xlSheetHidden;[/B]
           
                Glo
               
            }
    
            private void releaseObject(object obj)
            {
                try
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                    obj = null;
                }
    
                catch (Exception ex)
                {
                   obj = null;
                    MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
                }
                finally
                {
                    GC.Collect();
                }
    Last edited by tlhintoq; Jan 23 '10, 04:37 PM. Reason: [CODE] ... your code here ... [/CODE] tags added
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Please DO use code tags when posting code
    Please DON'T triple space the lines of code as it makes it hard to follow and makes the post a mile long.

    What is line 24 supposed to be? Obviously that just won't compile.

    Comment

    Working...