|
I have a word documant that contains text box shapes.
I'm tring to create a MS Word table inside one of this text box shapes.
But I'm having problem with the range setings.
(Microsoft.Office.Interop.Word.Range wordRange = wordDoc.Shapes[wordShapeIndexes[id]].TextFrame.ContainingRange;
throws exeption - The index into the specified collection is out of bounds.), can some one help me please ?
Here is my function:
public void setWordShapeDataTask(int id, DataGridView data)
{
int tableRowNumber = data.RowCount + 1;
Microsoft.Office.Interop.Word.Table wordTable;
Microsoft.Office.Interop.Word.Range wordRange = wordDoc.Shapes[wordShapeIndexes[id]].TextFrame.ContainingRange;
wordTable = wordDoc.Tables.Add(wordRange, tableRowNumber, 5);
wordTable.Cell(0, 0).Range.Text = "Num";
wordTable.Cell(0, 1).Range.Text = "Task";
wordTable.Cell(0, 2).Range.Text = "Recipiens";
wordTable.Cell(0, 3).Range.Text = "Time";
wordTable.Cell(0, 4).Range.Text = "Status";
for (int i = 1, j = 0; i < tableRowNumber; i++, j++)
{
wordTable.Cell(i, 0).Range.Text = i.ToString();
wordTable.Cell(i, 1).Range.Text = data.Rows[j].Cells["TaskBody"].Value.ToString();
wordTable.Cell(i, 2).Range.Text = data.Rows[j].Cells["Recipiens"].Value.ToString();
wordTable.Cell(i, 3).Range.Text = data.Rows[j].Cells["DueDate"].Value.ToString();
wordTable.Cell(i, 4).Range.Text = data.Rows[j].Cells["Status"].Value.ToString();
}
No comments:
Post a Comment