Aurosish Mohanty

Aurosish Mohanty

  • NA
  • 13
  • 43.9k

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

Feb 22 2011 12:33 AM
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

{

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(


releaseObject(range);

releaseObject(xlWorkSheet);

releaseObject(xlWorkBook);

xlApp.Quit();

releaseObject(xlApp);

}

}

}


{


}


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

{

}



Thanks in Advance.

Answers (1)