怎么用vb编程操作word绘制表格的边框?
+
f组合键);
2、弹出查找对话框,在查找内容处输入需要查找的数字,在以下项中查找处选择主文档,单击关闭按钮;
3、此时文档中所的查找的数字都被选中。
1、单击开始----查找按钮(或按Ctrl + F组合键);
2、弹出查找对话框,在查找内容处输入需要查找的数字,在以下项中查找处选择主文档,单击关闭按钮;
3、此时文档中所的查找的数字都被选中。
2020-06-11
用Free Spire.Doc for .NET来测试了设置边框的方法,你可以参考下。这里分给整个表格设置边框和单个单元格设置边框,具体参考以下方法:
1. 给整个Table设置Border
Imports Spire.Doc
Imports System.Drawing
Namespace SetTableBorder_Doc
Class Program
Private Shared Sub Main(args As String())
'加载Word文档
Dim doc As New Document()
doc.LoadFromFile("test.docx")
'获取Section
Dim section As Section = doc.Sections(0)
'获取第一个表格
Dim table As Table = TryCast(section.Tables(0), Table)
'设置上边框
table.TableFormat.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.DotDash
table.TableFormat.Borders.Top.LineWidth = 2F
table.TableFormat.Borders.Top.Color = Color.Red
'设置右边框
table.TableFormat.Borders.Right.BorderType = Spire.Doc.Documents.BorderStyle.[Double]
table.TableFormat.Borders.Right.LineWidth = 2F
table.TableFormat.Borders.Right.Color = Color.Green
'设置下边框
table.TableFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.None
'设置左边框
table.TableFormat.Borders.Left.BorderType = Spire.Doc.Documents.BorderStyle.Hairline
table.TableFormat.Borders.Left.LineWidth = 2F
table.TableFormat.Borders.Left.Color = Color.Blue
'设置垂直边框
table.TableFormat.Borders.Vertical.BorderType = Spire.Doc.Documents.BorderStyle.Dot
table.TableFormat.Borders.Vertical.LineWidth = 2F
table.TableFormat.Borders.Vertical.Color = Color.Orange
'设置水平边框
table.TableFormat.Borders.Horizontal.BorderType = Spire.Doc.Documents.BorderStyle.Wave
table.TableFormat.Borders.Horizontal.LineWidth = 2F
table.TableFormat.Borders.Horizontal.Color = Color.Purple
'保存文档
doc.SaveToFile("SetTableBorder.docx", FileFormat.Docx2013)
System.Diagnostics.Process.Start("SetTableBorder.docx")
End Sub
End Class
End Namespace
表格边框设置效果:
2. 给Cell设置Border
Imports Spire.Doc
Imports System.Drawing
Namespace SetCellBorder_Doc
Class Program
Private Shared Sub Main(args As String())
'加载Word文档
Dim doc As New Document()
doc.LoadFromFile("test.docx")
'获取Section
Dim section As Section = doc.Sections(0)
'获取第一个表格
Dim table As Table = TryCast(section.Tables(0), Table)
'获取单元格,设置上、下边框
Dim cell1 As TableCell = table(0, 0)
cell1.CellFormat.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.[Single]
cell1.CellFormat.Borders.Top.LineWidth = 2F
cell1.CellFormat.Borders.Top.Color = Color.Red
cell1.CellFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.DashDotStroker
cell1.CellFormat.Borders.Bottom.LineWidth = 2F
cell1.CellFormat.Borders.Bottom.Color = Color.Pink
'获取单元格,设置左、右边框
Dim cell2 As TableCell = table(2, 2)
cell2.CellFormat.Borders.Left.BorderType = Spire.Doc.Documents.BorderStyle.Hairline
cell2.CellFormat.Borders.Left.LineWidth = 2F
cell2.CellFormat.Borders.Left.Color = Color.Yellow
cell2.CellFormat.Borders.Right.BorderType = Spire.Doc.Documents.BorderStyle.[Double]
cell2.CellFormat.Borders.Right.LineWidth = 2F
cell2.CellFormat.Borders.Right.Color = Color.HotPink
'保存文档
doc.SaveToFile("SetCellBorder.docx", FileFormat.Docx2013)
System.Diagnostics.Process.Start("SetCellBorder.docx")
End Sub
End Class
End Namespace
单元格边框设置效果: