[GH-ISSUE #443] Bug: workbook_add_worksheet does not return a reasonable worksheet #346

Closed
opened 2026-05-05 12:11:10 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @ym-xie on GitHub (May 8, 2024).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/443

Originally assigned to: @jmcnamara on GitHub.

There may be a semantic bug here. When name is NULL, but the same name has been written before, a worksheet with a new valid name should be returned.

#include "xlsxwriter.h"
int main() {
    lxw_workbook  *workbook  = workbook_new("demo.xlsx");
    const char* name[] = {"Sheet1", "Sheet2", "Sheet4", NULL};
    for (int i = 0; i < sizeof(name) / sizeof(*name); ++i) {
      if (name[i] == NULL || workbook_validate_sheet_name(workbook, name[i]) == LXW_NO_ERROR) {
        lxw_worksheet *worksheet = workbook_add_worksheet(workbook, name[i]);
        if (worksheet == NULL) {
          __builtin_trap();
        }
      }
    }
    return 0;
}
Originally created by @ym-xie on GitHub (May 8, 2024). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/443 Originally assigned to: @jmcnamara on GitHub. There may be a semantic bug here. When name is NULL, but the same name has been written before, a worksheet with a new valid name should be returned. ```c #include "xlsxwriter.h" int main() { lxw_workbook *workbook = workbook_new("demo.xlsx"); const char* name[] = {"Sheet1", "Sheet2", "Sheet4", NULL}; for (int i = 0; i < sizeof(name) / sizeof(*name); ++i) { if (name[i] == NULL || workbook_validate_sheet_name(workbook, name[i]) == LXW_NO_ERROR) { lxw_worksheet *worksheet = workbook_add_worksheet(workbook, name[i]); if (worksheet == NULL) { __builtin_trap(); } } } return 0; } ```
Author
Owner

@jmcnamara commented on GitHub (May 8, 2024):

For me this isn't a bug. The default sheet naming is intended to be simple and incremental. If the user has a scenario where they want to use one of the default names out of sequence then they should avoid using default naming or at least add some logic to avoid this issue.

Closing as won't fix.

<!-- gh-comment-id:2101031417 --> @jmcnamara commented on GitHub (May 8, 2024): For me this isn't a bug. The default sheet naming is intended to be simple and incremental. If the user has a scenario where they want to use one of the default names out of sequence then they should avoid using default naming or at least add some logic to avoid this issue. Closing as won't fix.
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#346
No description provided.