VintaSoft Imaging .NET SDK 14.0: Documentation for .NET developer
In This Topic
    XLSX: Work with cells on XLSX page
    In This Topic
    SpreadsheetEditorControl and WpfSpreadsheetEditorControl controls allow to work (view, add, edit and delete) with cells of XLSX worksheet in desktop (WinForms, WPF) application.
    Cells can be changed visually manually using mouse/keyboard or programmatically.


    Add a cell to the XLSX worksheet

    Here is C#/VB.NET code that demonstrates how to add a cell to the focused XLSX worksheet:
    public void AddCellToXlsxWorksheet(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // insert empty cells in range of selected cells and shift columns to the right
        spreadsheetVisualEditor.InsertCellsAndShiftRight();
    
        // insert empty cells in range of selected cells and shift rows to down
        spreadsheetVisualEditor.InsertCellsAndShiftDown();
    }
    
    Public Sub AddCellToXlsxWorksheet(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' insert empty cells in range of selected cells and shift columns to the right
        spreadsheetVisualEditor.InsertCellsAndShiftRight()
    
        ' insert empty cells in range of selected cells and shift rows to down
        spreadsheetVisualEditor.InsertCellsAndShiftDown()
    End Sub
    


    Copy and paste cells of XLSX worksheet

    If you want to copy and paste the selected cells of XLSX worksheet using mouse, you should do the following steps:
    Here is C#/VB.NET code that demonstrates how to copy and paste cells of XLSX worksheet:
    public void CopyAndPasteXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // copy content (selected cells, cell text, etc) to the clipboard
        spreadsheetVisualEditor.CopyCells();
    
        // paste content (selected cells, cell text, etc) from the clipboard
        spreadsheetVisualEditor.PasteCells();
    }
    
    Public Sub CopyAndPasteXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' copy content (selected cells, cell text, etc) to the clipboard
        spreadsheetVisualEditor.CopyCells()
    
        ' paste content (selected cells, cell text, etc) from the clipboard
        spreadsheetVisualEditor.PasteCells()
    End Sub
    


    Cut and paste cells of XLSX worksheet

    If you want to cut and paste the selected cells of XLSX worksheet using mouse, you should do the following steps:
    Here is C#/VB.NET code that demonstrates how to cut and paste the cell of XLSX worksheet:
    public void CopyAndPasteXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // cut content(selected cells, cell text, etc) to the clipboard
        spreadsheetVisualEditor.CutCells();
    
        // paste content (selected cells, cell text, etc) from the clipboard
        spreadsheetVisualEditor.PasteCells();
    }
    
    Public Sub CopyAndPasteXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' cut content(selected cells, cell text, etc) to the clipboard
        spreadsheetVisualEditor.CutCells()
    
        ' paste content (selected cells, cell text, etc) from the clipboard
        spreadsheetVisualEditor.PasteCells()
    End Sub
    


    Change value of focused cell programmatically

    Here is C#/VB.NET code that demonstrates how to change the value of focused cell of XLSX worksheet:
    public void ChangeValueOfXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // get value or formula of focused cell
        string cellValue = spreadsheetVisualEditor.FocusedCellValue;
    
        // set value or formula of focused cell
        spreadsheetVisualEditor.FocusedCellValue = "0";
    }
    
    Public Sub ChangeValueOfXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' get value or formula of focused cell
        Dim cellValue As String = spreadsheetVisualEditor.FocusedCellValue
    
        ' set value or formula of focused cell
        spreadsheetVisualEditor.FocusedCellValue = "0"
    End Sub
    


    Change the value of focused cell using textbox in cell region (internal editor)

    If you want to change the value of focused cell of XLSX worksheet using mouse, you should do the following steps:

    Change the number format of selected cells of XLSX worksheet

    Here is C#/VB.NET code that demonstrates how to change the number format of focused cell of XLSX worksheet:
    public void ChangeNumberFormatOfXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // set the number format of selected cells
        spreadsheetVisualEditor.NumberFormat = "0";
    }
    
    Public Sub ChangeNumberFormatOfXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' set the number format of selected cells
        spreadsheetVisualEditor.NumberFormat = "0"
    End Sub
    


    Change the font properties of selected cells of XLSX worksheet

    Here is C#/VB.NET code that demonstrates how to change the font properties of focused cells of XLSX worksheet:
    public void ChangeFontPropertiesOfXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // get the font name for focused cell
        var fontName = spreadsheetVisualEditor.FontName;
        // set new font name for selected cells
        spreadsheetVisualEditor.FontName = "Impact";
    
        // get the font size for focused cell
        var fontSize = spreadsheetVisualEditor.FontSize;
        // set new font size for selected cells
        spreadsheetVisualEditor.FontSize = 16;
    
    
        // get the bold status of text of focused cell
        var isBold = spreadsheetVisualEditor.IsFontBold;
        // set new bold status for text in selected cells
        spreadsheetVisualEditor.IsFontBold = true;
    
        // get the italic status of text of focused cell
        var isItalic = spreadsheetVisualEditor.IsFontItalic;
        // set new italic status for text in selected cells
        spreadsheetVisualEditor.IsFontItalic = true;
    
        // get the underline status of text of focused cell
        var isUnderline = spreadsheetVisualEditor.IsFontUnderline;
        // set new underline status for text in selected cells
        spreadsheetVisualEditor.IsFontUnderline = true;
    
        // get the strikeout status of text of focused cell
        var isStrikeout = spreadsheetVisualEditor.IsFontStrikeout;
        // set new strikeout status for text in selected cells
        spreadsheetVisualEditor.IsFontStrikeout = true;
    
    
        // get font color of focused cell
        var fontColor = spreadsheetVisualEditor.FontColor;
        // set new font color for selected cells
        spreadsheetVisualEditor.FontColor = Vintasoft.Primitives.VintasoftColor.FromRgb(255, 0, 0);
    }
    
    Public Sub ChangeFontPropertiesOfXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' get the font name for focused cell
        Dim fontName = spreadsheetVisualEditor.FontName
        ' set new font name for selected cells
        spreadsheetVisualEditor.FontName = "Impact"
    
        ' get the font size for focused cell
        Dim fontSize = spreadsheetVisualEditor.FontSize
        ' set new font size for selected cells
        spreadsheetVisualEditor.FontSize = 16
    
    
        ' get the bold status of text of focused cell
        Dim isBold = spreadsheetVisualEditor.IsFontBold
        ' set new bold status for text in selected cells
        spreadsheetVisualEditor.IsFontBold = True
    
        ' get the italic status of text of focused cell
        Dim isItalic = spreadsheetVisualEditor.IsFontItalic
        ' set new italic status for text in selected cells
        spreadsheetVisualEditor.IsFontItalic = True
    
        ' get the underline status of text of focused cell
        Dim isUnderline = spreadsheetVisualEditor.IsFontUnderline
        ' set new underline status for text in selected cells
        spreadsheetVisualEditor.IsFontUnderline = True
    
        ' get the strikeout status of text of focused cell
        Dim isStrikeout = spreadsheetVisualEditor.IsFontStrikeout
        ' set new strikeout status for text in selected cells
        spreadsheetVisualEditor.IsFontStrikeout = True
    
    
        ' get font color of focused cell
        Dim fontColor = spreadsheetVisualEditor.FontColor
        ' set new font color for selected cells
        spreadsheetVisualEditor.FontColor = Vintasoft.Primitives.VintasoftColor.FromRgb(255, 0, 0)
    End Sub
    


    Change the text properties of selected cells of XLSX worksheet

    Here is C#/VB.NET code that demonstrates how to change the text properties of focused cells of XLSX worksheet:
    public void ChangeTextPropertiesOfXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // get the text horizontal alignment for focused cell
        var textHorizontalAlign = spreadsheetVisualEditor.TextHorizontalAlign;
    
        // set new text horizontal alignment for selected cells
        spreadsheetVisualEditor.TextHorizontalAlign = Vintasoft.Imaging.Office.Spreadsheet.Document.TextHorizontalAlign.Center;
    
    
        // get the text vertical alignment for focused cell
        var textVerticalAlign = spreadsheetVisualEditor.TextVerticalAlign;
    
        // set new text vertical alignment for selected cells
        spreadsheetVisualEditor.TextVerticalAlign = Vintasoft.Imaging.Office.Spreadsheet.Document.TextVerticalAlign.Bottom;
    }
    
    Public Sub ChangeTextPropertiesOfXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' get the text horizontal alignment for focused cell
        Dim textHorizontalAlign = spreadsheetVisualEditor.TextHorizontalAlign
    
        ' set new text horizontal alignment for selected cells
        spreadsheetVisualEditor.TextHorizontalAlign = Vintasoft.Imaging.Office.Spreadsheet.Document.TextHorizontalAlign.Center
    
    
        ' get the text vertical alignment for focused cell
        Dim textVerticalAlign = spreadsheetVisualEditor.TextVerticalAlign
    
        ' set new text vertical alignment for selected cells
        spreadsheetVisualEditor.TextVerticalAlign = Vintasoft.Imaging.Office.Spreadsheet.Document.TextVerticalAlign.Bottom
    End Sub
    


    Change the background color of selected cells of XLSX worksheet

    Here is C#/VB.NET code that demonstrates how to change the background color of focused cells of XLSX worksheet:
    public void ChangeBackgroundOfXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // get the background color of focused cell
        var backgroundColor = spreadsheetVisualEditor.FillColor;
    
        // set new background color for selected cells
        spreadsheetVisualEditor.FillColor = Vintasoft.Primitives.VintasoftColor.FromRgb(200, 150, 200);
    }
    
    Public Sub ChangeBackgroundOfXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' get the background color of focused cell
        Dim backgroundColor = spreadsheetVisualEditor.FillColor
    
        ' set new background color for selected cells
        spreadsheetVisualEditor.FillColor = Vintasoft.Primitives.VintasoftColor.FromRgb(200, 150, 200)
    End Sub
    


    Change the border of selected cells of XLSX worksheet

    Here is C#/VB.NET code that demonstrates how to change the border of focused cells of XLSX worksheet:
    public void ChangeBorderOfXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // create border style
        Vintasoft.Imaging.Office.Spreadsheet.Document.CellBorderStyle borderStyle = 
            Vintasoft.Imaging.Office.Spreadsheet.Document.CellBorderStyle.Dashed;
        // create border color
        Vintasoft.Primitives.VintasoftColor borderColor = Vintasoft.Primitives.VintasoftColor.Blue;
        // create border
        Vintasoft.Imaging.Office.Spreadsheet.Document.CellBorder border =
            new Vintasoft.Imaging.Office.Spreadsheet.Document.CellBorder(borderStyle, borderColor);
        // create outside borders (you can use different border for each side)
        Vintasoft.Imaging.Office.Spreadsheet.Document.CellBorders outsideBorders =
            new Vintasoft.Imaging.Office.Spreadsheet.Document.CellBorders(border, border, border, border);
        // create all borders
        Vintasoft.Imaging.Office.Spreadsheet.Document.CellsBorders allBorders =
            new Vintasoft.Imaging.Office.Spreadsheet.Document.CellsBorders(outsideBorders, border, border);
        // set borders to focused cells
        spreadsheetVisualEditor.CellsBorders = allBorders;
    
    
        // set new border color for selected cells
        spreadsheetVisualEditor.BordersColor = Vintasoft.Primitives.VintasoftColor.FromRgb(200, 150, 200);
    }
    
    Public Sub ChangeBorderOfXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' create border style
        Dim borderStyle As Vintasoft.Imaging.Office.Spreadsheet.Document.CellBorderStyle = Vintasoft.Imaging.Office.Spreadsheet.Document.CellBorderStyle.Dashed
        ' create border color
        Dim borderColor As Vintasoft.Primitives.VintasoftColor = Vintasoft.Primitives.VintasoftColor.Blue
        ' create border
        Dim border As New Vintasoft.Imaging.Office.Spreadsheet.Document.CellBorder(borderStyle, borderColor)
        ' create outside borders (you can use different border for each side)
        Dim outsideBorders As New Vintasoft.Imaging.Office.Spreadsheet.Document.CellBorders(border, border, border, border)
        ' create all borders
        Dim allBorders As New Vintasoft.Imaging.Office.Spreadsheet.Document.CellsBorders(outsideBorders, border, border)
        ' set borders to focused cells
        spreadsheetVisualEditor.CellsBorders = allBorders
    
    
        ' set new border color for selected cells
        spreadsheetVisualEditor.BordersColor = Vintasoft.Primitives.VintasoftColor.FromRgb(200, 150, 200)
    End Sub
    


    Clear contents of selected cells of XLSX worksheet

    If you want to clear contents of the selected cells of XLSX worksheet using mouse, you should do the following steps:
    Here is C#/VB.NET code that demonstrates how to clear contents of cells of XLSX worksheet:
    public void ClearXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // clear contents (value and formula) of selected cells
        spreadsheetVisualEditor.ClearCellsContents();
    }
    
    Public Sub ClearXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' clear contents (value and formula) of selected cells
        spreadsheetVisualEditor.ClearCellsContents()
    End Sub
    


    Merge and unmerge cells of XLSX worksheet

    Here is C#/VB.NET code that demonstrates how to merge and unmerge cells of XLSX worksheet:
    public void MergeAndUnmergeXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // merges the selected cells
        spreadsheetVisualEditor.MergeCells();
    
        // unmerges the selected cells
        spreadsheetVisualEditor.UnmergeCells();
    }
    
    Public Sub MergeAndUnmergeXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' merges the selected cells
        spreadsheetVisualEditor.MergeCells()
    
        ' unmerges the selected cells
        spreadsheetVisualEditor.UnmergeCells()
    End Sub
    


    Delete a cell from XLSX worksheet

    Here is C#/VB.NET code that demonstrates how to delete a cell from XLSX worksheet:
    public void DeleteCellFromXlsxWorksheet(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
    {
        // get visual editor for spreadsheet document
        Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
    
        // remove selected cells and shift columns to the left
        spreadsheetVisualEditor.RemoveCellsAndShiftLeft();
    
        // remove selected cells and shift rows to up
        spreadsheetVisualEditor.RemoveCellsAndShiftUp();
    }
    
    Public Sub DeleteCellFromXlsxWorksheet(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
        ' get visual editor for spreadsheet document
        Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
    
        ' remove selected cells and shift columns to the left
        spreadsheetVisualEditor.RemoveCellsAndShiftLeft()
    
        ' remove selected cells and shift rows to up
        spreadsheetVisualEditor.RemoveCellsAndShiftUp()
    End Sub