Skip to main content
Version: 4.1

VisioSheetObject

VisioSheetObject is an abstract class that allows for manipulation of cells within an object with sheet.

Classes inheriting from VisioSheetObject are VisioShape and VisioRow.

Any cells manipulation should be done only using the VisioSheetObject API.

Cell names​

Cell names are case-sensitive and should follow camel-case naming convention, while the name property in the cell object uses pascal-case naming convention. Having that difference in mind, when using getCell method, always use camel-case names, otherwise undefined will be returned.

Cell structure​

Each cell is an object with name, value properties. Optionally formula and units can be defined.

Methods​

getCell()​

sheetObject.getCell(name: types.VisioCellName | string): VisioCell | null;

Return a cell object with the given cellName. If cell with given name does not exist, return undefined. cellName is case sensitive and should use camel-case naming convention.

console.log(vsdShape.getCell(VisioCellName.PinX));
// {value: "1", units: "IN", name: "PinX"}

getOwnCellNames()​

sheetObject.getOwnCellNames(): string[];

Return an array of cell names defined as own for the sheet object. Does not include inherited cell names.

removeCell()​

sheetObject.removeCell(name: types.VisioCellName | string): void;

Remove cell with the given cellName from the sheet object. cellName is case sensitive and should use camel-case naming convention.

vsdShape.removeCell(VisioCellName.PinX)

setCell()​

sheetObject.setCell(name: types.VisioCellName | string, attributes: Partial<VisioCellAttributes>): void;

setCell allows for adding or updating a cell within the sheet object. Important thing to note is that knowledge about Visio Cells is required to properly set cells in certain scenarios, i.e. units might be required to properly evaluate the value in Visio.

Inheriting and overriding attributes​

Passing null as any of the cellAttributes will remove the attribute from the cell, which will in return fallback to inherited value. If the intention is to override any attribute, set it to an empty string, i.e. {formula:''}. Not passing any of the attributes will skip them, and existing ones will be kept.

setCell(name: types.VisioCellName | string, attributes: Partial<VisioCellAttributes>): void;

cellName​

cellName should use camel-case naming of cells. Full list of accepted cell names can be found in Visio documentation.

cellAttributes​

interface VisioCellAttributes {
value: any;
formula: string | null;
units: string | null;
}
value​

value should be passed as strings (case-sensitive).

formula​

formula are case-sensitive and should be passed as strings. Note, that exporting project to vsdx using visioArchive.toVSDX() will trigger re-evaluation of all formulas on first startup of the project in Visio.

units​

units should be set as string and are case-sensitive. For the list of units refer to types.VisioUnitType.

Below code will update width cell (or create it if it doesn't exist), setting value to '1', units to 'IN' and inheriting the formula.

// shape cell
vsdShape.setCell(VisioCellName.Width, { value: '1', units: VisioUnitType.IN });

// property section row cell
vsdRow.setCell(VisioCellName.Value, { value: '1', formula: null, units: VisioUnitType.BOOL });

Stay in the know

Be where thousands of diagramming enthusiasts meet

Star us on GitHub