gpt4 book ai didi

c# - Excel 走来走去

转载 作者:太空宇宙 更新时间:2023-11-03 18:42:39 24 4
gpt4 key购买 nike

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

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

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

?

问候斯特凡

最佳答案

Range.Offset属性(property)会为你做这件事。例如

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

关于c# - Excel 走来走去,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7411696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com