E
ekoniec1
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(String 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
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(String 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