VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx Namespace / XlsxDocumentEditor Class
    Класс XlsxDocumentEditor
    В этом разделе
    Представляет собой редактор низкого уровня для XLSX документа.
    Объектная модель
    OpenXmlDocumentImage XlsxDocumentSheet OpenXmlDocumentRootElement OpenXmlDocumentChart XlsxDocumentEditor
    Синтаксис
    Ремарки

    Этот редактор предназначен для низкоуровневого редактирования документа XSLX, т.е. редактор позволяет редактировать документ как XLSX документ:

    Если вы хотите редактировать XLSX документ с помощью команд высокого уровня (редактировать XLSX документ как документ электронной таблицы), используйте SpreadsheetEditor класс.

    Пример

    Вот C#/VB.NET код, который демонстрирует, как найти и заменить текст в XLSX документе (в примере используется шаблон документа)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);
        }
    }
    
    

    Иерархия наследования

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

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также