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

发布于 2024-09-05 06:23:42 字数 156 浏览 10 评论 0原文

是否可以将单元格添加到范围中?因为我需要的单元格并不相邻。

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

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

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

谢谢

Is it possible to add cells to a range? Because the cells i need, aren't next to each other.

Example:
I need to add the cells with x in one range

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

Is this possible? and if so, how?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

哎呦我呸! 2024-09-12 06:23:42

试试这个

VBA:

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

C#

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

Try this

VBA:

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

C#

Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("B26,B19,B13", Type.Missing);
你好,陌生人 2024-09-12 06:23:42

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

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";

I couldn't find a way around it so I ended up having to create new series for those columns.

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";
献世佛 2024-09-12 06:23:42

编程语言

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

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
扛起拖把扫天下 2024-09-12 06:23:42

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

ignore this, my suggestion didn't work properly

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文