tags:

views:

1212

answers:

4

Hi

I am having trouble in exporting to excel and it crashes out at the .set_Value function.

It seems to work if I change object[,] to string[,] but by doing this I lose the formatting.

Anyone Help?

+1  A: 

Are you passing 'null' for missing parameters rather than System.Reflection.Missing.Value ?

Mitch Wheat
A: 

hi,

I am passing Missing.Value but I have discovered what was the cause of this particular failure. The object[,] had a '=' sign as first character in some cells which caused excel to fail so I checked for column type string and checked value if substring(0,1) == "=" then add a ' in front of '=' sign.

Cheers

ProgrammerJam

A: 

Hi Guys

I would appreciate your help. I have never worked with Excel in C# so I have no idea whats going on. I am trying to export a dataset to a excel file.

I keep getting the same error as mentioned in this thread.

My code are as follows...

Microsoft.Office.Interop.Excel.ApplicationClass excel = new ApplicationClass();

        excel.Application.Workbooks.Add(true);

        System.Data.DataTable table = dsExport.Tables[0];

        int ColumnIndex = 0;

        ///create the column headings
        foreach (DataColumn col in table.Columns)
        {
            ColumnIndex++;
            excel.Cells[1, ColumnIndex] = col.ColumnName;
        }

        ///now add the data contained in ds to the spreadsheet
        ///iterate through rows and columns
        for(int i = 0 ; i < table.Rows.Count - 1 ; i ++)
        {           
            for (int j = 0; j < table.Columns.Count - 1; j++)
            {                   
             excel.Cells[i + 1, j] = table.Rows[i][j];///this is where error ocurs                                                             
            }           
        }

        excel.Visible = true;
        Microsoft.Office.Interop.Excel.Workbook wb = (Workbook)excel.ActiveSheet;
        wb.Activate();

Any suggestions?

A: 

I am also getting the same error. The spot i see is that if i input plain text ("test") in one of the cells it just works. But in case this cell get a long xml text (like 100 char long) it starts giving this error. Still have not found out whats the problem.

dotnetcoder