Last post Jun 06, 2009 12:33 AM by sabarishbabu
Mar 21, 2009 10:06 AM|sunny74|LINK
I am doing an export of gridview to EXcel.
The technique I have adopted is to read the values from Gridview row wisewise ie caption, header row, row and footer and write them to the Excel sheet.
But I am getting the above Exception in the lines where I have used the get_Range function.
My code is as below:
if (ExportGridToExcel1(grdview, filename, true,out grdcap1,out grdhead1,out grdrow1,out grdfoot1,out grdcolpos) == "success")
//myrange.Value2 = str;
app.Workbooks.Open(SavepathFR, 0, false, 5, "", "", false,
Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
string capst = grdcolpos;string capend = grdcolpos;
string hdst = grdcolpos;string hdend = grdcolpos;
string rowst = grdcolpos;string rowend = grdcolpos;
string ftst = grdcolpos;string ftend = grdcolpos;
Excel.Range caprange = (Excel.Range)CurSheet.get_Range(capst,capend); // I am getting error in this line and the 3 lines below this.
Excel.Range headrange = (Excel.Range)CurSheet.get_Range(hdst,hdend);
Excel.Range rowrange = (Excel.Range)CurSheet.get_Range(rowst,rowend);
Excel.Range footrange = (Excel.Range)CurSheet.get_Range(ftst,ftend);
WB.SaveAs(SavepathFR, Excel.XlFileFormat.xlWorkbookNormal, m_objOpt, m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange, m_objOpt, m_objOpt, m_objOpt, m_objOpt, false);
WB.Close(false, m_objOpt, m_objOpt);
return "Report created succesfully";
return ExportGridToExcel(grdview, filename, true, out str);
If I hardcode the range in this fashion then I don't get this Exception:
Excel.Range caprange = (Excel.Range)CurSheet.get_Range("A10","C10"); But I am dynamically generating the range i.e start and end strings depending on type of row etc.
Another question:Unlike grdcap1, grdrow1 is a 2 -dimensional array having multiple gridview rows in it.
So when I assign it to a range will it display all the rows properly or throw some exception.In other words does set_Value set values for multiple rows within that range or it sets value of only one row.
Thanks for your replies.
Mar 21, 2009 11:25 AM|PassHours|LINK
Have you tried the other way round of exporting Gridview to excel which is pretty straightforward
You can have a look here : Gridview Export to Excel
Hope that helps [Yes]
Mar 27, 2009 05:05 AM|sunny74|LINK
I am aware of the method for exporting gridview given in your link.But obviously I am not using it because I need a formatted output with Logo, Caption, headers etc which is not possible in that method.
Anyhow I have solved my problem.
Mar 27, 2009 05:09 AM|sunny74|LINK
I am aware of the method given in your link. But I am not using it because I need a formatted output which is not possible with that method.
I have solved the problem.
Jun 06, 2009 12:33 AM|sabarishbabu|LINK
How did you fix the issues "Exception from HRESULT: 0x800401A8" ?