Excel走来走去

Ste*_*son 1 c# wpf excel move cell

如果你有一个单元格的参考,有没有办法在Excel表格中走动?像这样

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

cellWalker = cellWalker.GoUpOneRowButKeepColumn();
cellWalker = cellWalker.GoDownOneRowButKeepColumn();
cellWalker = cellWalker.GoLeftOneColumnButKeepRow();
cellWalker = cellWalker.GoRightOneColumnButKeepRow();
Run Code Online (Sandbox Code Playgroud)

关心斯特凡

Ada*_*lph 7

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
Run Code Online (Sandbox Code Playgroud)