Click here to Skip to main content
15,888,133 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to update excel sheet using a 2 dimensional array , getting an error Exception from HRESULT: 0x800A03EC.

I am using the below code to update excel sheet :

C#
public static void WriteToExcel(Object[,] ObjDVLData2)
        {
            Excel.Application objApp;
            Excel._Workbook objBook;
            Excel.Workbooks objBooks;
            Excel.Sheets objSheets;
            Excel._Worksheet objSheet;
            Excel.Range range;

            objApp = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
            objApp.Visible = true;
            objBooks = objApp.Workbooks;
            objBook = objBooks[1];
            objBook.Unprotect();
            objSheets = objBook.Worksheets;
            objSheet = (Excel._Worksheet)objSheets.get_Item(4);
            range = objSheet.get_Range("F14:F754");
            range.set_Value(Missing.Value, ObjDVLData2);
           
        }


error :

C#
{"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_Value(Object RangeValueDataType, Object value)
   at UpdateExcel.WriteToExcel(Object[,] ObjDVLData2) in D:\Projects\Excel Addin\BDS\BDSAddin\ExcelUtilities\UpdateExcel.cs:line 31
   at DVLData.getValue_DVL2(String data_source, String ENTITY_ID, String ENTITY_ID_TYPE, String AcctBasis_Conf, String AcctStand_DataStage, String scurrency, String PERIOD_NAME, String PERIOD_TYPE, String PERIOD_END_DATE, Range rMnemonics, String STATEMENT_TYPE) in D:\Projects\Excel Addin\BDS\BDSUtilities\BDSUtilities\DVLData.cs:line 114


What I have tried:

I have tried parsing through each cell to assign values after making sure that sheet is not protected. tried Range.Value and Range.Value2 to assign the array values.
Posted
Comments
Patrice T 28-Mar-16 10:25am    
how large is that array ?
Jochen Arndt 29-Mar-16 6:41am    
This is a generic error which may have several reasons.

It can't be solved here without knowing the passed data. Because that are quite many, I suggest to write a loop writing each cell to check if all data are valid.

Older Excel versions had also some limits regarding cell sizes and the amount of data that can be passed at once with set_Value. So you can try to split the data if the above checks where successful.
CHill60 29-Mar-16 9:07am    
Just a thought, if it's a two dimensional array you are using shouldn't the range be range = objSheet.get_Range("F14:G754");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900