如何将数据追加到一个Excel工作表列?
问题描述:
我现有的Excel一些数据文件,我想数据追加到它...
![此处输入的形象描述] [1]
I have existing Excel file with some data and I want to append data to it... ![enter image description here][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());
}
这是我做了什么。但我想追加..
this is what I done. but I want to append..
答
要附加到现有的Excel文件,找到最后一排,用1加一
To append to an existing excel file, find the last row and increment it by 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;
,然后简单地写入到该行
and then simply write to that row