### RichTextFragment.style() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/RichTextFragment.md Demonstrates getting and setting styles on a fragment. Shows chaining, getting multiple styles, and setting styles via object. ```javascript const fragment = cell.value().add('bold text', { bold: true }); fragment.style('italic', true); const styles = fragment.style(['bold', 'italic']); fragment.style({ bold: false, fontColor: 'FF0000' }); ``` -------------------------------- ### name() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Sheet.md Shows how to set and get the sheet name. ```javascript sheet.name("renamed"); const n = sheet.name(); ``` -------------------------------- ### property() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Workbook.md Shows setting a single property, getting a property, and setting multiple properties at once. ```javascript workbook.property("author", "Dave"); const title = workbook.property("title"); workbook.property({ title: "Report", subject: "Q3" }); ``` -------------------------------- ### Install with bower for browser Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Install xlsx-populate with bower for browser usage. After including, the module is available globally as XlsxPopulate. ```bash bower install xlsx-populate ``` -------------------------------- ### Install npm dependencies Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Install the project's npm dependencies from the project root after checking out the code. ```bash npm install ``` -------------------------------- ### Install with npm for Node.js Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Use this command to install xlsx-populate via npm. Requires Node.js v4+ because the library uses ES6 features. ```bash npm install xlsx-populate ``` -------------------------------- ### Row.style() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Row.md Examples of setting and getting row styles. The first sets the bold style, the second retrieves the bold value, and the third sets multiple styles at once. ```javascript sheet.row(1).style("bold", true); const bold = sheet.row(1).style("bold"); sheet.row(1).style({ bold: true, italic: true }); ``` -------------------------------- ### toFileAsync() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Workbook.md Shows saving to a file with promise handling and with password encryption. The second example includes a try/catch for browser-only errors. ```javascript workbook.toFileAsync("./out.xlsx") .then(() => console.log("saved")) .catch(err => console.error(err)); try { workbook.toFileAsync("./out.xlsx", { password: "S3cret!" }); } catch (err) { /* browser only */ } ``` -------------------------------- ### Row.cell() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Row.md Examples of getting cells by column number and name. ```javascript const c5 = sheet.row(5).cell(3); // C5 const b5 = sheet.row(5).cell("B"); ``` -------------------------------- ### pageMargins() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Sheet.md Shows how to set, get, and reset page margins. Setting to null resets to preset. ```javascript sheet.pageMargins('top', 1.1); const top = sheet.pageMargins('top'); // 1.1 sheet.pageMargins('top', null); // back to preset ``` -------------------------------- ### Install gulp globally Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Install gulp globally via npm so the project's gulp tasks can be run from the command line. ```bash npm install -g gulp ``` -------------------------------- ### Get sheets by index, name, or all with xlsx-populate Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Shows how to retrieve a sheet by index or name, or get all sheets as an array. ```javascript // Get sheet by index const sheet1 = workbook.sheet(0); // Get sheet by name const sheet2 = workbook.sheet("Sheet2"); // Get all sheets as an array const sheets = workbook.sheets(); ``` -------------------------------- ### Row.address() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Row.md Example of calling address() on a row. ```javascript sheet.row(5).address(); // "5" ``` -------------------------------- ### Workbook.activeSheet() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Workbook.md Shows how to get the active sheet and set it by name. The getter returns a Sheet object, and the setter accepts a sheet name. ```javascript const active = workbook.activeSheet(); // Sheet workbook.activeSheet("Sheet2"); // activate by name ``` -------------------------------- ### Convenience API usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/PageBreaks.md Examples of using the convenience methods on cells, rows, and columns to add page breaks, and accessing the breaks via pageBreaks(). ```javascript workbook.sheet(0).cell("A5").addHorizontalPageBreak(); workbook.sheet(0).row(5).addPageBreak(); workbook.sheet(0).column("C").addPageBreak(); const breaks = workbook.sheet(0).pageBreaks(); breaks.rowBreaks.count; // 2 breaks.colBreaks.list; // [{ id: 3, isManual: true }] ``` -------------------------------- ### tabColor() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Sheet.md Demonstrates how to set and get the tab color using a string (RGB), a number (theme), and null to remove. The getter returns a color object. ```javascript sheet.tabColor("FF0000"); sheet.tabColor(3); const c = sheet.tabColor(); // { rgb: 'FF0000' } sheet.tabColor(null); ``` -------------------------------- ### Get and set active sheet with xlsx-populate Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Shows how to get the active sheet, check if a sheet is active, activate it, and set the active sheet from the workbook. ```javascript // Get the active sheet const sheet = workbook.activeSheet(); // Check if the current sheet is active sheet.active() // returns true or false // Activate the sheet sheet.active(true); // Or from the workbook workbook.activeSheet("Sheet2"); ``` -------------------------------- ### Using panes to get, set, and reset pane options Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Sheet.md Shows getting the current pane options, setting frozen panes with split positions, and resetting to no panes. The setter merges defaults and validates the options. ```javascript const opts = sheet.panes(); // { state: 'frozen', ... } sheet.panes({ state: 'frozen', topLeftCell: 'B2', xSplit: 1, ySplit: 1, activePane: 'bottomRight' }); sheet.panes(null); // reset ``` -------------------------------- ### tap() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Range.md Shows how to use tap to log the range address. ```javascript range.tap(r => console.log(r.address())); ``` -------------------------------- ### outputAsync() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Workbook.md Shows how to output the workbook as a nodebuffer/blob, as a base64 string, and with password encryption. ```javascript const data = await workbook.outputAsync(); // nodebuffer (Node) / blob (browser) const b64 = await workbook.outputAsync("base64"); // string form const enc = await workbook.outputAsync({ password: "pw" }); // encrypted ``` -------------------------------- ### Row.hidden() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Row.md Sets and gets the hidden state of a row. ```javascript sheet.row(3).hidden(true); const isHidden = sheet.row(3).hidden(); ``` -------------------------------- ### Row.height() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Row.md Sets, gets, and clears row height. ```javascript sheet.row(1).height(100); const h = sheet.row(1).height(); // 100 sheet.row(1).height(null); // clear ``` -------------------------------- ### style() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Range.md Shows various ways to set styles: single value, 2D array, callback, and object. ```javascript range.style("bold", true); range.style("bold", [[true, false], [false, true]]); range.style("bold", (cell, ri, ci, range) => Math.random() > 0.5); range.style({ bold: true, italic: [[true, false], [false, true]] }); ``` -------------------------------- ### Range.endCell() and startCell() methods and usage Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Range.md Returns the originally supplied end and start cells, not normalized to min/max. The example shows setting a value on the start cell. ```javascript endCell() { return this._endCell; } startCell() { return this._startCell; } ``` ```javascript range.startCell().value("start"); ``` -------------------------------- ### usedRange() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Sheet.md Gets the used range of a sheet and retrieves its values. ```javascript const values = workbook.sheet("Sheet1").usedRange().value(); ``` -------------------------------- ### Range.dataValidation([dataValidation]) method and usage Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Range.md Gets or sets data validation for the entire range. The setter accepts an object/string, and null/false clears. The example shows setting, getting, and clearing. ```javascript dataValidation() { return new ArgHandler('Range.dataValidation') .case(() => { return this.sheet().dataValidation(this.address()); }) .case('boolean', obj => { return this.sheet().dataValidation(this.address(), obj); }) .case('*', obj => { this.sheet().dataValidation(this.address(), obj); return this; }) .handle(arguments); } ``` ```javascript range.dataValidation('Item1,Item2,Item3'); const dv = range.dataValidation(); range.dataValidation(null); ``` -------------------------------- ### Build for the browser with gulp Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Build the code for the browser by running the gulp build command after adding tests and finishing development. ```bash gulp build ``` -------------------------------- ### sheet() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Workbook.md Shows how to retrieve the first sheet by index and a sheet by name. ```javascript workbook.sheet(0); // first sheet workbook.sheet("Sheet2"); // by name ``` -------------------------------- ### gridLinesVisible usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Sheet.md Sets grid lines invisible and then gets the current visibility. ```javascript sheet.gridLinesVisible(false); const vis = sheet.gridLinesVisible(); ``` -------------------------------- ### range.formula() Source: https://github.com/dtjohnson/xlsx-populate/blob/master/README.md Gets the shared formula in the start cell (assuming it's the source of the shared formula). ```APIDOC ## range.formula() ### Description Gets the shared formula in the start cell (assuming it's the source of the shared formula). ### Method range.formula() ### Returns - **string** | **undefined** - The shared formula. ``` -------------------------------- ### reduce() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Range.md Shows how to sum all cell values. ```javascript const total = range.reduce((sum, cell) => sum + Number(cell.value()), 0); ``` -------------------------------- ### outputAsync() method implementation Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Workbook.md Shows the internal implementation of outputAsync, which generates the zip with DEFLATE compression, optionally encrypts the output, and converts the buffer to the requested type. ```javascript outputAsync(opts) { opts = opts || {}; if (typeof opts === 'string') opts = { type: opts }; ... return this._zip.generateAsync({ type: "nodebuffer", compression: "DEFLATE" }) .then(output => { if (opts.password) output = encryptor.encrypt(output, opts.password); return this._convertBufferToOutput(output, opts.type); }); } ``` -------------------------------- ### Method chaining example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Demonstrates chaining setters on workbook, sheet, cell, and range objects to set values and styles in a single expression. ```javascript workbook .sheet(0) .cell("A1") .value("foo") .style("bold", true) .relativeCell(1, 0) .formula("A1") .style("italic", true) .workbook() .sheet(1) .range("A1:B3") .value(5) .cell(0, 0) .style("underline", "double"); ``` -------------------------------- ### RichTextFragment.value() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/RichTextFragment.md Shows how to get a fragment from a cell's rich text value, set its text, and read it back. ```javascript const fragment = cell.value().get(0); fragment.value('updated text'); const text = fragment.value(); ``` -------------------------------- ### formula() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Range.md Shows how to set a shared formula over a range and retrieve it. ```javascript range.formula("A1*2"); // shared formula over the whole range const f = range.formula(); ``` -------------------------------- ### style(...) implementation and usage Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Column.md Gets or sets whole-column styles. Setting a style also sets width to default (9.140625) if no custom width is set. The example sets bold and italic on column A, then gets the 'bold' style on column 3. ```javascript style() { return new ArgHandler("Column.style") .case('string', name => { this._createStyleIfNeeded(); return this._style.style(name); }) .case('array', names => { ... }) .case(['string', '*'], (name, value) => { this.sheet().forEachExistingRow(row => { if (row.hasStyle() || row.hasCell(this.columnNumber())) { row.cell(this.columnNumber()).style(name, value); } }); this._createStyleIfNeeded(); this._style.style(name, value); return this; }) .case('object', nameValues => { ... }) .case('Style', style => { ... }) .handle(arguments); } ``` ```javascript sheet.column("A").style({ bold: true, italic: true }); const bold = sheet.column(3).style("bold"); ``` -------------------------------- ### move() implementation and usage Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Sheet.md Shows the move method implementation and example calls. Moves the sheet to a new position. Returns Sheet for chaining. ```javascript move(indexOrBeforeSheet) { this.workbook().moveSheet(this, indexOrBeforeSheet); return this; } ``` ```javascript sheet.move(0); sheet.move("Sheet2"); ``` -------------------------------- ### Populate a blank workbook with xlsx-populate Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Loads a new blank workbook, sets a cell value, and writes to a file. Use this to create a workbook from scratch. ```javascript const XlsxPopulate = require('xlsx-populate'); // Load a new blank workbook XlsxPopulate.fromBlankAsync() .then(workbook => { // Modify the workbook. workbook.sheet("Sheet1").cell("A1").value("This is neat!"); // Write to file. return workbook.toFileAsync("./out.xlsx"); }); ``` -------------------------------- ### column() / columnName() / columnNumber() - column accessors Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Cell.md column() returns the parent Column, columnName() returns the column letter (e.g. 'B'), and columnNumber() returns the 1-based column number. The example shows setting column width and getting the column number. ```javascript column() { return this.sheet().column(this.columnNumber()); } columnName() { return addressConverter.columnNumberToName(this.columnNumber()); } columnNumber() { return this._columnNumber; } ``` ```javascript cell.column().width(20); const cn = cell.columnNumber(); // 1-based ``` -------------------------------- ### Workbook.addSheet() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Workbook.md Shows how to add a sheet at the end, at a specific index, or before an existing sheet by name. ```javascript const s = workbook.addSheet('New 1'); // at end const s2 = workbook.addSheet('New 2', 1); // at index 1 const s3 = workbook.addSheet('New 3', 'Sheet1'); // before Sheet1 ``` -------------------------------- ### Set and get row and column styles Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Set or get styles for entire rows or columns. Setting a style on a column applies to all existing and new cells. Getting returns only styles applied to the whole row/column. ```JavaScript // Set a single style sheet.row(1).style("bold", true); // Set multiple styles sheet.column("A").style({ bold: true, italic: true }); // Get a single style const bold = sheet.column(3).style("bold"); // Get multiple styles const styles = sheet.row(5).style(["bold", "italic"]); ``` -------------------------------- ### find() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Workbook.md Shows how to use the find method with a string for case-insensitive substring search and with a RegExp for advanced search and replacement. ```javascript workbook.find("foo", "bar"); // find+replace, returns matched cells workbook.find(/[a-z]+/g, match => match.toUpperCase()); ``` -------------------------------- ### Using Encryptor via password options Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Internals.md Demonstrates using the Encryptor indirectly through the public API. Loading a file with a password decrypts it, and outputting with a password encrypts it. The example shows chaining fromFileAsync and toFileAsync with password options. ```javascript // Reachable indirectly: loading with a password decrypts; outputting with a password encrypts. XlsxPopulate.fromFileAsync("in.xlsx", { password: "open sesame" }) .then(wb => wb.toFileAsync("out.xlsx", { password: "new password" })); ``` -------------------------------- ### PageBreaks.remove(index) usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/PageBreaks.md Example of removing a horizontal page break at index 0. ```javascript sheet.horizontalPageBreaks().remove(0); ``` -------------------------------- ### definedName() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Workbook.md Shows how to use the definedName method: dereference and set a value, create/update a name, and delete a name by passing null. ```javascript workbook.definedName("some name").value(5); // dereference + set workbook.definedName("some name", "TRUE"); // create/update workbook.definedName("some name", null); // delete ``` -------------------------------- ### style(...) Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/RichTextFragment.md Gets or sets style properties on the fragment. Supports multiple call forms: get a single style, get multiple styles, set a single style, or set multiple styles via an object. ```APIDOC ## style(...) ### Description Gets or sets style properties on the fragment. Supports multiple call forms: get a single style, get multiple styles, set a single style, or set multiple styles via an object. ### Call Forms - `style(name)` - Get a single style value. Returns `*`. - `style(names)` - Get multiple style values. Returns `object.`. - `style(name, value)` - Set a single style. Returns `RichTextFragment`. - `style({name: value, ...})` - Set multiple styles. Returns `RichTextFragment`. ### Parameters - **name** (string) - The style name. - **names** (Array.) - Array of style names. - **value** (*) - The style value. - **nameValues** (object) - Object mapping style names to values. ### Supported Style Names `bold`, `italic`, `underline`, `strikethrough`, `subscript`, `superscript`, `fontSize`, `fontFamily`, `fontGenericFamily`, `fontScheme`, `fontColor`. ### Throws - **Error** - If an unknown style name is provided. ### Example ```js const fragment = cell.value().add('bold text', { bold: true }); fragment.style('italic', true); const styles = fragment.style(['bold', 'italic']); fragment.style({ bold: false, fontColor: 'FF0000' }); ``` ``` -------------------------------- ### Using pageMarginsPreset with preset name and custom attributes Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Sheet.md Demonstrates setting a preset by name and registering a new preset with custom margins. The custom preset requires all six attribute keys with numeric values. ```javascript sheet.pageMarginsPreset('normal'); sheet.pageMarginsPreset('custom', { left: 1, right: 1, top: 1, bottom: 1, header: 0.5, footer: 0.5 }); ``` -------------------------------- ### PageBreaks.add(id) usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/PageBreaks.md Examples of adding horizontal and vertical page breaks using the add method. ```javascript sheet.horizontalPageBreaks().add(5); // break after row 5 sheet.verticalPageBreaks().add(3); // break after column C ``` -------------------------------- ### fromBlankAsync() Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/XlsxPopulate.md Creates a new blank Workbook asynchronously. Returns a Promise that resolves to a Workbook instance. ```APIDOC ## fromBlankAsync() ### Description Creates a new blank `Workbook` asynchronously. The workbook is built from an embedded blank template. ### Method Static method ### Endpoint `XlsxPopulate.fromBlankAsync()` ### Parameters None ### Returns - **Promise.** - Resolves to a new blank `Workbook`. ### Example ```js XlsxPopulate.fromBlankAsync() .then(workbook => { workbook.sheet("Sheet1").cell("A1").value("Hello"); return workbook.toFileAsync("./out.xlsx"); }) .catch(err => console.error(err)); ``` ``` -------------------------------- ### tap and thru usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Cell.md Demonstrates using tap to log a cell's address and thru to transform a cell's value. tap returns the cell, thru returns the callback's result. ```javascript cell.tap(c => console.log(c.address())); const label = cell.thru(c => c.value().toUpperCase()); ``` -------------------------------- ### map() usage example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Range.md Shows how to map cell values to their string lengths. ```javascript const lengths = range.map(cell => String(cell.value()).length); ``` -------------------------------- ### Using Cell.style Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Cell.md Shows how to set styles with chaining and via object, retrieve a style value, and set a 2D block of styles. ```javascript cell.style("bold", true).style({ italic: true }); const bold = cell.style("bold"); cell.style("bold", [[true, false], [false, true]]); // returns Range over that block ``` -------------------------------- ### row.style(name) / row.style(names) / row.style(name, value) / row.style(styles) / row.style(style) Source: https://github.com/dtjohnson/xlsx-populate/blob/master/README.md Gets or sets styles on the row. Can get an individual style by name, get multiple styles by array of names, set an individual style by name and value, or set multiple styles via an object. ```APIDOC ## row.style(name) / row.style(names) / row.style(name, value) / row.style(styles) / row.style(style) ### Description Gets or sets styles on the row. ### Method N/A (instance method) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (string) - The name of the style (for getter/setter). - **names** (Array.) - The names of the styles (for getter). - **value** (*) - The value to set (for setter). - **styles** (Object) - Object with style names as keys and values (for setter). - **style** (Object) - Object with style names as keys and values (for setter). ### Request Example None ### Response #### Success Response - Getter (single): Returns * - The style. - Getter (multiple): Returns object. - Object with style names and values. - Setter: Returns Cell - The cell. #### Response Example Getter: style value or object. Setter: Cell object. ``` -------------------------------- ### Range.value() usage examples Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Range.md Demonstrates the getter and setter call forms: retrieving all values from a used range, setting a single value, setting a 2D array, and setting values via a callback. ```javascript const values = sheet.usedRange().value(); range.value(5); range.value([[1, 2, 3], [4, 5, 6]]); range.value((cell, ri, ci) => Math.random()); ``` -------------------------------- ### activeCell([rowNumber, columnNameOrNumber] | [cell]) Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Sheet.md Gets or sets the active cell in the sheet. Can be called with no arguments to get the current active cell, or with coordinates or a cell reference to set it. ```APIDOC ## activeCell([rowNumber, columnNameOrNumber] | [cell]) ### Description Gets or sets the active cell in the sheet. Can be called with no arguments to get the current active cell, or with coordinates or a cell reference to set it. ### Method Getter/Setter ### Parameters - `rowNumber` (number) - Optional - The row number (1-based) when setting by coordinates. - `columnNameOrNumber` (string | number) - Optional - The column name (e.g., 'C') or 1-based number when setting by coordinates. - `cell` (string | Cell) - Optional - A cell address string (e.g., 'C5') or a Cell object when setting directly. ### Returns - Getter: `Cell` - the currently active cell (defaults to A1). - Setter: `Sheet` - the sheet instance for chaining. ### Example ```js sheet.activeCell("C5"); sheet.activeCell(5, 3); const active = sheet.activeCell(); // Cell C5 ``` ``` -------------------------------- ### Get and set cell styles Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Get or set single or multiple styles on a cell. Getters return full style objects, setters accept a style name, an object, or a value. ```JavaScript // Get a single style const bold = cell.style("bold"); // true // Get multiple styles const styles = cell.style(["bold", "italic"]); // { bold: true, italic: true } // Set a single style cell.style("bold", true); // Set multiple styles cell.style({ bold: true, italic: true }); ``` -------------------------------- ### Create RichText instance via namespace Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/RichText.md Shows how to import the RichText class from the xlsx-populate namespace and instantiate it. Use this when you need to create a rich-text value programmatically. ```javascript const XlsxPopulate = require('xlsx-populate'); const RichText = XlsxPopulate.RichText; const rt = new RichText(); ``` -------------------------------- ### Sheet.panes() Source: https://github.com/dtjohnson/xlsx-populate/blob/master/README.md Gets the pane options. ```APIDOC ## Sheet.panes() ### Description Gets the pane options. ### Method GET ### Endpoint Sheet.panes() ### Returns - **PaneOptions** - The pane options. ``` -------------------------------- ### Import XlsxPopulate Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/XlsxPopulate.md Shows how to import the XlsxPopulate module in Node.js or access the global in the browser. ```javascript const XlsxPopulate = require('xlsx-populate'); // or, in the browser, the global: XlsxPopulate ``` -------------------------------- ### Workbook static factory methods Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Workbook.md Workbooks are created only through these static factory methods. fromBlankAsync() creates a blank workbook, fromDataAsync() initializes from data, and fromFileAsync() loads from a file. ```javascript static fromBlankAsync() { return Workbook.fromDataAsync(blank); } // lib/Workbook.js:60 ``` ```javascript static fromDataAsync(data, opts) { return new Workbook()._initAsync(data, opts); } // :71 ``` ```javascript static fromFileAsync(path, opts) { ... } // :82 ``` -------------------------------- ### Sheet.name() Source: https://github.com/dtjohnson/xlsx-populate/blob/master/README.md Gets the name of the sheet. ```APIDOC ## Sheet.name() ### Description Gets the name of the sheet. ### Method GET ### Endpoint Sheet.name() ### Returns - **string** - The sheet name. ``` -------------------------------- ### workbook.outputAsync([opts]) Source: https://github.com/dtjohnson/xlsx-populate/blob/master/README.md Generates the workbook output with options. Returns a promise resolving to the data. ```APIDOC ## GET workbook.outputAsync([opts]) ### Description Generates the workbook output. ### Method GET ### Endpoint workbook.outputAsync([opts]) ### Parameters #### Path Parameters - **opts** (Object) - Optional - Options - **opts.type** (string) - Optional - The type of the data to return: base64, binarystring, uint8array, arraybuffer, blob, nodebuffer. Defaults to 'nodebuffer' in Node.js and 'blob' in browsers. - **opts.password** (string) - Optional - The password to use to encrypt the workbook. ### Response #### Success Response (200) - **returns** (Promise<(string|Uint8Array|ArrayBuffer|Blob|Buffer)>) - The data. #### Response Example ```json { "data": "..." } ``` ``` -------------------------------- ### row.rowNumber() Source: https://github.com/dtjohnson/xlsx-populate/blob/master/README.md Gets the row number. ```APIDOC ## row.rowNumber() ### Description Gets the row number. ### Method N/A (instance method) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - Returns number - The row number. #### Response Example number ``` -------------------------------- ### fromBlankAsync: Create New Blank Workbook Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/XlsxPopulate.md Creates a new blank Workbook from the embedded blank template in lib/blank.js. Returns a Promise that resolves to a Workbook. ```javascript static fromBlankAsync() { return Workbook.fromBlankAsync(); } ``` ```javascript XlsxPopulate.fromBlankAsync() .then(workbook => { workbook.sheet("Sheet1").cell("A1").value("Hello"); return workbook.toFileAsync("./out.xlsx"); }) .catch(err => console.error(err)); ``` -------------------------------- ### range.workbook() Source: https://github.com/dtjohnson/xlsx-populate/blob/master/README.md Gets the parent workbook. ```APIDOC ## range.workbook() ### Description Gets the parent workbook. ### Method N/A (instance method) ### Endpoint N/A ### Parameters None ### Returns - **Workbook** - The parent workbook. ### Example ```javascript const wb = range.workbook(); ``` ``` -------------------------------- ### Style id() Usage Example Source: https://github.com/dtjohnson/xlsx-populate/blob/master/_autodocs/api-reference/Style.md Demonstrates retrieving the style ID from a created style object. ```js const style = workbook.styleSheet().createStyle(0); const id = style.id(); ``` -------------------------------- ### column.workbook() Source: https://github.com/dtjohnson/xlsx-populate/blob/master/README.md Gets the parent workbook. ```APIDOC ## column.workbook() ### Description Get the parent workbook. ### Method N/A (instance method) ### Endpoint N/A ### Parameters None ### Returns - **Workbook** - The parent workbook. ### Example N/A ``` -------------------------------- ### Serve workbook from Express Source: https://github.com/dtjohnson/xlsx-populate/blob/master/docs/template.md Express route handler that opens an existing workbook, makes an edit, and sends the output as an attachment. Uses XlsxPopulate.fromFileAsync and workbook.outputAsync. ```JavaScript router.get("/download", function (req, res, next) { // Open the workbook. XlsxPopulate.fromFileAsync("input.xlsx") .then(workbook => { // Make edits. workbook.sheet(0).cell("A1").value("foo"); // Get the output return workbook.outputAsync(); }) .then(data => { // Set the output file name. res.attachment("output.xlsx"); // Send the workbook. res.send(data); }) .catch(next); }); ``` -------------------------------- ### column.width() Source: https://github.com/dtjohnson/xlsx-populate/blob/master/README.md Gets the width of the column. ```APIDOC ## column.width() ### Description Get the width of the column. ### Method N/A (instance method) ### Endpoint N/A ### Parameters None ### Returns - **undefined** | **number** - The width of the column. ### Example N/A ```