VintaSoft Imaging .NET SDK 14.0: Documentation for .NET developer
Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx Namespace / XlsxDocumentEditor Class
Members Object Syntax Remarks Example Hierarchy Requirements SeeAlso
In This Topic
    XlsxDocumentEditor Class
    In This Topic
    Represents the low-level editor for XLSX document.
    Object Model
    OpenXmlDocumentImage XlsxDocumentSheet OpenXmlDocumentRootElement OpenXmlDocumentChart XlsxDocumentEditor
    Syntax
    Remarks

    This editor is intended for low-level editing of XSLX document, i.e. editor allows to edit document as an XLSX document:

    If you want to edit XLSX document using high-level commands (edit XLSX document as spreadsheet document), please use the SpreadsheetEditor class.

    Example

    This C#/VB.NET code shows how to find and replace text in XLSX document (example uses template document FindAndReplaceText_template.xlsx):

    
    Public Shared Sub XlsxFindAndReplaceTextExample()
        Dim templateFilename As String = "FindAndReplaceText_template.xlsx"
        Dim outFilename As String = "FindAndReplaceText.xlsx"
        Dim outPdfFilename As String = "FindAndReplaceText.pdf"
    
        ' create XlsxDocumentEditor that allows to edit file "FindAndReplaceText_template.xlsx"
        Using editor As New Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentEditor(templateFilename)
            ' get first sheet in XLSX document
            Dim sheet As Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheet = editor.Sheets(0)
    
            ' replace first occurrence of text "[field1]" by text "value1"
            sheet("[field1]") = "value1"
    
            ' replace all occurrences of text "[field2]" by text "value2"
            sheet.ReplaceText("[field2]", "value2")
    
            ' find text content that corresponds to the text "[field3]"
            Dim field3Content As Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlTextContent = sheet.FindText("[field3]")
            ' change text in found text content
            field3Content.Text = "value3"
    
            ' replace text "[multiline_field]" by multiline text
            sheet("[multiline_field]") = vbLf & "line1" & vbLf & "line2" & vbLf & "line3"
    
            ' save changed document to a XLSX file
            editor.Save(outFilename)
    
            ' export changed document to a PDF document
            editor.Export(outPdfFilename)
        End Using
    End Sub
    
    
    
    public static void XlsxFindAndReplaceTextExample()
    {
        string templateFilename = "FindAndReplaceText_template.xlsx";
        string outFilename = "FindAndReplaceText.xlsx";
        string outPdfFilename = "FindAndReplaceText.pdf";
    
        // create XlsxDocumentEditor that allows to edit file "FindAndReplaceText_template.xlsx"
        using (Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentEditor editor =
            new Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentEditor(templateFilename))
        {
            // get first sheet in XLSX document
            Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheet sheet = editor.Sheets[0];
    
            // replace first occurrence of text "[field1]" by text "value1"
            sheet["[field1]"] = "value1";
    
            // replace all occurrences of text "[field2]" by text "value2"
            sheet.ReplaceText("[field2]", "value2");
    
            // find text content that corresponds to the text "[field3]"
            Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlTextContent field3Content = sheet.FindText("[field3]");
            // change text in found text content
            field3Content.Text = "value3";
    
            // replace text "[multiline_field]" by multiline text
            sheet["[multiline_field]"] = "\nline1\nline2\nline3";
    
            // save changed document to a XLSX file
            editor.Save(outFilename);
    
            // export changed document to a PDF document
            editor.Export(outPdfFilename);
        }
    }
    
    

    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentEditor
          Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentEditor

    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