jmcnamara / libxlsxwriter

A C library for creating Excel XLSX files.
https://libxlsxwriter.github.io
Other
1.49k stars 332 forks source link

Feature request: Add support for quotePrefix #385

Closed stenvaag closed 1 year ago

stenvaag commented 1 year ago

Greetings,

I am using libxlsxwriter to create a spreadsheet equal to an old one I have.

The old spreadsheet uses the equal sign in the beginning of a string. To avoid evaluation when selecting this cell for editiing in Excel I need the quotePrefix attribute.

Here is some code that demonstrates the problem:

#include "xlsxwriter.h"
int main() {
    lxw_workbook  *workbook  = workbook_new("quoteprefix.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    worksheet_write_string(worksheet, 0, 0, "= Hello", NULL);
    return workbook_close(workbook);
}

Opening the quoteprefix.xlsx in Excel and start editing the cell and press just press Enter, the cell content changes to #NAME?.

After patch

#include "xlsxwriter.h"
int main() {
    lxw_workbook  *workbook  = workbook_new("quoteprefix.xlsx");
    lxw_format *quote = workbook_add_format(workbook);
    format_set_quote_prefix(quote);
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    worksheet_write_string(worksheet, 0, 0, "= Hello", quote);
    return workbook_close(workbook);
}

A patch is attached. libxlsxwriter-quote_prefix.txt

jmcnamara commented 1 year ago

Sure, I can look at that for the next release.

jmcnamara commented 1 year ago

Add on main.