Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hey all,
I am having some problems using the Excel.Range.Value2 property to copy data from a DataTable into a Worksheet. excelRange = excelWorksheet.get_Range( "A2", System.Type.Missing ); excelRange = excelRange.get_Resize( dt.Rows.Count, dt.Columns.Count ); object[,] tableData = new Object[ dt.Rows.Count, dt.Columns.Count ]; for( int i = 0; i < dt.Rows.Count; i++ ) for( int j = 0; j < dt.Columns.Count; j++ ) tableData[ i, j ] = dt.Rows[ i ][ j ].ToString(); excelRange.Value2 = tableData; The above code fails with the following exception thrown: System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at Excel.Range.set_Value2(Object ) The DataTable that I am copying is fairly large in size (~8000 rows, 5 columns), with some large entries. When I change the following line: tableData[ i, j ] = dt.Rows[ i ][ j ].ToString(); to tableData[ i, j ] = "str"; No exception is thrown and the code functions as intended. Any help on this would be greatly appreciated. Thanks in advance, Eric Konieczny |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Copying worksheet problem | Excel Discussion (Misc queries) | |||
Bind datatable to excel worksheet | Excel Programming | |||
Problem copying rows to new worksheet | Excel Programming | |||
Problem copying worksheet containing code module | Excel Programming |