Excel for WPF | ComponentOne
Using Excel for WPF and Silverlight / Cells
In This Topic
    Cells
    In This Topic

    The XLSheet object also contains cells that can be accessed using an indexer that takes row and column indices. The cells are represented by XLCell objects that contain the cell value and style.

    As with rows and columns, the cell indexer also extends the sheet automatically. For example, write:

    Visual Basic
    Copy Code
    Dim cell As XLCell = sheet(10, 10)
    

     

    C#
    Copy Code
    XLCell cell = sheet[10,10];
    

    If the sheet has fewer than 11 rows and 11 columns, rows and columns will be added and a valid XLCell object will be returned.

    Because the sheet expands automatically, this indexer will never return a null reference. If you want to check whether a particular cell exists on the sheet and you don't want to create the cell inadvertently, use the sheet's GetCell method instead of the indexer.

    XLCell objects have a Value property that contains the cell contents. This property is of type object and it may contain strings, numeric, Boolean, DateTime, or null objects. Other types of objects cannot be saved into Excel files.

    XLCell objects also have a Style property that defines the appearance of the cell. If the Style property is set to null, the cell is displayed using the default style. Otherwise, it should be set to an XLStyle object that defines the appearance of the cell (font, alignment, colors, format, and so on).