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 ..
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();
}
Comment