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;
}
}
}
|