VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx Namespace / XlsxDocumentSheet Class
Члены типа Объект Синтаксис Example Иерархия Требования Смотрите также
В этом разделе
    Класс XlsxDocumentSheet
    В этом разделе
    Представляет рабочий лист XLSX документа.
    Объектная модель
    XlsxDocumentSheetFormat XlsxDocumentSheetView XlsxDocumentSheetDrawing OpenXmlDocumentImage XlsxDocumentMergeCells XlsxDocumentHyperlinks OpenXmlDocumentTableRow OpenXmlDocumentTableCell OpenXmlDocumentElement OpenXmlDocumentElement OpenXmlDocumentElement OpenXmlDocumentElement OpenXmlDocumentElementCollection OpenXmlDocumentRootElement XlsxDocumentSheet
    Синтаксис
    Пример

    Вот C#/VB.NET код, который демонстрирует, как заполнить таблицу данных (в примере используется документ-шаблон).CopyTableRow_template.xlsx):

    
    Public Shared Sub XlsxCopyTableRowExample()
        Dim templateFilename As String = "CopyTableRow_template.xlsx"
        Dim outFilename As String = "CopyTableRow.xlsx"
        Dim outPdfFilename As String = "CopyTableRow.pdf"
    
        ' create XlsxDocumentEditor that allows to edit file "CopyTableRow_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)
    
            ' find  row that contains text "[cell1]"
            Dim templateRow As Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTableRow = sheet.FindRow("[cell1]")
    
            ' create an array that contains colors
            Dim colors As System.Drawing.Color() = New System.Drawing.Color() {System.Drawing.Color.Red, System.Drawing.Color.Green, System.Drawing.Color.Blue, System.Drawing.Color.Orange, System.Drawing.Color.Yellow}
            ' for each color
            For i As Integer = 0 To colors.Length - 1
                ' insert copy of template row before template row
                Dim rowCopy As Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTableRow = DirectCast(templateRow.InsertCopyBeforeSelf(), Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTableRow)
    
                ' set row data
                rowCopy(0).Text = String.Format("Copy {0} ({1})", i, colors(i))
                rowCopy("[cell1]") = String.Format("cell data {0}", i)
    
                ' set cell colors
                rowCopy(1).SetFillColor(colors(i))
                rowCopy(2).SetFillColor(colors(i))
    
                ' if color has odd index in colors array
                If i Mod 2 = 1 Then
                    ' set row height to 10mm
                    rowCopy.Height = Vintasoft.Imaging.Utils.UnitOfMeasureConverter.ConvertToPoints(10, Vintasoft.Imaging.UnitOfMeasure.Millimeters)
                End If
            Next
    
            ' remove template row
            templateRow.Remove()
    
            ' 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 XlsxCopyTableRowExample()
    {
        string templateFilename = "CopyTableRow_template.xlsx";
        string outFilename = "CopyTableRow.xlsx";
        string outPdfFilename = "CopyTableRow.pdf";
    
        // create XlsxDocumentEditor that allows to edit file "CopyTableRow_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];
    
            // find  row that contains text "[cell1]"
            Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTableRow templateRow = sheet.FindRow("[cell1]");
    
            // create an array that contains colors
            System.Drawing.Color[] colors = new System.Drawing.Color[] {
                System.Drawing.Color.Red,
                System.Drawing.Color.Green,
                System.Drawing.Color.Blue,
                System.Drawing.Color.Orange,
                System.Drawing.Color.Yellow
            };
            // for each color
            for (int i = 0; i < colors.Length; i++)
            {
                // insert copy of template row before template row
                Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTableRow rowCopy = 
                    (Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTableRow)templateRow.InsertCopyBeforeSelf();
    
                // set row data
                rowCopy[0].Text = string.Format("Copy {0} ({1})", i, colors[i]);
                rowCopy["[cell1]"] = string.Format("cell data {0}", i);
    
                // set cell colors
                rowCopy[1].SetFillColor(colors[i]);
                rowCopy[2].SetFillColor(colors[i]);
    
                // if color has odd index in colors array
                if (i % 2 == 1)
                {
                    // set row height to 10mm
                    rowCopy.Height = Vintasoft.Imaging.Utils.UnitOfMeasureConverter.ConvertToPoints(10, Vintasoft.Imaging.UnitOfMeasure.Millimeters);
                }
            }
    
            // remove template row
            templateRow.Remove();
    
            // 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.OpenXmlDocumentElement
          Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentTable
             Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheet

    Требования

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

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