jmcnamara / libxlsxwriter

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

We found a problem with some content #371

Closed willm132 closed 2 years ago

willm132 commented 2 years ago

Using Swift and Xcode

Once you open the document you get this error

Screen Shot 2022-05-03 at 1 26 20 PM Screen Shot 2022-05-03 at 1 26 26 PM Screen Shot 2022-05-03 at 1 26 48 PM
jmcnamara commented 2 years ago

Like you add a complete sample application that demonstrates the issue.

willm132 commented 2 years ago
 let workbook = workbook_new(formatURLForIOS)
 let worksheet1 = workbook_add_worksheet(workbook, "\(fileName)")
worksheet_center_horizontally(worksheet1)

let standardText = workbook_add_format(workbook)
format_set_font_name(standardText, SETTINGS.reportFont)

let boldTextCustShipLoc = workbook_add_format(workbook)
format_set_font_name(boldTextCustShipLoc, SETTINGS.reportFont)

format_set_text_wrap(standardText)
format_set_text_wrap(boldTextCustShipLoc)

worksheet_merge_range(worksheet1, lxw_row_t(currentRow), 0, lxw_row_t(currentRow), lxw_col_t(totalLength), 
"Generated On: \(SETTINGS.fullDateAndTime) ", boldTextCustShipLoc)
currentRow += 1

worksheet_fit_to_pages(worksheet1, 1, 0)
workbook_close(workbook)
jmcnamara commented 2 years ago

Thanks. Could you also attach the output xlsx file.

willm132 commented 2 years ago

Also, worksheet_repeat_rows(worksheet1, 5, 5) does nothing when you open with excel and try to print

jmcnamara commented 2 years ago

Sorry, I meant could you attach the xlsx file from the smaller sample program above.

jmcnamara commented 2 years ago

The reason for this Excel error is that there are overlapping merged ranges. Specifically "A97:C97" and "A97:I97".

Libxlsxwriter should warn/prevent overlapping ranges (and it is a planned feature https://github.com/jmcnamara/XlsxWriter/issues/848) but for now try to avoid overlapping merged ranges.

willm132 commented 2 years ago

And why does the worksheet_repeat_rows(worksheet1, 5, 5) do nothing when opening in excel?

jmcnamara commented 2 years ago

And why does the worksheet_repeat_rows(worksheet1, 5, 5) do nothing when opening in excel?

It should work. Here is a C example:

#include "xlsxwriter.h"

int main() {

    lxw_workbook  *workbook  = workbook_new("test_repeat.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, "Sheet 1");

    worksheet_repeat_rows(worksheet, 5, 5);

    worksheet_write_string(worksheet, CELL("A1"), "Foo" , NULL);

    return workbook_close(workbook);
}

Output:

Screenshot 2022-05-04 at 15 32 11

However, if you are using xlsxwriter.swift then it may not be supported/ported. I don't see it mentioned in the code.