[]
        
(Showing Draft Content)

Cell Types

GcExcel supports Button, CheckBox, ComboBox, and Hyperlink cell types. These cell types define the type of information in a cell and its behavior.

Cell types can be defined for a cell, range of cells, row, column or a worksheet. GcExcel library provides the CellType property in IRange interface to get or set cell type for a cell or range of cells. If the cell types are different in a range of cells, the cell type of the top-left cell of the range will be returned. The CellType property of IWorksheet interface can be used to get or set cell type for a worksheet. Further, the EntireColumn and EntireRow property of IRange interface can be used to get or set cell types for columns and rows respectively.

Note: Cell types are not supported by Excel. So, these are lost after saving to Excel files. But the cell types work well with SpreadJS, and is retained during JSON I/O with SpreadJS.

Button Cell Type

Refer to the following code to create a Button cell type:

public void ButtonCellTypes()
{
    // Initialize workbook
    Workbook workbook = new Workbook();
    // Fetch default worksheet 
    IWorksheet worksheet = workbook.Worksheets[0];

    //Creating Button cell type
    ButtonCellType button = new ButtonCellType();
    button.Text = "Click Me..!!";
    button.ButtonBackColor = "LightBlue";
    button.MarginLeft = 10;
    worksheet.Range["A1:B2"].CellType = button;

    // Saving workbook to Pdf
    workbook.Save(@"ButtonCellTypes.pdf", SaveFileFormat.Pdf);
    
}

CheckBox Cell Type

Refer to the following code to create a CheckBox cell type:

public void CheckBoxCellTypes()
{
    // Initialize workbook
    Workbook workbook = new Workbook();
    // Fetch default worksheet 
    IWorksheet worksheet = workbook.Worksheets[0];

    // Creating CheckBoxCellType
    CheckBoxCellType checkBox = new CheckBoxCellType();
    checkBox.Caption = "Caption";
    checkBox.TextTrue = "True";
    checkBox.TextFalse = "False";
    checkBox.IsThreeState = false;
    worksheet.Range["A1:C3"].CellType = checkBox;

    worksheet.Range["A1"].Value = true;
    worksheet.Range["B2"].Value = true;

    // Saving workbook to Pdf
    workbook.Save(@"CheckBoxCellTypes.pdf", SaveFileFormat.Pdf);


}

ComboBox Cell Type

Refer to the following code to create a ComboBox cell type:

public void ComboCellTypes()
{
    // Initialize workbook
    Workbook workbook = new Workbook();
    // Fetch default worksheet 
    IWorksheet worksheet = workbook.Worksheets[0];

    // Creating ComboBoxCellType
    ComboBoxCellType comboBox = new ComboBoxCellType();
    comboBox.EditorValueType = EditorValueType.Value;

    ComboBoxCellItem comboItem = new ComboBoxCellItem();
    comboItem.Value = "US";
    comboItem.Text = "United States";
    comboBox.Items.Add(comboItem);

    comboItem = new ComboBoxCellItem();
    comboItem.Value = "CN";
    comboItem.Text = "China";
    comboBox.Items.Add(comboItem);

    comboItem = new ComboBoxCellItem();
    comboItem.Value = "JP";
    comboItem.Text = "Japan";
    comboBox.Items.Add(comboItem);

    worksheet.Range["A1:B2"].CellType = comboBox;
    worksheet.Range["A1"].Value = "CN";

    // Saving workbook to Pdf
    workbook.Save(@"ComboCellTypes.pdf", SaveFileFormat.Pdf);
}

Refer to the following code to create a Hyperlink cell type:

public void HyperlinkCellTypes()
{
    // Initialize workbook
    Workbook workbook = new Workbook();
    // Fetch default worksheet 
    IWorksheet worksheet = workbook.Worksheets[0];

    // Creating HyperLinkCellType
    HyperLinkCellType hyperlinkCell = new HyperLinkCellType();
    hyperlinkCell.Text = "GrapeCity Website";
    hyperlinkCell.LinkColor = "Blue";
    hyperlinkCell.LinkToolTip = "GrapeCity Website";
    hyperlinkCell.VisitedLinkColor = "Green";
    hyperlinkCell.Target = HyperLinkTargetType.Blank;

    worksheet.Range["A1"].CellType = hyperlinkCell;
    worksheet.Range["A1"].Value = "https://www.grapecity.com/";

    // Saving workbook to Pdf
    workbook.Save(@"HyperlinkCellTypes.pdf", SaveFileFormat.Pdf);
}