mirror of
https://github.com/jmcnamara/libxlsxwriter.git
synced 2026-10-05 06:10:24 -06:00
[PR #518] [CLOSED] Add workbook_rename_worksheet() and workbook_remove_worksheet() #525
Labels
No labels
awaiting user feedback
bug
cmake
cmake
docs
feature request
in progress
long term
medium term
medium term
pull-request
question
question
ready to close
short term
under investigation
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github-starred/libxlsxwriter#525
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/jmcnamara/libxlsxwriter/pull/518
Author: @viest
Created: 6/14/2026
Status: ❌ Closed
Base:
main← Head:rename📝 Commits (1)
499aba4workbook: add worksheet rename and remove functions📊 Changes
6 files changed (+482 additions, -0 deletions)
View changed files
📝
include/xlsxwriter/common.h(+3 -0)📝
include/xlsxwriter/workbook.h(+48 -0)📝
src/utility.c(+1 -0)📝
src/workbook.c(+127 -0)➕
test/unit/workbook/test_workbook_remove_worksheet.c(+156 -0)➕
test/unit/workbook/test_workbook_rename_worksheet.c(+147 -0)📄 Description
Summary
Adds two public workbook functions, both looking the worksheet up by name (case insensitive, matching
workbook_get_worksheet_by_name()):workbook_rename_worksheet(workbook, old_name, new_name)workbook_remove_worksheet(workbook, name)Also adds a new
LXW_ERROR_SHEETNAME_NOT_FOUNDerror code for the lookup-miss case.Motivation
Downstream language bindings sometimes need to rename or drop a worksheet after it has been added. This came up for the PHP extension php-ext-xlswriter#306, where rename/delete of sheets is a frequently requested feature. These functions let bindings implement that without reaching into private structs.
Design notes
new_name, so a case-only rename such asSheet1->sheet1is not treated as a collision. It preserves the single sharedworksheet->name/ name-node allocation used byworkbook_add_worksheet().active_sheet/first_sheetpositions past the removed sheet (resetting them to 0 if the removed sheet was active/first, mirroringworksheet_hide()).Verification
test/unit/workbook/).-Wall -Wextra -Wstrict-prototypes -pedantic -ansi.workbook.xmlhas contiguoussheetId/r:id, the correct threesheetN.xmlparts, andactiveTabcorrectly tracking the shifted sheet.I'm happy to split this into a rename-only PR and a remove-only PR, add a Changes.txt entry, or add the chartsheet counterparts (
workbook_rename/remove_chartsheet, structurally identical) if that's preferred.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.