Excel 四处走动

发布于 2024-12-04 05:58:34 字数 380 浏览 3 评论 0原文

如果您有对单元格的引用,是否可以在 Excel 工作表中四处走动? 像这样

Microsoft.Office.Interop.Excel.Range cellWalker = mfe.GetMyCell(Mysheet);

cellWalker = cellWalker.GoUpOneRowButKeepColumn();
cellWalker = cellWalker.GoDownOneRowButKeepColumn();
cellWalker = cellWalker.GoLeftOneColumnButKeepRow();
cellWalker = cellWalker.GoRightOneColumnButKeepRow();

问候斯特凡

Is there a way of walking around in a Excel sheet if you have a reference to a cell ?
Like this

Microsoft.Office.Interop.Excel.Range cellWalker = mfe.GetMyCell(Mysheet);

cellWalker = cellWalker.GoUpOneRowButKeepColumn();
cellWalker = cellWalker.GoDownOneRowButKeepColumn();
cellWalker = cellWalker.GoLeftOneColumnButKeepRow();
cellWalker = cellWalker.GoRightOneColumnButKeepRow();

?

Regards Stefan

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

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

发布评论

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

评论(2

剧终人散尽 2024-12-11 05:58:35

该文档说。您可以通过将接口包装在您自己的对象中来自己实现此类功能。您可以将这些方法写入对象中,然后使用 Range 和 Cell 属性来导航工作表。

概念性(未经测试,但“一般要点”示例)

public class ExcelWalker {
    Microsoft.Office.Interop.Excel.Range navigator
    Microsoft.Office.Interop.Excel.Range currentCells
    Integer currentRow,currentColumn

    public void GoUpOneRowButKeepColumn(){
       currentCells = navigator.Cells(currentRow++,currentColumn);
    }
}

The documentation says no. You can probably implement such functionality yourself by wrapping the Interface within your own object. You can write those methods into the object, then use the Range and Cell properties to navigate the sheet.

Conceptual (untested, but "general gist" example)

public class ExcelWalker {
    Microsoft.Office.Interop.Excel.Range navigator
    Microsoft.Office.Interop.Excel.Range currentCells
    Integer currentRow,currentColumn

    public void GoUpOneRowButKeepColumn(){
       currentCells = navigator.Cells(currentRow++,currentColumn);
    }
}
岁月静好 2024-12-11 05:58:34

Range.Offset 属性将为您执行此操作。例如

Microsoft.Office.Interop.Excel.Range cellWalker = mfe.GetMyCell(Mysheet);

cellWalker = cellWalker.Offset[-1, 0]; // GoUpOneRowButKeepColumn
cellWalker = cellWalker.Offset[1, 0];  // GoDownOneRowButKeepColumn
cellWalker = cellWalker.Offset[0, -1]; // GoLeftOneColumnButKeepRow
cellWalker = cellWalker.Offset[0, 1];  // GoRightOneColumnButKeepRow

The Range.Offset property will do this for you. E.g.

Microsoft.Office.Interop.Excel.Range cellWalker = mfe.GetMyCell(Mysheet);

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