如果您有对单元格的引用,是否有办法在Excel工作表中走动? 喜欢这个
Microsoft.Office.Interop.Excel.Range cellWalker = mfe.GetMyCell(Mysheet);
cellWalker = cellWalker.GoUpOneRowButKeepColumn();
cellWalker = cellWalker.GoDownOneRowButKeepColumn();
cellWalker = cellWalker.GoLeftOneColumnButKeepRow();
cellWalker = cellWalker.GoRightOneColumnButKeepRow();
关心Stefan
答案 0 :(得分:7)
Range.Offset属性会为您执行此操作。 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
答案 1 :(得分:0)
文档说no。您可以通过将Interface包装在您自己的对象中来自己实现此类功能。您可以将这些方法写入对象,然后使用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);
}
}