Products

Columns

The following methods are available for column operations.

Documentation

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

Insert columns

Add a new column in a specific position

import { Client } from "@intrasheets/client";

// Create a new client
const client = new Client({
  // API Server
  baseUrl: "http://localhost:8009/api",
  // Your authentication token
  token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});

// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Insert before flag
const insertBefore = true;

// Column properties
const properties = [{
    title: "new A",
    type: "text",
}];

// Add a new column on the second position. Position start on zero
spreadsheet.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

import { Client } from "@intrasheets/client";

// Create a new client
const client = new Client({
  // API Server
  baseUrl: "http://localhost:8009/api",
  // Your authentication token
  token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});

// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Insert before flag
const insertBefore = false;

// Column properties
const properties = [
    {
        title: "new A",
        type: "text",
    },
];

// Add a new column at the end
spreadsheet.insertColumn({
    numOfColumns: 1,
    insertBefore,
    properties,
}).then(() => {
    // It worked correctly
}).catch((err) => {
    // Something went wrong
    console.log(err);
});

Column position

Change a column position

import { Client } from "@intrasheets/client";

// Create a new client
const client = new Client({
  // API Server
  baseUrl: "http://localhost:8009/api",
  // Your authentication token
  token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});

// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Move the first column to the second position
spreadsheet.moveColumn(0, 1).then(() => {
    // It worked correctly
}).catch((err) => {
    // Something went wrong
    console.log(err);
});

Delete columns

Delete the column from a specific position

import { Client } from "@intrasheets/client";

// Create a new client
const client = new Client({
  // API Server
  baseUrl: "http://localhost:8009/api",
  // Your authentication token
  token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});

// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Delete first column
spreadsheet.deleteColumn(0).then(() => {
    // It worked correctly
})
.catch((err) => {
    // Something went wrong
    console.log(err);
});

Delete multiple columns

import { Client } from "@intrasheets/client";

// Create a new client
const client = new Client({
  // API Server
  baseUrl: "http://localhost:8009/api",
  // Your authentication token
  token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});

// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Delete the first 2 columns
spreadsheet.deleteColumn(0, 2).then(() => {
    // It worked correctly
})
.catch((err) => {
    // Something went wrong
    console.log(err);
});

Column width

Define the width of a column

import { Client } from "@intrasheets/client";

// Create a new client
const client = new Client({
  // API Server
  baseUrl: "http://localhost:8009/api",
  // Your authentication token
  token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});

// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Set the position of the third column to 200px
spreadsheet.setWidth(2, 200).then(() => {
    // It worked correctly
})
.catch((err) => {
    // Something went wrong
    console.log(err);
});

Define the width of multiple columns

import { Client } from "@intrasheets/client";

// Create a new client
const client = new Client({
  // API Server
  baseUrl: "http://localhost:8009/api",
  // Your authentication token
  token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});

// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Define the width of the forth and fifth columns to 250px
spreadsheet.setWidth([3, 4], 250).then(() => {
    // It worked correctly
})
.catch((err) => {
    // Something went wrong
    console.log(err);
});

Get the width from multiple columns

import { Client } from "@intrasheets/client";

// Create a new client
const client = new Client({
  // API Server
  baseUrl: "http://localhost:8009/api",
  // Your authentication token
  token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});

// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Get the width from multiple columns
spreadsheet.getWidth([3, 4]).then((widths) => {
    console.log(widths);
});

// {
//     "3": 250,
//     "4": 250,
// }