這是我發現問題的解決方法。這不是最有效的方法,它doesn't work if the table has merged cells in it
。我發現你可以選擇你的開始單元格的範圍,然後通過以單元格爲單位移動來擴展範圍的結束點。通過發現要選擇的區域的開始點和結束點之間的單元格數量,可以迭代這些數目的單元格步驟。下面是低於一般的代碼:
word.Table table;
word.Cell cellTopLeft; //some cell on table.
word.Cell cellBottomRight; //another cell on table. MUST BE BELOW AND/OR TO THE RIGHT OF cellTopLeft
int cellTopLeftPosition = (cellTopLeft.RowIndex - 1) * table.Columns.Count + cellTopLeft.ColumnIndex;
int cellBottomRightPosition = (cellBottomRight.RowIndex - 1) * table.Columns.Count + cellBottomRight.ColumnIndex;
int stepsToTake = cellBottomRightPosition - cellTopLeftPosition;
if (stepsToTake > 0 &&
cellTopLeft.RowIndex <= cellBottomRight.RowIndex && //enforces bottom right cell is actually below of top left cell
cellTopLeft.ColumnIndex <= cellBottomRight.ColumnIndex) //enforces bottom right cell is actually to the right of top left cell
{
word.Range range = cellTopLeft.Range;
range.MoveEnd(word.WdUnits.wdCell, stepsToTake);
range.Select();
}