使用word文档中的下一个循环创建表

时间:2013-12-26 05:48:30

标签: vb.net

    For i = 1 To BooksTableDataGridView.Rows.Count
        docTable = document.Tables.Add(document.Bookmarks.Item("\endofdoc").Range, i + 1, 6)
    Next
    docTable.Borders.Enable = True
    docTable.Rows.HeightRule = WdRowHeightRule.wdRowHeightExactly
    docTable.Cell(1, 1).Range.Text = "Date"
    docTable.Cell(1, 2).Range.Text = "Time"
    docTable.Cell(1, 3).Range.Text = "Title"
    docTable.Cell(1, 4).Range.Text = "Code"
    docTable.Cell(1, 5).Range.Text = "Condition"
    docTable.Cell(1, 6).Range.Text = "No. of copies"
    For datadate = 0 To BooksTableDataGridView.Rows.Count - 1
        arr(datadate) = BooksTableDataGridView.Rows(datadate).Cells(0).Value.ToString
        docTable.Cell(2, 1).Range.Text = arr(0)
        docTable.Cell(3, 1).Range.Text = arr(1)
        docTable.Cell(4, 1).Range.Text = arr(2)
        docTable.Cell(5, 1).Range.Text = arr(3)
        docTable.Cell(6, 1).Range.Text = arr(4)
        docTable.Cell(7, 1).Range.Text = arr(5)
        docTable.Cell(8, 1).Range.Text = arr(6)
        docTable.Cell(9, 1).Range.Text = arr(7)
    Next
    For dataTime = 0 To BooksTableDataGridView.Rows.Count - 1
        arr(dataTime) = BooksTableDataGridView.Rows(dataTime).Cells(1).Value.ToString
        docTable.Cell(2, 2).Range.Text = arr(0)
        docTable.Cell(3, 2).Range.Text = arr(1)
        docTable.Cell(4, 2).Range.Text = arr(2)
        docTable.Cell(5, 2).Range.Text = arr(3)
        docTable.Cell(6, 2).Range.Text = arr(4)
        docTable.Cell(7, 2).Range.Text = arr(5)
        docTable.Cell(8, 2).Range.Text = arr(6)
        docTable.Cell(9, 2).Range.Text = arr(7)
    Next
    For dataTitle = 0 To BooksTableDataGridView.Rows.Count - 1
        arr(dataTitle) = BooksTableDataGridView.Rows(dataTitle).Cells(2).Value.ToString
        docTable.Cell(2, 3).Range.Text = arr(0)
        docTable.Cell(3, 3).Range.Text = arr(1)
        docTable.Cell(4, 3).Range.Text = arr(2)
        docTable.Cell(5, 3).Range.Text = arr(3)
        docTable.Cell(6, 3).Range.Text = arr(4)
        docTable.Cell(7, 3).Range.Text = arr(5)
        docTable.Cell(8, 3).Range.Text = arr(6)
        docTable.Cell(9, 3).Range.Text = arr(7)
    Next
    For dataCode = 0 To BooksTableDataGridView.Rows.Count - 1
        arr(dataCode) = BooksTableDataGridView.Rows(dataCode).Cells(3).Value.ToString
        docTable.Cell(2, 4).Range.Text = arr(0)
        docTable.Cell(3, 4).Range.Text = arr(1)
        docTable.Cell(4, 4).Range.Text = arr(2)
        docTable.Cell(5, 4).Range.Text = arr(3)
        docTable.Cell(6, 4).Range.Text = arr(4)
        docTable.Cell(7, 4).Range.Text = arr(5)
        docTable.Cell(8, 4).Range.Text = arr(6)
        docTable.Cell(9, 4).Range.Text = arr(7)
    Next
    For dataCondition = 0 To BooksTableDataGridView.Rows.Count - 1
        arr(dataCondition) = BooksTableDataGridView.Rows(dataCondition).Cells(4).Value.ToString
        docTable.Cell(2, 5).Range.Text = arr(0)
        docTable.Cell(3, 5).Range.Text = arr(1)
        docTable.Cell(4, 5).Range.Text = arr(2)
        docTable.Cell(5, 5).Range.Text = arr(3)
        docTable.Cell(6, 5).Range.Text = arr(4)
        docTable.Cell(7, 5).Range.Text = arr(5)
        docTable.Cell(8, 5).Range.Text = arr(6)
        docTable.Cell(9, 5).Range.Text = arr(7)
    Next
    For dataNumber = 0 To BooksTableDataGridView.Rows.Count - 1
        arr(dataNumber) = BooksTableDataGridView.Rows(dataNumber).Cells(5).Value.ToString
        docTable.Cell(2, 6).Range.Text = arr(0)
        docTable.Cell(3, 6).Range.Text = arr(1)
        docTable.Cell(4, 6).Range.Text = arr(2)
        docTable.Cell(5, 6).Range.Text = arr(3)
        docTable.Cell(6, 6).Range.Text = arr(4)
        docTable.Cell(7, 6).Range.Text = arr(5)
        docTable.Cell(8, 6).Range.Text = arr(6)
        docTable.Cell(9, 6).Range.Text = arr(7)
    Next

此代码应根据我在datagridview中有多少行在word文档中创建一个包含6列和行的表

但它创建的行数多于我在datagridview

中的行数

怎么了?

0 个答案:

没有答案