VintaSoft Imaging .NET SDK 14.0: Documentation for .NET developer
Vintasoft.Imaging.Office.OpenXml.Editor Namespace / OpenXmlDocumentTable Class / SetOutsideBorder Methods / SetOutsideBorder(OpenXmlDocumentTableCell,OpenXmlDocumentTableCell,OpenXmlDocumentTableCell) Method
Syntax Exceptions Example Requirements SeeAlso
In This Topic
    SetOutsideBorder(OpenXmlDocumentTableCell,OpenXmlDocumentTableCell,OpenXmlDocumentTableCell) Method (OpenXmlDocumentTable)
    In This Topic
    Sets the outside border of rectangular area.
    Syntax
    'Declaration
    
    Public Overloads Sub SetOutsideBorder( _
    ByVal firstCell
    The first cell of rectangular area.
    As OpenXmlDocumentTableCell, _
    ByVal lastCell
    The last cell of rectangular area.
    As OpenXmlDocumentTableCell, _
    ByVal borderSource
    The cell from which border style must be copied.
    As OpenXmlDocumentTableCell _
    )

    Parameters

    firstCell
    The first cell of rectangular area.
    lastCell
    The last cell of rectangular area.
    borderSource
    The cell from which border style must be copied.
    Exceptions
    ExceptionDescription
    Thrown if firstCell or lastCell is null.
    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: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also