Setting Excel Cell values using C#
Hi,
There is an Excel Addin ( developed in C#) having requirement to populate the data in Workbook after fetching it from DB, based on the Cell selected by user. So if User selects "A1" cell, and the dataset retrieved from DB has 6 rows and cols, it will fill the range of cells from "A1" to "E6". When we try to do the same, by making a call from Menu Item (Addin adds a new Menu Item in Excel menus ) the call succeeds and the data has been displayed properly . However if we specify the same formula in one of the cell (press F2,insert the formula, press CTRL + SHIFT + ENTER to calculate)as soon as the code updates one of the cells,the Exception returned is Exception from HRESULT: 0x800A03EC. Please suggest. Code Snippet :- -------------- _oExcelRange = (Excel.Range) _oExcelApp.ActiveCell; if (m_oDtrsData.Length 0) { for (int _iDataRowIndex=0; _iDataRowIndex < m_oDtrsData.Length;_iDataRowIndex++) { int _iColCount = 0; foreach(DataColumn _oDataColumn in m_oDtColumns) { if(_oDataColumn.DataType == Type.GetType("System.DateTime")) { _oExcelRange.get_Offset(_iDataRowIndex,_iColCount) .Value2 = Convert.ToDateTime(m_oDtrsData[_iDataRowIndex][_oDataColumn].ToString()); } else if(Utilities.IsNumeric(m_oDtrsData[_iDataRowIndex][_oDataColumn].ToString())) { _oExcelRange.get_Offset(_iDataRowIndex,_iColCount) .Value2 = Convert.ToDouble(m_oDtrsData[_iDataRowIndex][_oDataColumn].ToString()); } else { _oExcelRange.get_Offset(_iDataRowIndex,_iColCount) .Value2 = m_oDtrsData[_iDataRowIndex][_oDataColumn]; } _iColCount = _iColCount + 1; } } } |
Setting Excel Cell values using C#
Can this be due to the Limit imposed by Excel for worksheet formula.
Basically the limit is that the worksheet formula can only return a value to the cell containing the formula. Other attributes of the cell cannot be changed (formatting etc) and no other cell can be modified. Can any of you Gurus can confirm the same ???? Thanks |
All times are GMT +1. The time now is 06:30 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com