From 30c16b094553d4eaf70957bd9df8044e1496758e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Francisco=20Xavier?= Date: Thu, 19 Oct 2023 17:56:48 -0300 Subject: [PATCH] Enhanced excel4node library: Added support for additional Workbook options and multiple authors. - Added options for Workbook: - `title`: Title for the worksheet. - `subject`: Subject of the workbook. - `company`: Name of the company for use in features such as comments and file information. - `manager`: Name for use in features such as comments and file information. - `version`: Version number of the workbook, allowing text string representation (e.g., "1.0," "2.0," "Final Version," "Draft 2," etc.). - `revisionNumber`: Revision number of the workbook, accepting text string representations (e.g., "0," "1," "2," "A," "B," "Final Draft," "RC1," etc.). - `language`: BCP 47 language tag to represent the file language ('en-US', 'es-ES', 'pt-BR', etc.). - Introduced the ability to have multiple authors: - `author`: Name for use in features such as comments and file information. Use 'author' when there is a single author. You can also provide a semicolon-separated string to include multiple authors (e.g., 'Author 1; Author 2'). - `authors`: Names of authors, for use in features such as comments and file information. Use 'authors' when there are multiple authors. These enhancements improve the flexibility and functionality of the library, making it easier to customize and handle workbooks in Excel. --- README.md | 50 +++++++++++++++++++-------------- sample.js | 4 ++- source/lib/worksheet/builder.js | 16 ++++++++++- 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 84c7aea..39089fc 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ xl.PAPER_SIZE ## Workbook -An instance of the Workbook class contains all data and parameters for the Excel Workbook. +An instance of the Workbook class encapsulates all data and parameters for the Excel Workbook. #### Constructor @@ -125,31 +125,39 @@ Workbook constructor accepts an optional configuration object. var xl = require('excel4node'); var wb = new xl.Workbook({ jszip: { - compression: 'DEFLATE', + compression: 'DEFLATE', // Specifies the compression method for the ZIP file ('STORE', 'DEFLATE'). }, defaultFont: { - size: 12, - name: 'Calibri', - color: 'FFFFFFFF', + size: 12, // Default font size. + name: 'Calibri', // Default font name. + color: 'FFFFFFFF', // Default font color. }, - dateFormat: 'm/d/yy hh:mm:ss', + dateFormat: 'm/d/yy hh:mm:ss', // Default date format. workbookView: { - activeTab: 1, // Specifies an unsignedInt that contains the index to the active sheet in this book view. - autoFilterDateGrouping: true, // Specifies a boolean value that indicates whether to group dates when presenting the user with filtering options in the user interface. - firstSheet: 1, // Specifies the index to the first sheet in this book view. - minimized: false, // Specifies a boolean value that indicates whether the workbook window is minimized. - showHorizontalScroll: true, // Specifies a boolean value that indicates whether to display the horizontal scroll bar in the user interface. - showSheetTabs: true, // Specifies a boolean value that indicates whether to display the sheet tabs in the user interface. - showVerticalScroll: true, // Specifies a boolean value that indicates whether to display the vertical scroll bar. - tabRatio: 600, // Specifies ratio between the workbook tabs bar and the horizontal scroll bar. - visibility: 'visible', // Specifies visible state of the workbook window. ('hidden', 'veryHidden', 'visible') (§18.18.89) - windowHeight: 17620, // Specifies the height of the workbook window. The unit of measurement for this value is twips. - windowWidth: 28800, // Specifies the width of the workbook window. The unit of measurement for this value is twips.. - xWindow: 0, // Specifies the X coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips. - yWindow: 440, // Specifies the Y coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips. + activeTab: 1, // Index of the active sheet in this book view. + autoFilterDateGrouping: true, // Indicates whether to group dates when presenting filtering options to the user. + firstSheet: 1, // Index of the first sheet in this book view. + minimized: false, // Specifies whether the workbook window is minimized. + showHorizontalScroll: true, // Indicates whether to display the horizontal scroll bar in the user interface. + showSheetTabs: true, // Indicates whether to display the sheet tabs in the user interface. + showVerticalScroll: true, // Indicates whether to display the vertical scroll bar in the user interface. + tabRatio: 600, // Ratio between the workbook tabs bar and the horizontal scroll bar. + visibility: 'visible', // Visibility state of the workbook window ('hidden', 'veryHidden', 'visible'). (§18.18.89) + windowHeight: 17620, // Height of the workbook window (measured in twips). + windowWidth: 28800, // Width of the workbook window (measured in twips). + xWindow: 0, // X-coordinate for the upper-left corner of the workbook window (measured in twips). + yWindow: 440, // Y-coordinate for the upper-left corner of the workbook window (measured in twips). }, - logLevel: 0, // 0 - 5. 0 suppresses all logs, 1 shows errors only, 5 is for debugging - author: 'Microsoft Office User', // Name for use in features such as comments + logLevel: 0, // Log level (0-5). 0 suppresses all logs, 1 shows errors only, 5 is for debugging. + author: 'Microsoft Office User', // Name for use in features such as comments and file information. (Use 'author' when a single author) You can also provide a semicolon-separated string to include multiple authors (e.g., 'Author 1; Author 2'). + authors: ['Author 1', 'Author 2'], // Names of authors, for use in features such as comments and file information. (Use 'authors' when are multiple authors). + title: 'Worksheet Title', // Title for the worksheet. + subject: 'Invoice Information - 2023-10-19', // Subject of the workbook. + company: 'Company, Inc.', // Name of the company for use in features such as comments and file information. (§22.2.2.21) + manager: 'Worksheet Manager', // Name for use in features such as comments and file information. + version: '1.0.0', // Version number of the workbook, which can be a text string representing the document's version, such as "1.0," "2.0," "Final Version," "Draft 2," etc. + revisionNumber: '2', // Revision number of the workbook, which can be a text string representing the document's revision number, such as "0," "1," "2," "A," "B," "Final Draft," "RC1," etc. + language: 'en-US' // BCP 47 language tag to represent the file language ('en-US', 'es-ES', 'pt-BR', etc.). }); ``` diff --git a/sample.js b/sample.js index 51d6855..c78a0bf 100644 --- a/sample.js +++ b/sample.js @@ -18,7 +18,9 @@ function generateWorkbook() { xWindow: 240, yWindow: 480, }, - author: 'Workbook Author Name' + author: 'Workbook Author Name', + company: 'Company, Inc.', + version: '1.0.0' }); /***************************************** diff --git a/source/lib/worksheet/builder.js b/source/lib/worksheet/builder.js index b561800..ab662f7 100644 --- a/source/lib/worksheet/builder.js +++ b/source/lib/worksheet/builder.js @@ -615,7 +615,21 @@ let commentsXML = (ws) => { ); commentsXml.att('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'); - commentsXml.ele('authors').ele('author').text(ws.wb.author); + const authors = ws.wb.author || ws.wb.authors; + if (Array.isArray(authors) && authors.length) { + authors.forEach(author => { + commentsXml.ele('authors').ele('author').text(author); + }) + } else { + commentsXml.ele('authors').ele('author').text(authors); + } + commentsXml.ele('company', ws.wb.company); + commentsXml.ele('title', ws.wb.title); + commentsXml.ele('subject', ws.wb.subject); + commentsXml.ele('version', ws.wb.version); + commentsXml.ele('revisionNumber', ws.wb.revisionNumber); + commentsXml.ele('manager', ws.wb.manager); + commentsXml.ele('language', ws.wb.language); const commentList = commentsXml.ele('commentList'); Object.keys(ws.comments).forEach(ref => {