如果你有一个单元格的引用,有没有一种方法可以在Excel表格中遍历?像这样
Microsoft.Office.Interop.Excel.Range cellWalker = mfe.GetMyCell(Mysheet);
cellWalker = cellWalker.GoUpOneRowButKeepColumn();
cellWalker = cellWalker.GoDownOneRowButKeepColumn();
cellWalker = cellWalker.GoLeftOneColumnButKeepRow();
cellWalker = cellWalker.GoRightOneColumnButKeepRow();
向Stefan致敬
发布于 2011-09-14 06:00:42
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
发布于 2011-09-14 05:45:24
文档上写着no。您可能可以通过将接口包装在自己的对象中来实现此类功能。您可以将这些方法写入对象,然后使用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);
}
}
https://stackoverflow.com/questions/7411696
复制