Hi this is kavita,
can anybody tell me what wrong inthis code :
Excel.Application ex = new Excel.Application();
Excel.Workbook wb = ex.Workbooks.Add(Type.Missing);
Excel.Worksheet ws = Excel.Worksheets[1]; //ERROR IN THIS LINE//////
Excel.Range r = ws.get_Range("A1",Type.Missing); r.Value2 = "From Russia With Love";
r.Font.Bold = true; r.Interior.ColorIndex = 6; ex.Visible = true;
actually I want to fetch data from sql table & show in Excel report.What is the cirrect code ?
please help me!
Dipal ChoksiPosted Jan 3, 2007, 3:13 AM
Looks like the worksheet is not being referenced correctly in the code..
Try changing the following line in your code:
Excel.Worksheet ws = Excel.Worksheets[1]; //ERROR IN THIS LINE//////
TO THE FOLLOWING
Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
A code sample is also available here:
http://blogs.msdn.com/carlosag/archive/2005/08/27/WhyIWroteExcelXmlWriter.aspx
Hope this helps...
kavitaPosted Dec 30, 2006, 6:32 AM
Excel.Worksheet ws = Excel.Worksheets[1];
what is ...[1] ?
tharak nadhPosted Dec 29, 2006, 6:07 AM