About This Article
This article is created using an automated generation workflow leveraging generative AI. Number formatting, XLSX output, and formula result handling were verified against the official ExcelJS 4.4.0 documentation, and material input validation and expected values were tested using Node.js. Live demo screen operations and recalculation after opening in Excel have not been verified.Verification Status: 🧪 Syntax and input logic verified / Browser and physical Excel device unverified
When creating a sales workbook with ExcelJS, cell contents and visual presentation are configured separately. For example, the numeric value 1200 can be displayed as 1,200 using the #,##0 display format, whereas the string "1200 yen" does not become a number. Since it is impossible to determine whether a value is included in a sum based on appearance alone, verify value types, display formats, and formula results separately.
- What We Will Test in This Article
- Quick Review: Supported Environments and Constraints
- Interact with the live demo
- Mechanism: Data types, display formats, and formulas are separate settings.
- Comparing under different conditions
- When the results are not as expected
- Verification before applying to production
- Materials and Verification
- Official Information and Primary Sources
What We Will Test in This Article
Using a small demo in the browser, we will generate an Excel file with modified sales columns for Product A. We will swap between the numeric value 1200 and the string "1200 yen" containing units to compare how the cell type and total display change.
This experiment uses fictional monetary amounts only. Please do not input company sales data, customer names, or personal information. Because the demo loads ExcelJS 4.4.0 from esm.sh, an internet connection is required at runtime. In the source code, input values are used exclusively to generate the workbook, and no processing sends data to external services. Network communication in the browser has not been verified.
Quick Review: Supported Environments and Constraints
| Item | Description |
|---|---|
| Target | ExcelJS 4.4.0 running in the browser |
| Requirements | A modern browser capable of executing JavaScript, and an internet connection to fetch ExcelJS |
| Input | Product A amount field. 1200 is a number, while "1200 yen" and "1,200" are treated as strings in this demo |
| Output | Download sales.xlsx |
| Capabilities | Generates a small XLSX workbook containing cells with number formatting and SUM formulas |
| Limitations and Unverified Features | Formula calculation using ExcelJS, recalculation when opened in Excel or Excel for the web, and button operations on Pages are unverified |
| Safety Precautions | Test with dummy data. Do not enter internal corporate data or confidential information |
ExcelJS is a JavaScript library for reading and writing XLSX files. It is neither the Excel application itself nor a substitute that calculates and displays all Excel features.
Interact with the live demo
Select "Open Live Demo" above.
Leave the initial value as 1200 and click "Run".
When the save link for sales.xlsx appears in the browser, download it for practice.
Change the input to 1200 yen and click "Run" again.
Compare the "Type" and "Total" on the screen. Also try 1,200.
Because the live page could not be opened in this environment, screen display, button operations, and file downloads are unverified. The following results indicate expected values derived from the demo code stored in GitHub and Node.js inspection.
| Input Field | Value inserted into the cell by the demo | Display example | Total result configured by the demo |
|---|---|---|---|
| 1200 | Numeric 1200 | 1,200 | 4,700 |
| 1200 JPY | String 1200 JPY | 1200 JPY | 3,500 |
| 1,200 | String 1,200 | 1,200 | 3,500 |
While 1200 JPY and 1,200 may also differ in their display, the root cause cannot be identified without checking the data type. In particular, 1,200 is a string that looks like a number. Since the demo conversion process does not remove commas or currency symbols, it is not treated as a numeric value.
Mechanism: Data types, display formats, and formulas are separate settings.
The tutorial process checks whether the input field value can be converted to a number using Number() and sets the number format to #,##0 in the second column of the worksheet. SUM(B2:B3) is inserted into the total row. Shortening the main part yields the following.
const amount = input.trim() && Number.isFinite(Number(input))
? Number(input)
: input;
sheet.getColumn(2).numFmt = '#,##0';
sheet.getCell('B4').value = {
formula: 'SUM(B2:B3)',
result: (typeof amount === 'number' ? amount : 0) + 3500
};
numFmt is the display format. This setting is used to make numbers appear like 1,200 and is not a feature for converting strings into numbers. When numeric and string types are confused, simply changing the display format may not fix the issue.
Furthermore, ExcelJS does not evaluate formulas to calculate answers. The result of a formula cell is a value prepared and saved by the creator. This demo sets result to 1200 + 3500 if the input is numeric, or 0 + 3500 if it is a string. The on-screen "Total" also displays that value. Whether formulas are recalculated when Excel is opened, or what values are displayed after recalculation, is not verified here.
Comparing under different conditions
Changing 1200 to 2500 keeps the input as a number, so the demo's total result becomes 6000. Changing it to 2500 JPY turns it into a string, and the total result set by the demo remains 3500. Even though the numeric part is identical, adding a unit to the input field changed the type determination.
Next, enter 1,200. While spreadsheet software may read this as a number in some cases, this tutorial saves it as a string because JavaScript's Number('1,200') does not evaluate to a finite number. Instead of relying on browser locale settings or input methods, explicitly define allowed decimal points, digit separators, and currency symbols during data ingestion in practical applications before performing conversion.
,##0 is a format that does not display decimal places. If amounts require decimals, choose a format that suits the purpose, such as #,##0.00. Rather than appending currency symbols directly to the value itself, keep it as a numeric value and verify the display format in the target Excel environment. Displayed digit separators and currency symbols are affected by regional settings.
The task of normalizing region-specific numeric strings in existing Excel cells is outside the scope of this article. For converting existing workbooks, refer tothe article on Excel's NUMBERVALUE functioncan be helpful. Here, when creating a new XLSX file from JavaScript, value types, display formats, and formula results are evaluated separately.
When the results are not as expected
The total is smaller than expected: Even if they look like numbers, the cells might be strings. Use =ISNUMBER(B2) or =ISTEXT(B2) in Excel to check the type of value.
The sum is not calculated even though only the display format was changed: Display formats do not change data types. Establish a separate rule for converting strings to numbers and log any rows that fail conversion.
1,200 becomes a string: This demo does not remove digit separators. You must define the allowed input formats and parse them safely. Unconditionally stripping commas risks incorrectly converting data with different decimal separator conventions.
Formula results are blank, outdated, or unexpected: Do not assume ExcelJS calculates formulas; check both the formula and the saved result. Recalculate in the target version of Excel and cross-check the totals using the input rows.
Cannot load the library in the demo: This sample loads ExcelJS from an external URL. Check for network restrictions or temporary retrieval failures. There is no need to use actual corporate data for verification.
Verification before applying to production
When automatically generating sales reports, first determine the meaning and type of each column. As a rule, monetary amounts should be stored as numbers, while non-calculated identifiers like product codes, postal codes, and phone numbers should be stored as strings. For example, converting 00125 to a number may cause leading zeros to be lost.
Before applying changes to production data, verify the following using a copy of the original file and mock data:
The data type with which input values are stored.
That changing the display format does not alter the underlying value.
The conditions under which strings and blank cells are excluded from totals.
Ensure that the formulas reference the intended ranges.
Verify that the formula results after opening in Excel match the totals calculated separately from the line items.
When multiple currencies are present, do not sum amounts alone. Maintain a separate currency code column and aggregate values of the same currency only. The two-product demonstration table is intended as instructional material to observe type differences and does not guarantee the validity of invoices or monthly closing processes.
Materials and Verification
The executed inspections consist of common JavaScript syntax checks and four logic test cases that classify inputs into numeric and string types. Actual XLSX generation by loading ExcelJS, opening the downloaded file in Excel, and browser button operations have not been performed.
