LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem Copying DataTable into Worksheet

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying worksheet problem owl37 Excel Discussion (Misc queries) 0 January 10th 06 10:09 AM
Bind datatable to excel worksheet gianni Excel Programming 0 April 28th 05 02:54 PM
Problem copying rows to new worksheet caksey Excel Programming 7 February 26th 04 03:11 PM
Problem copying worksheet containing code module Basie[_2_] Excel Programming 1 September 3rd 03 12:28 AM


All times are GMT +1. The time now is 06:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"