如何将数据追加到Excel表格列?

我有一些数据的现有Excel文件,我想追加数据…![input图片描述] [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文件,find最后一行,并增加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; 

然后简单地写入该行

您必须打开现有的文件,而不是创build一个新的。

 var xlApp = new Excel.Application(); xlApp.Workbooks.Open(path + "Chat_Competitors.xls");