Exporting DataGrid to Excel
-
Hello Friends, I use this link to export datagrid values to excel sheet. http://support.microsoft.com/kb/306023/EN-US/ and iam following this topic Use Automation to Transfer an Array of Data to a Range on a Worksheet The problem is , if the no of characters are more in the datagrid cell and if i make transfer to the excel sheet, then it throws error.When i debug , i found out if the characters in a datagrid cell exceed 910, then it throws error. If any of you, have faced a problem like this before,please share your thoughts. Suresh.P.S
-
Hello Friends, I use this link to export datagrid values to excel sheet. http://support.microsoft.com/kb/306023/EN-US/ and iam following this topic Use Automation to Transfer an Array of Data to a Range on a Worksheet The problem is , if the no of characters are more in the datagrid cell and if i make transfer to the excel sheet, then it throws error.When i debug , i found out if the characters in a datagrid cell exceed 910, then it throws error. If any of you, have faced a problem like this before,please share your thoughts. Suresh.P.S
HI Are you Editing the datagrid ? What throwing the Exception datagrid or Excel sheet ?
Thanks and Regards Sandeep
-
HI Are you Editing the datagrid ? What throwing the Exception datagrid or Excel sheet ?
Thanks and Regards Sandeep
-
Hi, I am not editing the datagrid. I am trying to export to excel.I am very sure, it is because of the no of characters presented in a cell. The exception is COM Exception "Exception from HRESULT: 0x800A03EC." Suresh.P.S
NO i don't think Suresh its because of it i just add near about 1000 char in one cell and also saved it succesfully ! Again you can you try again for some small data then go for bigger one can you post the code ? so that i can see what you have done I also had COM error that time it was due to Security issue :) Its very difficult resovle COM error as errors are in number no description :)
Thanks and Regards Sandeep
-
NO i don't think Suresh its because of it i just add near about 1000 char in one cell and also saved it succesfully ! Again you can you try again for some small data then go for bigger one can you post the code ? so that i can see what you have done I also had COM error that time it was due to Security issue :) Its very difficult resovle COM error as errors are in number no description :)
Thanks and Regards Sandeep
Hi, use this link.i made my code from this link. http://support.microsoft.com/kb/306023/EN-US/ and the following is my code This is the windows application.when i truncate the data, it saves successfully, but when i increase the limit , then it throws the error. // Start a new workbook in Excel. excel = new Excel.Application(); books = (Excel.Workbooks)excel.Workbooks; book = (Excel._Workbook)(books.Add(optionalValue)); sheets = (Excel.Sheets)book.Worksheets; sheet = (Excel._Worksheet)(sheets.get_Item(1)); System.Data.DataView customizeGridView=(System.Data.DataView)CustomizeExportDataGrid.DataSource; // Create an array for the headers and add it to cells A1:C1. object[] headers=new object[customizeGridView.Table.Columns.Count]; //Read the column names from the view and add it as a column headers to excel sheet. if(customizeGridView!=null) { for(int i=0;i < customizeGridView.Table.Columns.Count;i++) { headers[i]=customizeGridView.Table.Columns[i].ColumnName; } } range = sheet.get_Range("A1", optionalValue); if(customizeGridView.Table.Columns.Count > 0) range = range.get_Resize(1,customizeGridView.Table.Columns.Count); range.Value = headers; range.EntireColumn.AutoFit(); font = range.Font; font.Bold=true; if(customizeGridView!=null) { // Create an array with 3 columns and 100 rowxs and add it to // the worksheet starting at cell A2. int rowcount=customizeGridView.Table.Rows.Count; int ColumnCount=customizeGridView.Table.Columns.Count; object[,] data = new Object[rowcount,ColumnCount]; int rowLoop=0; int ColumnLoop=0; //First the object values are copied and they are saved in to excel as a stretch to increase performance. for(rowLoop=0;rowLoop <= rowcount-1;rowLoop++) { for(ColumnLoop=0;ColumnLoop <= ColumnCount-1;ColumnLoop++) { if(CustomizeExportDataGrid[rowLoop,ColumnLoop]==System.DBNull.Value) data[rowLoop,ColumnLoop]=string.Empty; else { data[rowLoop,ColumnLoop] = CustomizeExportDataGrid[rowLoop,ColumnLoop]; } } } range = sheet.get_Range("A2", optionalValue); range = range.get_Resize(rowcount,ColumnCount); range.Value = data; excel.DisplayAlerts=false; book.SaveAs(filename, optionalValue, optionalValue, optionalValue, optionalValue, optionalValue, Excel.XlSaveAsAccessMode.xlNoChange, optionalValue, optionalValue, optionalValue, optionalValue); Thanks, Suresh.P.S -- modified at 10:08 Thursday 8th February, 2007