0

Hi,

I am extracting data from datagridview to Excel. But for columns with so many numbers Excel turns the format to 6,45646E+11
Is there a way that I can prevent this.
I tried to use worksheets but I could not even save the data by using that.
Here is my code:

int i = 1;
            int j;

            foreach (DataRow row in datatable.Rows)
            {
                j = 1;
                foreach (DataColumn col in datatable.Columns)
                {
                    ExcelApp.Cells[i, j] = row[col.ColumnName].ToString();
                    j = j + 1;
                }
                i = i + 1;
            }

 ExcelApp.ActiveWorkbook.SaveAs(filename, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                    ExcelApp.ActiveWorkbook.Saved = true;

            ExcelApp.Quit();
2
Contributors
1
Reply
4
Views
7 Years
Discussion Span
Last Post by DdoubleD
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.