Class: Workbook

Core.SpreadsheetEditor. Workbook

Represents a Workbook in the spreadsheet editor that encapsulates a collection of sheets along with operations to manipulate them.

new Workbook()

Properties:
Name Type Description
activeSheetIndex number Gets the current active sheet index.
sheetCount number Gets the number of sheets currently in the Workbook.

Methods


createCellStyle( [options])

Creates and returns a new CellStyle object, allowing for the customization of cell appearance within the Workbook.
Parameters:
Name Type Argument Description
options Core.SpreadsheetEditor.CellStyleOptions <optional>
The options to customize the cell style.
Properties
Name Type Argument Description
backgroundColor string <optional>
The background color of a cell within a sheet.
horizontalAlignment Core.SpreadsheetEditor.Types.HorizontalAlignment <optional>
The horizontal alignment of the cell's content within a sheet to determine the positioning of its content along the horizontal axis within the boundaries.
verticalAlignment Core.SpreadsheetEditor.Types.VerticalAlignment <optional>
The vertical alignment of the cell's content to determine the positioning of its content along the vertical axis within the boundaries.
wrapText Core.SpreadsheetEditor.Types.TextWrap <optional>
The text wrapping behavior within the cell to allow control on text exceeding the cell's width.
font Core.SpreadsheetEditor.Font <optional>
The font styling of a cell's content within a sheet.
Returns:
A new instance of the CellStyle object, which can be customized and then applied to cells within the Workbook.
Type
Core.SpreadsheetEditor.CellStyle
Example
const { Core } = window.getInstance();
const Types = Core.SpreadsheetEditor.Types;
const workbook = Core.documentViewer.getDocument().getSpreadsheetEditorDocument().getWorkbook();
const cellStyle = workbook.createCellStyle();
cellStyle.backgroundColor = 'red';
cellStyle.horizontalAlignment = Types.HorizontalAlignment.RIGHT;
cellStyle.verticalAlignment = Types.VerticalAlignment.TOP;
cellStyle.wrapText = Types.TextWrap.WRAP;
const cell = workbook.getSheetAt(0).getRowAt(0).getCellAt(0);
cell.setStyle(cellStyle);

createFont(fontObject)

Creates a Font object to customize the text appearance in a workbook.
Parameters:
Name Type Description
fontObject object An object containing the font attributes.
Properties
Name Type Argument Description
fontFace string A string specifying the name of the font. Supports any valid CSS font family name, such as web-safe fonts or fonts available in the environment.
pointSize number A number representing the font size in points.
color string A string specifying the color of the font. Support any valid CSS color. Alpha is not supported.
bold boolean <optional>
A boolean indicating whether the font should be bold. Defaults to false.
italic boolean <optional>
A boolean indicating whether the font should be italic. Defaults to false.
underline boolean <optional>
A boolean indicating whether the font should be underlined. Defaults to false.
strikeout boolean <optional>
A boolean indicating whether the font should have a strikeout effect. Defaults to false.
Returns:
A new Font instance with provided font attributes.
Type
Core.SpreadsheetEditor.Font
Example
const { Core } =  window.getInstance();
const { documentViewer, SpreadsheetEditor } = Core;
const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
const FontStyles = SpreadsheetEditor.Types.FontStyle;
const workbook = documentViewer.getDocument().getSpreadsheetEditorDocument().getWorkbook();
const fontFace = 'Calibri';
const pointSize = 12;
const color = 'red';
const font = workbook.createFont({
  fontFace,
  pointSize,
  color,
  bold: true,
  italic: true,
  underline: true
});

const cell = workbook.getSheetAt(0).getRowAt(0).getCellAt(0);
const style = cell.getStyle();
style.font = font;
cell.setStyle(style);

createSheet(sheetName)

Creates and adds a new sheet to the Workbook with the specified name. Allows for the dynamic expansion of the Workbook by adding additional sheets.
Parameters:
Name Type Description
sheetName string A string specifying the name of the new sheet. Sheet names must be unique within the Workbook and should not contain illegal characters.

getSheet(sheetName)

Retrieves a sheet from the Workbook based on the specified name.
Parameters:
Name Type Description
sheetName string A string specifying the name of the sheet to retrieve. The sheet name must exactly match the name of an existing sheet within the Workbook, considering case sensitivity.
Returns:
The Sheet object corresponding to the specified name.
Type
Core.SpreadsheetEditor.Sheet

hideSheet(sheetName)

Modifies the visibility of a specified sheet within the Workbook to be hidden
Parameters:
Name Type Description
sheetName string A string specifying the name of the sheet whose visibility is to be changed. The sheet name must exactly match an existing sheet in the Workbook, including case sensitivity.

isSheetHidden(sheetName)

Determines whether a specified sheet within the Workbook is hidden. This method checks the visibility state of a sheet by its name.
Parameters:
Name Type Description
sheetName string A string specifying the name of the sheet whose visibility status is to be checked. The sheet name must exactly match an existing sheet in the Workbook, including case sensitivity.
Returns:
true if the specified sheet is hidden; otherwise, false.
Type
boolean

removeSheet(sheetName)

Removes a sheet from the Workbook by name. Allows for the deletion of a specified sheet within the Workbook, facilitating dynamic management of the Workbook's content and structure.
Parameters:
Name Type Description
sheetName string A string specifying the name of the sheet to be removed. The sheet name must exactly match an existing sheet in the Workbook, including case sensitivity.

setActiveSheet(activeSheetIndex)

Sets the specified sheet as the active sheet in a spreadsheet.
Parameters:
Name Type Description
activeSheetIndex number Sets the active sheet by its zero-based index, where the first sheet is 0, the second is 1, and subsequent sheets follow in sequence.

unhideSheet(sheetName)

Modifies the visibility of a specified sheet within the Workbook to be visible
Parameters:
Name Type Description
sheetName string A string specifying the name of the sheet whose visibility is to be changed. The sheet name must exactly match an existing sheet in the Workbook, including case sensitivity.