Excel c#将单元格添加到范围

时间:2010-06-10 10:53:19

标签: c# excel range add cells

是否可以将细胞添加到范围内?因为我需要的细胞不是彼此相邻的。

例:
我需要在一个范围内添加x的单元格

x 0 x x
x 0 x x
x 0 x x

这可能吗?如果是的话,怎么样?

由于

4 个答案:

答案 0 :(得分:1)

试试这个

VBA:

Range("B26,B19,B13").Select

C#

Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("B26,B19,B13", Type.Missing);

答案 1 :(得分:1)

我找不到解决方法,所以我最终不得不为这些专栏创建新系列。

Excel.SeriesCollection series =  chartPage[1].SeriesCollection();
        Excel.Series TSeries1 = series.NewSeries();
        TSeries1.XValues = xlWorkSheet.Range[xlWorkSheet.Cells[2, 1], xlWorkSheet.Cells[chart1.Series[0].Points.Count + 1, 1]];
        TSeries1.Values = xlWorkSheet.Range[xlWorkSheet.Cells[2, 5], xlWorkSheet.Cells[chart1.Series[0].Points.Count + 1, 5]];
        TSeries1.Name = "Setpoint Value";
        Excel.Series TSeries2 = series.NewSeries();
        TSeries2.XValues = xlWorkSheet.Range[xlWorkSheet.Cells[2, 1], xlWorkSheet.Cells[chart1.Series[0].Points.Count + 1, 1]];
        TSeries2.Values = xlWorkSheet.Range[xlWorkSheet.Cells[2, 6], xlWorkSheet.Cells[chart1.Series[0].Points.Count + 1, 6]];
        TSeries2.Name = "Process Value";

答案 2 :(得分:0)

VBA

Option Explicit

Sub ShowAreaUse()

    Dim oRange As Range
    Dim oArea As Range

    'create range with four cells
    Set oRange = Range("C9,E22,F15,I6")

    Debug.Print "Range with four area ranges"
    Debug.Print oRange.Address

    For Each oArea In oRange.Areas
        Debug.Print "    " + oArea.Address
    Next

    'add more cells
    Set oRange = Range(oRange.Address + ",A1:B10")

    Debug.Print "Range with added cells"
    Debug.Print oRange.Address

    For Each oArea In oRange.Areas
        Debug.Print "    " + oArea.Address
    Next

    Debug.Print "Dump Range Cells"

    For Each oArea In oRange
        Debug.Print "    " + oArea.Address
    Next

End Sub

答案 3 :(得分:0)

忽略这一点,我的建议没有正常工作