【问题标题】:how to insert new row at end of the used Range in excel using .net or vba?如何使用.net或vba在excel中使用范围的末尾插入新行?
【发布时间】:2015-05-07 06:49:55
【问题描述】:

我的范围值包含 Excel 工作表的已用范围值,现在我无法在范围区域的末尾插入行

 static public void SpreedsheetOpen(string ExcelFile)
    {
        xlApp = new Excel.Application();
        xlApp.Visible = false;
        xlWorkBook = xlApp.Workbooks.Open(ExcelFile, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
        xlRange = xlWorkSheet.UsedRange;        
    }

在这个 xlRange=xlWorkSheet.UsedRange; 我在范围对象中获取 xl 表使用的范围值如何在此范围的末尾插入新行。

【问题讨论】:

    标签: c# .net vb.net vba excel


    【解决方案1】:
    Dim LastRow As Long, x As Long
    
    'Select your range
    xlRange.Select
    
    'determine the last row of the selection/range
    x = Selection.Rows(1).Row
    LastRow = Selection.Rows.Count + x - 1
    
    'Select only the last row
    Rows(LastRow).Select
    
    'Insert a new row under the selected row
    Selection.Offset(1).EntireRow.Insert
    

    【讨论】:

    • xlRange.select 是什么意思?
    • @KaruppaSamy 这有帮助吗?
    猜你喜欢
    • 2012-05-31
    • 2021-11-01
    • 2014-11-21
    • 1970-01-01
    • 2013-10-14
    • 2017-04-24
    • 2016-04-27
    • 2013-03-29
    • 2021-07-20
    相关资源
    最近更新 更多