我有现有的Excel文件与一些数据,我想追加数据给它…
啊![在此处输入图像描述][1]

try
{
    xlApp = new Excel.Application();
    xlWorkBook = xlApp.Workbooks.Add(misValue);
    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    xlWorkSheet.Cells[1, 1] = "http://csharp.net-informations.com";
    xlWorkBook.Save();
    Object newpath = path + "Chat_Competitors.xls";
    xlWorkBook.SaveAs(newpath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
    xlWorkBook.Close(true, misValue, misValue);
    xlApp.Quit();
}
catch (Exception ex)
{
    MessageBox.Show("Error" + ex.ToString());
}

我就是这么做的。但我想附加..

最佳答案

要追加到现有的Excel文件,查找最后一行并将其增加1

int _lastRow = xlWorkSheet.Cells.Find(
                              "*",
                              xlWorkSheet.Cells[1,1],
                              Excel.XlFindLookIn.xlFormulas,
                              Excel.XlLookAt.xlPart,
                              Excel.XlSearchOrder.xlByRows,
                              Excel.XlSearchDirection.xlPrevious,
                              misValue,
                              misValue,
                              misValue
                              ).Row + 1;

然后直接写到那一行

10-05 21:45