转动Option Strict On
,你应该看到你的第一个问题,Colspan
只需要整数。
我能想到的唯一方法是把它分成更多的列,就像我们过去在 HTML 表格时代所做的那样。有两种基本方法,要么使用列数的最小公倍数 (6),要么将中心列分成两个较小的列。我个人更喜欢第一种方法,因为我认为它更干净一些。
''//Create a 6 column table with each column have about 16.666667%
Dim T1 As New PdfPTable(6)
''//For three across we span 2
T1.AddCell(New PdfPCell(New Phrase("1")) With {.Colspan = 2})
T1.AddCell(New PdfPCell(New Phrase("2")) With {.Colspan = 2})
T1.AddCell(New PdfPCell(New Phrase("3")) With {.Colspan = 2})
''//For two across we span 3
T1.AddCell(New PdfPCell(New Phrase("1.5A")) With {.Colspan = 3})
T1.AddCell(New PdfPCell(New Phrase("1.5B")) With {.Colspan = 3})
Doc.Add(T1)
''//Create a 4 column table with the center columns have half the width of the outer columns
Dim T2 As New PdfPTable({2, 1, 1, 2})
''//Add a normal cell
T2.AddCell(New PdfPCell(New Phrase("1")))
''//Add a cell that spans the two "smaller" columns
T2.AddCell(New PdfPCell(New Phrase("2")) With {.Colspan = 2})
''//Add a normal cell
T2.AddCell(New PdfPCell(New Phrase("3")))
''//In this row we need a full normal column plus one of the half columns
T2.AddCell(New PdfPCell(New Phrase("1.5A")) With {.Colspan = 2})
T2.AddCell(New PdfPCell(New Phrase("1.5B")) With {.Colspan = 2})
Doc.Add(T2)