/// <summary>
/// 追加记录
/// </summary>
/// <param name="DataTable"></param>
public void AppendText(string fileName, System.Data.DataTable dt)
{
ApplicationClass excel = new ApplicationClass();
object miss = System.Type.Missing;
excel.Workbooks.Open(fileName, miss, false, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss);
Workbooks workBooks = null;
try
{
workBooks = excel.Workbooks;
Workbook curWorkBook = workBooks[1];
Worksheet curSheet = (Worksheet)curWorkBook.Worksheets[1];
excel.DisplayAlerts = false;
excel.AlertBeforeOverwriting = false;
int cout = curSheet.UsedRange.Rows.Count;
for (int i = 0; i < dt.Rows.Count; i++)
{
//for (int j = 0; j < dt.Columns.Count; j++)
//{
curSheet.Cells[cout + i + 1, 1] = (cout + i - 2).ToString();
curSheet.Cells[cout + i + 1, 2] = dt.Rows[i][0].ToString();
//}
}
curWorkBook.Save();
workBooks.Close();
excel.Quit();
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (workBooks != null) { workBooks.Close(); }
if (excel != null) { excel.Quit(); }
}
}