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 columns programmatically.
| Method | Description |
|---|---|
| insertColumn | Add one or more columns. @param columns - position, data and options of new columns.Jworksheet insertColumn(columns: { column: number; data?: (string | number | boolean)[]; options?: Record<string, any>; }[]): Promise<void>POST /api/:guid/:worksheetIndex/columns/insert |
| moveColumn | Move one or more columns. @param from - Index of the first column to be moved.@param to - Index where columns should be moved to.@param quantity - Number of columns to be moved.Jworksheet moveColumn(from: number, to: number, quantity: number): Promise<void>POST /api/:guid/:worksheetIndex/columns/move |
| deleteColumn | Remove one or more columns. @param columns - Indexes of the columns that should be removed.Jworksheet deleteColumn(columns: number[]): Promise<void>DELETE /api/:guid/:worksheetIndex/columns/:columnIndexes |
| setWidth | Define the width of one or multiple columns. @param column - column number(s). @param width - new width. Jworksheet setWidth(column: number, width: number): Promise<void>Jworksheet setWidth(column: number[], width: number | number[]): Promise<void> POST /api/:guid/:worksheetIndex/width |
| getWidth | Get the with of one or multiple columns. @param columns - column number. If not informed, all columns will be returned. Jworksheet getWidth(columns?: number | number[] : Promise<{ [columnNumber: string]: number; }>Jworksheet getWidth(columns?: undefined): Promise<number[]>; GET /api/:guid/:worksheetIndex/width/:columns |
| setColumnVisibility | Change the visibility of one or more columns. @param columns - affected columns. @param visible - column visibility. Jworksheet setColumnVisibility(columns: number | number[], visible: boolean): Promise<void> POST /api/:guid/:worksheetIndex/columns/showPOST /api/:guid/:worksheetIndex/columns/hide |
Examples
Section titled “Examples”Insert columns
Section titled “Insert 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 Jworksheet objectconst worksheet = spreadsheet.getWorksheet(0);
// Column dataconst data = ["1", "2", "3", "4", "5"];
// Column propertiesconst options = { title: "new A", type: "text",};
// Add a new column on the second position. Position start on zeroworksheet.insertColumn([{ column: 1, data, options,}]).then(() => { // It worked correctly});curl -X POST "http://localhost:8009/api/15eb1171-5a64-45bf-be96-f52b6125a045/0/columns/insert" \ -H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i" \ -H "Content-Type: application/json" \ -d '{ "columns": [ { "column": 1, "data": ["1", "2", "3", "4", "5"], "options": { "title": "new A", "type": "text" } } ] }'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);
// Get Jworksheet objectconst worksheet = spreadsheet.getWorksheet(0);
// Move the first column to the second positionworksheet.moveColumn(0, 1, 1).then(() => { // It worked correctly});curl -X POST "http://localhost:8009/api/15eb1171-5a64-45bf-be96-f52b6125a045/0/columns/move" \ -H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i" \ -H "Content-Type: application/json" \ -d '{ "from": 0, "to": 1, "count": 1 }'Delete columns
Section titled “Delete 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 Jworksheet objectconst worksheet = spreadsheet.getWorksheet(0);
// Delete first columnworksheet.deleteColumn([0, 2]).then(() => { // It worked correctly});curl -X DELETE "http://localhost:8009/api/15eb1171-5a64-45bf-be96-f52b6125a045/0/columns/0,2" \ -H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i"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);
// Get Jworksheet objectconst worksheet = spreadsheet.getWorksheet(0);
// Set the position of the third column to 200pxworksheet .setWidth(2, 200) .then(() => { // It worked correctly }) .catch((err) => { // Something went wrong console.log(err); });curl -X POST "http://localhost:8009/api/15eb1171-5a64-45bf-be96-f52b6125a045/0/width" \ -H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i" \ -H "Content-Type: application/json" \ -d '{ "column": 2, "width": 200 }'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);
// Get Jworksheet objectconst worksheet = spreadsheet.getWorksheet(0);
// Define the width of the forth and fifth columns to 250pxworksheet .setWidth([3, 4], 250) .then(() => { // It worked correctly }) .catch((err) => { // Something went wrong console.log(err); });curl -X POST "http://localhost:8009/api/15eb1171-5a64-45bf-be96-f52b6125a045/0/width" \ -H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i" \ -H "Content-Type: application/json" \ -d '{ "columns": [3, 4], "width": 250 }'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 Jworksheet objectconst worksheet = spreadsheet.getWorksheet(0);
// Get the width from multiple columnsworksheet.getWidth([3, 4]).then((widths) => { console.log(widths);});curl -X GET "http://localhost:8009/api/15eb1171-5a64-45bf-be96-f52b6125a045/0/width/3,4" \ -H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i"