Skip to content

Giving Excel Alert message everytime I open the same excel sheet for writing in a loop

Aurosish Mohanty

Asked Feb 21, 2011, 7:33 PM EST1 answer
Share
LinkedInX
Hi Team,

I am trying to modify one existing excel sheet in a loop based on different conditions. However I am getting Excel Alert message for all the very second time and not able to modify the excel. I have used the Microsoft.office.Interop.Excel component.

Attached is my code, please suggest me as soon as possible. This is very urgent and I am struggling a lot.

Microsoft.Office.Interop.Excel.

Microsoft.Office.Interop.Excel.

Microsoft.Office.Interop.Excel.

Microsoft.Office.Interop.Excel.



Application xlApp;Workbook xlWorkBook;Worksheet xlWorkSheet;Range range;int startRow = 0;try
Code
{
xlApp =
xlWorkBook = xlApp.Workbooks.Open
(


{


{
xlWorkSheet = (Microsoft.Office.Interop.Excel.
range = xlWorkSheet.UsedRange;

range.SpecialCells(

startRow = xlApp.ActiveCell.Row + 1;



new Microsoft.Office.Interop.Excel.ApplicationClass();@"C:\Aurosish\Innovation\Result.xls", 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true,false, 0, true, false, false);for (int i = 0; i < xlWorkBook.Worksheets.Count; i++)if (strOrderType.Contains("TS") || strOrderType.Contains("EQ") || strOrderType.Contains("TU") || strOrderType.Contains("BR"))Worksheet)xlWorkBook.Worksheets.get_Item(1);XlCellType.xlCellTypeLastCell, Type.Missing).Activate();/* The below code is to populate the field values*/


// for Order Date

xlWorkSheet.Cells[startRow, 3] = strDate;


// for Order #

xlWorkSheet.Cells[startRow, 4] = strOrder;


// for State

xlWorkSheet.Cells[startRow, 5] = strState;


// for County

xlWorkSheet.Cells[startRow, 6] = strCounty;


// for Borrower name

xlWorkSheet.Cells[startRow, 7] = strBorrower;


// for Order Type

xlWorkSheet.Cells[startRow, 8] = strOrderType;


xlApp.Save(xlWorkBook);

xlWorkBook.Close(


Code
releaseObject(range);
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
xlApp.Quit();
releaseObject(xlApp);
}
}
}


{


}


true,xlWorkSheet,null);catch (COMException E)throw E;finally

{

}



Thanks in Advance.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Suthish Nair
    0
    what error message you getting?
    0