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

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

    
    Public Shared Sub XlsxCellExample()
        Dim templateFilename As String = "XlsxCell_template.xlsx"
        Dim outFilename As String = "XlsxCell.xlsx"
        Dim outPdfFilename As String = "XlsxCell.pdf"
    
        ' create XlsxDocumentEditor that allows to edit file "SetBarcodeImage_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 cell by reference (A1 format) and set cell fill color
            sheet.FindCellByName("B3").SetFillColor(System.Drawing.Color.Red)
            sheet.FindCellByName("D3").SetFillColor(System.Drawing.Color.Yellow)
            sheet.FindCellByName("C4").SetFillColor(System.Drawing.Color.Green)
            sheet.FindCellByName("D5").SetFillColor(System.Drawing.Color.Blue)
            sheet.FindCellByName("B5").SetFillColor(System.Drawing.Color.Pink)
    
            ' set cell formula
            Dim cellD16 As Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheetCell = sheet.FindCellByName("D8")
            cellD16.Formula = "SUM(B8,C8)"
            cellD16.Number = sheet.FindCellByName("B8").Number + sheet.FindCellByName("C8").Number
    
            ' find cell that contains text "[cell_name]"
            Dim cell As Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheetCell = sheet.FindCell("[cell_name]")
            ' set cell text to cell name in A1 format
            cell.Text = cell.Name
    
            ' 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 XlsxCellExample()
    {
        string templateFilename = "XlsxCell_template.xlsx";
        string outFilename = "XlsxCell.xlsx";
        string outPdfFilename = "XlsxCell.pdf";
    
        // create XlsxDocumentEditor that allows to edit file "SetBarcodeImage_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 cell by reference (A1 format) and set cell fill color
            sheet.FindCellByName("B3").SetFillColor(System.Drawing.Color.Red);
            sheet.FindCellByName("D3").SetFillColor(System.Drawing.Color.Yellow);
            sheet.FindCellByName("C4").SetFillColor(System.Drawing.Color.Green);
            sheet.FindCellByName("D5").SetFillColor(System.Drawing.Color.Blue);
            sheet.FindCellByName("B5").SetFillColor(System.Drawing.Color.Pink);
    
            // set cell formula
            Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheetCell cellD16 = sheet.FindCellByName("D8");
            cellD16.Formula = "SUM(B8,C8)";
            cellD16.Number = sheet.FindCellByName("B8").Number + sheet.FindCellByName("C8").Number;
    
            // find cell that contains text "[cell_name]"
            Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheetCell cell = sheet.FindCell("[cell_name]");
            // set cell text to cell name in A1 format
            cell.Text = cell.Name;
    
            // 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.OpenXmlDocumentTableCell
             Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheetCell

    Требования

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

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