[GH-ISSUE #149] Writing formulas on xlsx files #123

Closed
opened 2026-05-05 11:43:11 -06:00 by gitea-mirror · 3 comments
Owner

Originally created by @HenriqueMisael on GitHub (Mar 8, 2018).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/149

Originally assigned to: @jmcnamara on GitHub.

In excel,
When you write it shows up in the cell
A2+A3 A2+A3
=A2+A3 the result of the sum
'=A2+A3 =A2+A3

Knowing that, I've tried to write "=A2+A3" using the write_string function, but it wrote just the formula, not showing up the result. Once I select the cell and press ENTER, however, the cell turned to the result of the formula I entered.

Looking deep in the xlsx file I've figured out that

  • in x1/worksheets/worksheet_name.xml the cells have the tag <c></c>, with the attributes "r" for identification (A3, B6, etc).
  • when I use write_string function, it writes on x1/sharedStrings.xml adding in the final of the list. The ordinal position of the string is wrote on x1/worksheets/worksheet_name.xml, in the tag <v></v> of the cell. For identify this is a reference for sharedStrings.xml and not the actually value of the cell, a attribute "t" of the cell it suppled with "s" (<c r=X9 t="s"></c>).
  • when I write a formula (in excel), the tag seems standart, except for adding another tag into the cell tag: <f></f>, and the string equivalent to the formula is writen in it.
    Example: if I wrote "=A2+A3" in the cell A1, the tag for it will be something like <c r=A1><f>A2+A3</f><v>698</v></c>, considering the result of the formula would be 698.

I have not found any method to write a formula using libxlsxwriter. It would be really useful (I thought I will found this pointed out in Issues, and not finding it suprised me).

Originally created by @HenriqueMisael on GitHub (Mar 8, 2018). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/149 Originally assigned to: @jmcnamara on GitHub. In excel, **When you write** _it shows up in the cell_ **A2+A3** _A2+A3_ **=A2+A3** _the result of the sum_ **'=A2+A3** _=A2+A3_ Knowing that, I've tried to write "=A2+A3" using the write_string function, but it wrote just the formula, not showing up the result. Once I select the cell and press **ENTER**, however, the cell turned to the result of the formula I entered. **Looking deep in the xlsx file I've figured out that** - in x1/worksheets/worksheet_name.xml the cells have the tag `<c></c>`, with the attributes "`r`" for identification (A3, B6, etc). - when I use write_string function, it writes on x1/sharedStrings.xml adding in the final of the list. The ordinal position of the string is wrote on x1/worksheets/worksheet_name.xml, in the tag `<v></v>` of the cell. For identify this is a reference for sharedStrings.xml and not the actually value of the cell, a attribute "t" of the cell it suppled with "s" (`<c r=X9 t="s"></c>`). - when I write a formula (in excel), the tag seems standart, except for adding another tag into the cell tag: `<f></f>`, and the string equivalent to the formula is writen in it. **Example:** if I wrote "=A2+A3" in the cell A1, the tag for it will be something like `<c r=A1><f>A2+A3</f><v>698</v></c>`, considering the result of the formula would be 698. I have not found any method to write a formula using libxlsxwriter. It would be really useful (I thought I will found this pointed out in Issues, and not finding it suprised me).
gitea-mirror 2026-05-05 11:43:11 -06:00
Author
Owner

@jmcnamara commented on GitHub (Mar 8, 2018):

I have not found any method to write a formula using libxlsxwriter.

What about the worksheet_write_formula() function?: https://libxlsxwriter.github.io/worksheet_8h.html#ae57117f04c82bef29805ec3eabc219bb

<!-- gh-comment-id:371477386 --> @jmcnamara commented on GitHub (Mar 8, 2018): > I have not found any method to write a formula using libxlsxwriter. What about the `worksheet_write_formula()` function?: https://libxlsxwriter.github.io/worksheet_8h.html#ae57117f04c82bef29805ec3eabc219bb
Author
Owner

@HenriqueMisael commented on GitHub (Mar 8, 2018):

I searched in the examples, sorry for the bad reporting

<!-- gh-comment-id:371477885 --> @HenriqueMisael commented on GitHub (Mar 8, 2018): I searched in the examples, sorry for the bad reporting
Author
Owner

@jmcnamara commented on GitHub (Mar 8, 2018):

No problem. Closing.

<!-- gh-comment-id:371478053 --> @jmcnamara commented on GitHub (Mar 8, 2018): No problem. Closing.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#123
No description provided.