private bool AddLineToExcelFile(string file, string[] data)
{
try
{
ApplicationClass excelApplication = null;
Workbook excelWorkbook = null;
Worksheet excelWorksheet = null;
excelApplication = new ApplicationClass();
excelApplication.Visible = false;
System.Threading.Thread.Sleep(2000);
object missing = System.Reflection.Missing.Value;
excelWorkbook = excelApplication.Workbooks.Open(file, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
excelWorksheet = (Worksheet)excelWorkbook.Worksheets.get_Item(1);
int row = 1;
while (excelWorksheet.Cells[row, 1].ToString() != "")
{
string cellNumber2 = ("A" + row).ToString();
if (excelWorksheet.get_Range(cellNumber2, cellNumber2).Value2 == null)
break;
else
row++;
}
for (int i = 0; i < data.Length; i++ )
excelWorksheet.Cells[row, i + 1] = data[i];
excelWorkbook.Save();
excelWorkbook.Close();
excelApplication.Quit();
return true;
}
catch
{
return false;
}
}