セルの最後までワードテーブルをアンダーラインにする方法を解明しようとしています。私は、もし行が長くても短くても問題があるようです。私は、言葉の専門家ではないです、しかし、私はこのコードがvb.netワードテーブルのフォーマット
以下コードであるを生成するものである...すべての文字が同じサイズではないことを
を想定しています私は上記を作成するために使用しました。私は細胞の長さを確認することができるはずだと思いますか?どんな助けもありがとう。
公共の共有サブCreateWordDocument() あなたの問題には2つの部分がありますWord.Document
'Start Word and open the document template.
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add
Dim Row As Integer, Column As Integer
Dim myTable As Word.Table = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, 10, 2)
myTable.Range.ParagraphFormat.SpaceAfter = 1
Dim mystring As String = "This is my Test name That Runs over to the next line"
Dim address1 As String = "123 1st fake street"
Dim address2 As String = "Fake town place"
Dim mystring2 As String = "This is good line"
Dim address3 As String = "321 3rd fake street"
Dim address4 As String = "Fake town place"
Dim line As String = "_"
For Row = 1 To 10
If Row <> 5 Then
myTable.Rows.Item(Row).Range.Font.Underline = Word.WdUnderline.wdUnderlineSingle
myTable.Rows.Item(Row).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
myTable.Rows.Item(Row).Range.Font.Bold = False
myTable.Rows.Item(Row).Range.Font.Size = 11
myTable.Rows.Item(Row).Range.Font.Underline = Word.WdUnderline.wdUnderlineSingle
End If
For Column = 1 To 2
If Column = 1 And Row = 1 Then
myTable.Cell(Row, Column).Range.Text = GetString(mystring)
ElseIf Column = 1 And Row = 2 Then
myTable.Cell(Row, Column).Range.Text = GetString(address1)
ElseIf Column = 1 And Row = 3 Then
myTable.Cell(Row, Column).Range.Text = GetString(address2)
ElseIf Column = 2 And Row = 1 Then
myTable.Cell(Row, Column).Range.Text = GetString(mystring2)
ElseIf Column = 2 And Row = 2 Then
myTable.Cell(Row, Column).Range.Text = GetString(address3)
ElseIf Column = 2 And Row = 3 Then
myTable.Cell(Row, Column).Range.Text = GetString(address4)
Else
myTable.Cell(Row, Column).Range.Text = GetString(line)
End If
Next
Next
Dim strCellText As String
Dim uResp As String
Dim itable As Table
For Each itable In oDoc.Tables
uResp = ""
For Row = 1 To itable.Rows.Count
For Col = 1 To itable.Columns.Count
strCellText = itable.Cell(Row, Col).Range.Text
If strCellText.Length >= 33 Then
Console.Write("this will be on a different line")
ElseIf strCellText.Length <= 31 Then
Console.Write("this will be on a different line")
End If
Next
Next
Next
Catch ex As Exception
End Try
End Sub
Public Shared Function GetString(ByVal strGetLine As String) As String
If strGetLine.Length <> 30 Then
Do Until strGetLine.Length >= 30
strGetLine += "_"
Dim count As String = strGetLine.Length
Loop
End If
Return strGetLine
End Function
まだ喪失しています...私は行が32以上になると、次の行に流出すると思いました。ラインをトリムします。 – coder32