VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging.Office.OpenXml.Editor Namespace / OpenXmlDocumentTableRow Class / SetBorder Methods / SetBorder(OpenXmlDocumentTableCell) Method
Syntax Example Requirements SeeAlso
In This Topic
SetBorder(OpenXmlDocumentTableCell) Method (OpenXmlDocumentTableRow)
In This Topic
Sets the border of this row from specified table cell.
Syntax
'Declaration

Public Overloads Sub SetBorder( _
ByVal borderSource
The cell from which border style must be copied.
As OpenXmlDocumentTableCell _
)

Parameters

borderSource
The cell from which border style must be copied.
Example

This C#/VB.NET code shows how to set table borders from sample table cell (example uses template document SetTableBorders_template.docx):


Public Shared Sub DocxSetTableBordersExample()
    Dim templateFilename As String = "SetTableBorders_template.docx"
    Dim outFilename As String = "SetTableBorders.docx"
    Dim outPdfFilename As String = "SetTableBorders.pdf"

    ' create DocxDocumentEditor that allows to edit file "SetTableBorders_template.docx"
    Using editor As New Vintasoft.Imaging.Office.OpenXml.Editor.Docx.DocxDocumentEditor(templateFilename)
        ' get cell border templates
        Dim bordersTemplateTable As Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTable = editor.Tables(0)
        Dim boldBorderTemplate As Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTableCell = bordersTemplateTable.FindCell("[bold]")
        Dim colorBorderTemplate As Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTableCell = bordersTemplateTable.FindCell("[color]")

        ' remove border template table
        bordersTemplateTable.Remove()

        ' get test table
        Dim table As Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTable = editor.Tables(0)

        ' set borders from template cells
        table.FindRow("[bold_row]").SetBorder(boldBorderTemplate)
        table.FindCell("[bold_cell]").SetBorder(boldBorderTemplate)
        table.FindRow("[color_row]").SetBorder(colorBorderTemplate)
        table.FindCell("[color_cell]").SetBorder(colorBorderTemplate)

        ' set outside border inside table
        table.SetOutsideBorder(table.FindCell("[bold_first]"), table.FindCell("[bold_last]"), boldBorderTemplate)

        ' save changed document to a DOCX file
        editor.Save(outFilename)

        ' export changed document to a PDF document
        editor.Export(outPdfFilename)
    End Using
End Sub


public static void DocxSetTableBordersExample()
{
    string templateFilename = "SetTableBorders_template.docx";
    string outFilename = "SetTableBorders.docx";
    string outPdfFilename = "SetTableBorders.pdf";

    // create DocxDocumentEditor that allows to edit file "SetTableBorders_template.docx"
    using (Vintasoft.Imaging.Office.OpenXml.Editor.Docx.DocxDocumentEditor editor =
        new Vintasoft.Imaging.Office.OpenXml.Editor.Docx.DocxDocumentEditor(templateFilename))
    {
        // get cell border templates
        Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTable bordersTemplateTable =
            editor.Tables[0];
        Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTableCell boldBorderTemplate =
            bordersTemplateTable.FindCell("[bold]");
        Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTableCell colorBorderTemplate =
            bordersTemplateTable.FindCell("[color]");

        // remove border template table
        bordersTemplateTable.Remove();

        // get test table
        Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTable table = editor.Tables[0];

        // set borders from template cells
        table.FindRow("[bold_row]").SetBorder(boldBorderTemplate);
        table.FindCell("[bold_cell]").SetBorder(boldBorderTemplate);
        table.FindRow("[color_row]").SetBorder(colorBorderTemplate);
        table.FindCell("[color_cell]").SetBorder(colorBorderTemplate);

        // set outside border inside table
        table.SetOutsideBorder(table.FindCell("[bold_first]"), table.FindCell("[bold_last]"), boldBorderTemplate);

        // save changed document to a DOCX file
        editor.Save(outFilename);

        // export changed document to a PDF document
        editor.Export(outPdfFilename);
    }
}

Requirements

Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also