This closes #324, update worksheet name in chart cell reference formulas on sheet rename - #2380
Open
ChrisJr404 wants to merge 1 commit into
Open
This closes #324, update worksheet name in chart cell reference formulas on sheet rename#2380ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
… formulas on sheet rename
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
SetSheetNamerenames a worksheet but does not update the cell reference formulas that charts store inxl/charts/chart*.xml. Because those formulas keep pointing at the old worksheet name (for exampleSheet1!$B$2:$B$3), the reference becomes dangling once the sheet no longer exists, and Excel opens the workbook with an empty chart — the series data is lost.This change updates the worksheet name in every chart series reference (name, categories and values) when a sheet is renamed, so charts keep their data. References to other worksheets are left untouched, and the worksheet name is quoted when it contains a space or other non-alphabetical characters, matching how Excel writes the formula.
While wiring this up I also fixed
adjustRangeSheetName, which is used for renaming references in defined names. It escaped the source name before comparing, so a source worksheet whose name required quoting (e.g.My Data) never matched and was silently left unchanged. It now unescapes each reference token before comparing, so quoted source names are handled correctly for both defined names and charts. A smallunescapeSheetNamehelper (the inverse of the existingescapeSheetName) was added for this.Related Issue
Closes #324
Motivation and Context
Renaming a sheet that has a chart on it is a common operation, and today it silently corrupts the chart. On the issue, the maintainer noted that solving this requires checking and updating the references (such as
xl/charts/chart*.xml) when a sheet is renamed; this implements that for charts.How Has This Been Tested
TestSetSheetNameWithChart, which builds a chart with series that reference two worksheets, renames one of them to a name containing a space, and asserts that the renamed references are updated and correctly quoted, that references to the other worksheet are preserved, and that the result survives a save/reopen round trip.TestAdjustRangeSheetNameandTestUnescapeSheetNamecovering unquoted names, quoted (spaced) source and target names, escaped single quotes, and references to unrelated worksheets.go test ./,go vet ./andgofmtall pass; the new and changed functions are covered 100%.Types of changes