gpt4 book ai didi

c# - 如何将数据附加到 Excel 工作表列中?

转载 作者:太空狗 更新时间:2023-10-30 01:05:04 24 4
gpt4 key购买 nike

我有包含一些数据的现有 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;

然后简单地写入那一行

关于c# - 如何将数据附加到 Excel 工作表列中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20142488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com