重复添加列表内容到excel

时间:2014-12-11 15:43:54

标签: c# excel list sequential

我希望你能帮助我。我的问题是我不知道如何将列表中的信息转储到现有的excel文件中。我有一个int列表(L1)作为大型代码的一部分。此代码将信息添加到列表中(3个数字),然后将它们复制到excel文件而不覆盖现有内容(这是我不知道的位),清除列表并重复该过程。换句话说,过程如下:

   1- I add stuff to L1                                        //I know how to do this
   2- I dump stuff to excel                                    //HOW?
   3- I clear L1                                               //I know how to do this
   4- I add new stuff to L1                                    //I know how to do this
   5- I dump stuff to excel starting in the following line     //HOW?
   6- I clear L1                                               //I know how to do this
   ...

最终的excel应该是这样的(包括单词Start和End):

    A      B       C
    Start                     //List1 is copied below
    15     18   0                     
    20     40   50
    12     15   16
    End                       //List1 is cleared
    Start       
    7      90   16            //List1 is copied below
    20     15   50
    12     15   8
    End                       //List1 is cleared

要在Excel中写,我使用的是:

  string path = @"C:\file.xlsx";
        oXL = new Microsoft.Office.Interop.Excel.Application();
        oXL.Visible = true;
        oXL.DisplayAlerts = false;
        mWorkBook = oXL.Workbooks.Open(path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
        //Get all the sheets in the workbook
        mWorkSheets = mWorkBook.Worksheets;
        //Get the allready exists sheet
        mWSheet1 = (Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item("Sheet1");
        Microsoft.Office.Interop.Excel.Range range = mWSheet1.UsedRange;
        int colCount = range.Columns.Count;
        int rowCount = range.Rows.Count;

但我不知道如何检索最后一个现有数据单元以及如何创建excel,如上所示。

有人可以帮我处理excel部分吗?

谢谢!

0 个答案:

没有答案