如何将数据追加到一个Excel工作表列? [英] How to append data into a excel sheet column?

查看:195
本文介绍了如何将数据追加到一个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

这篇关于如何将数据追加到一个Excel工作表列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆