CellValue class

Office 2013 and later

Cell Value. When the object is serialized out as xml, its qualified name is x:v.

Namespace:  DocumentFormat.OpenXml.Spreadsheet
Assembly:  DocumentFormat.OpenXml (in DocumentFormat.OpenXml.dll)

public class CellValue : XstringType

[ISO/IEC 29500-1 1st Edition]

v (Cell Value)

This element expresses the value contained in a cell. If the cell contains a string, then this value is an index into the shared string table, pointing to the actual string value. Otherwise, the value of the cell is expressed directly in this element. Cells containing formulas express the last calculated result of the formula in this element.

For applications not wanting to implement the shared string table, an 'inline string' can be expressed in an <is> element under <c> (instead of a <v> element under <c>),in the same way a string would be expressed in the shared string table. [Note: See <is> for an example. end note]

[Example:In this example cell B4 contains the number "360" and C4 contains the UTC date 22 November 1976, 08:30.

<c r="B4">
<c r="C4" t="d">

end example]

The possible values for this element are defined by the ST_Xstring simple type (§

Parent Elements

c (§; cell (§18.14.1); nc (§; oc (§; tp (§18.15.3)

[Note: The W3C XML Schema definition of this element’s content model (ST_Xstring) is located in §A.6.9. end note]

© ISO/IEC29500: 2008.

The following code example creates a spreadsheet file named "CellValue.xlsx" and writes the text "Microsoft" in the cell A2.

using System;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;

namespace CellTypeEx
    class Program
        static void Main(string[] args)
            string fileName = @"C:\Users\Public\Documents\CellValueEx.xlsx";

            // Create a spreadsheet document by supplying the fileName.
            SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.
                Create(fileName, SpreadsheetDocumentType.Workbook);

            // Add a WorkbookPart to the document.
            WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
            workbookpart.Workbook = new Workbook();

            // Add a WorksheetPart to the WorkbookPart.
            WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
            worksheetPart.Worksheet = new Worksheet(new SheetData());

            // Add Sheets to the Workbook.
            Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());

            // Append a new worksheet and associate it with the workbook.
            Sheet sheet = new Sheet()
                Id = spreadsheetDocument.WorkbookPart.
                SheetId = 1,
                Name = "mySheet"

            Worksheet worksheet = new Worksheet();
            SheetData sheetData = new SheetData();

            Row row = new Row() { RowIndex = 2U, Spans = new ListValue<StringValue>() };
            Cell cell = new Cell()
                CellReference = "A2",
                DataType = CellValues.String,
                CellValue = new CellValue("Microsoft")
            worksheetPart.Worksheet = worksheet;

            // Close the document.

            Console.WriteLine("All done.\nPress a key.");

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.