Columns
The following methods are available for column operations.
Documentation
Section titled “Documentation”Methods
Section titled “Methods”The following methods are available to interact with the spreadsheet headers programmatically.
| Method | Description |
|---|---|
| insertColumn | Add a new column. @param options.data - new column data. @param options.properties - new column properties. @param options.insertBefore - insert before or after the reference column. @param options.numOfColumns - number of columns to insert. @param options.columnNumber - reference column for insert. Jspreadsheet insertColumn(options: { data?: string[][], properties?: Column[], insertBefore?: boolean, numOfColumns: number, columnNumber?: number }): Promise<void> POST /api/:guid/columns |
| moveColumn | Change the column position. @param from - column number. @param to - to the position. Jspreadsheet moveColumn(from: number, to: number): Promise<void> POST /api/:guid/columns/move |
| deleteColumn | Delete one or multiple columns. @param columnNumber - column number. @param numOfColumns - number of columns. The default is 1. Jspreadsheet deleteColumn(columnNumber: number, numOfColumns?: number): Promise<void> POST /api/:guid/columns/delete |
| setWidth | Define the width of one or multiple columns. @param column - column number(s). @param width - new width. `Jspreadsheet setWidth(column: number |
| getWidth | Get the with of one or multiple columns. @param columns - column number. If not informed, all columns will be returned. `Jspreadsheet getWidth(columns?: number |
Examples
Section titled “Examples”Insert columns
Section titled “Insert columns”Add a new column in a specific position
Section titled “Add a new column in a specific position”import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Insert before flagconst insertBefore = true;
// Column propertiesconst properties = [{ title: "new A", type: "text",}];
// Add a new column on the second position. Position start on zerospreadsheet.insertColumn({ columnNumber: 1, numOfColumns: 1, insertBefore, properties,}).then(() => { // It worked correctly}).catch((err) => { // Something went wrong console.log(err);});Add a new column at the end with data
Section titled “Add a new column at the end with data”import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Insert before flagconst insertBefore = false;
// Column propertiesconst properties = [ { title: "new A", type: "text", },];
// Add a new column at the endspreadsheet.insertColumn({ numOfColumns: 1, insertBefore, properties,}).then(() => { // It worked correctly}).catch((err) => { // Something went wrong console.log(err);});Column position
Section titled “Column position”Change a column position
Section titled “Change a column position”import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Move the first column to the second positionspreadsheet.moveColumn(0, 1).then(() => { // It worked correctly}).catch((err) => { // Something went wrong console.log(err);});Delete columns
Section titled “Delete columns”Delete the column from a specific position
Section titled “Delete the column from a specific position”import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Delete first columnspreadsheet.deleteColumn(0).then(() => { // It worked correctly}).catch((err) => { // Something went wrong console.log(err);});Delete multiple columns
Section titled “Delete multiple columns”import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Delete the first 2 columnsspreadsheet.deleteColumn(0, 2).then(() => { // It worked correctly}).catch((err) => { // Something went wrong console.log(err);});Column width
Section titled “Column width”Define the width of a column
Section titled “Define the width of a column”import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Set the position of the third column to 200pxspreadsheet.setWidth(2, 200).then(() => { // It worked correctly}).catch((err) => { // Something went wrong console.log(err);});Define the width of multiple columns
Section titled “Define the width of multiple columns”import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Define the width of the forth and fifth columns to 250pxspreadsheet.setWidth([3, 4], 250).then(() => { // It worked correctly}).catch((err) => { // Something went wrong console.log(err);});Get the width from multiple columns
Section titled “Get the width from multiple columns”import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Get the width from multiple columnsspreadsheet.getWidth([3, 4]).then((widths) => { console.log(widths);});
// {// "3": 250,// "4": 250,// }