Hi,
I am trying something like this for saving the data to excel sheet 4
Excel.Worksheet xlWorkSheet4 = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(4);
i = 1;
foreach (DataRow row in lstDS[2].Tables[0].Rows)
{
string fieldFromDB = row[1].ToString();
string FromDB = row[2].ToString();
foreach (DataRow row1 in lstDS[0].Tables[0].Rows)
{
string fieldFromDB1 = row1[1].ToString();
if (fieldFromDB == fieldFromDB1)
{
foreach (DataRow row2 in lstDS[1].Tables[0].Rows)
{
string fieldFromDB2 = row2[1].ToString();
if (fieldFromDB1 == fieldFromDB2)
{
xlWorkSheet4.Cells[i, 1] = fieldFromDB;
xlWorkSheet4.Cells[i, 2] = fieldFromDB1;
xlWorkSheet4.Cells[i, 3] = fieldFromDB2;
i++;
}
}
}
}
}
xlWorkBook.SaveAs(path1, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlShared, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
I have no problem when trying to save into excel sheets 1,2,3
I am getting unhandled exception when I am trying to save into excel sheet 4
Additional information: Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
Can any one help me in solving this???
Thanks
John