Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function processing in XLSX #692

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/excellentexport.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ <h3>Test page</h3>
new line</td>
<td>ç ñ ÄËÏÖÜ äëïöü</td>
</tr>
<tr>
<td>=HYPERLINK("https://google.com","Link")</td>
<td>=SUM(12,24)</td>
<td>EMPTY</td>
<td>=A1</td>
</tr>
</table>

<br/>
Expand Down
12 changes: 11 additions & 1 deletion src/excellentexport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,17 @@ const ExcellentExport = function() {
// Create sheet
workbook.SheetNames.push(name);
const worksheet = XLSX.utils.aoa_to_sheet(dataArray, {sheet: name} as XLSX.AOA2SheetOpts);

for (var cellName in worksheet) {
if (utils.hasContent(worksheet[cellName])) {
var cell = worksheet[cellName];
if (utils.hasContent(cell.v)) {
if(cell.v[0] == '=') {
cell.f = cell.v.toString().substring(1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the "=" is removed, it will not get into the final Excel file. Then opening will not get it as a formula.
Did this work for you?

Copy link
Author

@ilavloki ilavloki May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it works but only for XLSX format
Probably for XLS few modifications are needed
I've tried to launch index.html in Chrome and Edge
XLSX example:
image
in XLS format - it really doesn't work (and cells remain empty)
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it is not supported to write formula in XLS format at all :(
https://docs.sheetjs.com/docs/csf/features/formulae/

delete cell.v
}
}
}
}
// Apply format
if (sheetConf.formats) {
sheetConf.formats.forEach(f => {
Expand Down