exceljs / exceljs/exceljs

[BUG] Single quote is being added automatically with a numeric value of type string.

Open
#2,338 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
15.5k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

## 🐛 Bug Report

We have found an issue with numeric string values. When we try to push a number as a string to the worksheet row, it adds an leading single quote and escapes the value as string. This is also happening with the Date fields.

Lib version: 4.3.0

## Steps To Reproduce

```javascript
const ExcelJS = require("exceljs");
const fs = require('fs')

const options = {
filename: 'demo.xlsx',
useStyles: false,
useSharedStrings: false,
};

const workbook = new ExcelJS.stream.xlsx.WorkbookWriter(options);
workbook.creator = "ABC";
let worksheet = workbook.addWorksheet();
const row = worksheet.getRow(1);

row.values = [1, 'John Doe', new Date(1970,1,1), '32.5', '32']
row.commit()
worksheet.getColumn(1).
worksheet.commit()
workbook.commit()
```
**Output:**
The values 32.5 and 32, both being a string is being escaped by a single quote and now being treated as a text instead of number. When we observe the first column, it is just integer and it doesn't have any escape character, also right aligned.

![image](https://github.com/exceljs/exceljs/assets/22557749/8f7f94eb-0802-473f-b222-77bbdeb38657)

## The expected behaviour:

The value should be added into the excel cell without any special consideration. We could have option to opt in for such behavior.

Could anyone please help with this issue, in terms to understand why this is being default behavior and ways to prevent such modifications?
Thank you.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.