PC Review


Reply
Thread Tools Rate Thread

Adding large amount of data to range get excetion:HRESULT:0x800A03

 
 
=?Utf-8?B?TW9ydGVuIEhlcm1hbiBKZW5zZW4=?=
Guest
Posts: n/a
 
      25th Jan 2007
I have made some code that can take som data from a .NET dataset and put it
into an excell sheet. This works perfectly when i have e.g. 1000 rows of
information. My problem is that based on som meta data, i create a four
column and 24000+ row data for an excel range. when i try to assign the data
to the range, i get the following exception:
Exception from HRESULT: 0x800A03EC
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Microsoft.Office.Interop.Excel.Range.set_Value2(Object )


the code that produces the error is:

private void InsertData(DataTable table, _Worksheet concreteWorkSheet)
{
// the worksheet starting at cell A2.
int numOfRows = table.Rows.Count;
int numOfColums = table.Columns.Count;
object[,] objData = new Object[numOfRows, numOfColums];


for (int row = 0; row < numOfRows; row++)
{
for (int column = 0; column < numOfColums; column++)
{
objData[row, column] = table.Rows[row][column];
}

}
excellRange = concreteWorkSheet.get_Range("A2", excelNullValue);
excellRange = excellRange.get_Resize(numOfRows, numOfColums);
excellRange.Value2 = objData;
}



********************The operation calling the method is the
following******************
Application excelApplication;
excelApplication = new Application();
Workbooks excellWorkBooks;
excellWorkBooks = excelApplication.Workbooks;
_Workbook concreteWorkbook;
concreteWorkbook = excellWorkBooks.Add(excelNullValue);
Sheets excelWorkSheets;
excelWorkSheets = concreteWorkbook.Worksheets;
if (data.Tables.Count > excelWorkSheets.Count)
{
int numberOfMissingSheets = data.Tables.Count - excelWorkSheets.Count;
for (int i = 0; i < numberOfMissingSheets; i++)
{
concreteWorkbook.Worksheets.Add(excelNullValue, excelNullValue,
excelNullValue, excelNullValue);
}
}
for (int i = 1; i <= excelWorkSheets.Count && i <= data.Tables.Count;
i++)
{
_Worksheet concreteWorkSheet;
concreteWorkSheet = (_Worksheet)(excelWorkSheets.get_Item(i));

DataTable table = data.Tables[i - 1];
CreateHeaders(table, concreteWorkSheet);
InsertData(table, concreteWorkSheet);
}

if (!Path.IsPathRooted(excelFileName))
{
excelFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
Path.GetFileName(excelFileName));
}

// Save the Workbook and quit Excel.
if (File.Exists(excelFileName)) File.Delete(excelFileName);
concreteWorkbook.SaveAs(excelFileName, excelNullValue, excelNullValue,
excelNullValue, excelNullValue, excelNullValue,
XlSaveAsAccessMode.xlNoChange,
XlSaveConflictResolution.xlLocalSessionChanges, excelNullValue,
excelNullValue, excelNullValue, excelNullValue);
concreteWorkbook.Close(false, excelNullValue, excelNullValue);
excelApplication.Quit();


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TW9ydGVuIEhlcm1hbiBKZW5zZW4=?=
Guest
Posts: n/a
 
      26th Jan 2007
I found that instead of inserting 24000+ rows in one operation, i split the
operation and tried with a smaller amount of data. This resulted in the
following behavior:

inserting the data at 1000 rows at a time, the exception occured after some
3000+ inserted rows.
inserting the data at 200 rows at a time, the exception occured after some
2300+ rows inserted.
inserting the data at 150 rows at a time, the exception occured after some
1900+ rows inserted.
inserting the data at 140 rows at a time, the exception occured after some
1900+ rows inserted.
inserting the data at 127 or 128 rows at a time, the exception did not occur.

So it might look like there is som kind of 7bit (127 or 128 with offset 1)
constraint/error, that when adding large amount of data makes Excel throw
exceptions. I managed to create a workaround, but i cant figure out why it
was made this way in the first place.

I have only tried inserting one specific dataset, so it could also be
something with the total amount of bytes inserted at a time, and a
coincidence with the 127/128 limit.

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reformating large amount of data Jason Microsoft Excel Misc 2 10th Apr 2008 10:41 PM
Large amount of data for plotting dharshanie Microsoft Excel Charting 7 24th May 2006 05:08 PM
Moving large amount of data =?Utf-8?B?V0hTQ0M=?= Microsoft Access 3 24th Mar 2005 05:51 PM
$ large amount of Data. confused man Microsoft Excel Discussion 5 9th Feb 2005 12:34 AM
hot to copy large amount of data from one mdb 2 another John Smith Microsoft Access 2 24th Jun 2004 07:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:41 AM.