@nguyenphp/antigravity-marketing 1.0.18 → 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/README.md +186 -78
  2. package/package.json +4 -3
  3. package/templates/.agent/skills/marketing-report-expert/SKILL.md +70 -0
  4. package/templates/.agent/skills/minimax-docx/LICENSE +21 -0
  5. package/templates/.agent/skills/minimax-docx/SKILL.md +274 -0
  6. package/templates/.agent/skills/minimax-docx/assets/styles/academic_styles.xml +250 -0
  7. package/templates/.agent/skills/minimax-docx/assets/styles/corporate_styles.xml +284 -0
  8. package/templates/.agent/skills/minimax-docx/assets/styles/default_styles.xml +449 -0
  9. package/templates/.agent/skills/minimax-docx/assets/xsd/aesthetic-rules.xsd +470 -0
  10. package/templates/.agent/skills/minimax-docx/assets/xsd/business-rules.xsd +130 -0
  11. package/templates/.agent/skills/minimax-docx/assets/xsd/common-types.xsd +159 -0
  12. package/templates/.agent/skills/minimax-docx/assets/xsd/wml-subset.xsd +589 -0
  13. package/templates/.agent/skills/minimax-docx/references/cjk_typography.md +357 -0
  14. package/templates/.agent/skills/minimax-docx/references/cjk_university_template_guide.md +184 -0
  15. package/templates/.agent/skills/minimax-docx/references/comments_guide.md +191 -0
  16. package/templates/.agent/skills/minimax-docx/references/design_good_bad_examples.md +829 -0
  17. package/templates/.agent/skills/minimax-docx/references/design_principles.md +819 -0
  18. package/templates/.agent/skills/minimax-docx/references/openxml_element_order.md +308 -0
  19. package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part1.md +4061 -0
  20. package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part2.md +2820 -0
  21. package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part3.md +3381 -0
  22. package/templates/.agent/skills/minimax-docx/references/openxml_namespaces.md +82 -0
  23. package/templates/.agent/skills/minimax-docx/references/openxml_units.md +72 -0
  24. package/templates/.agent/skills/minimax-docx/references/scenario_a_create.md +284 -0
  25. package/templates/.agent/skills/minimax-docx/references/scenario_b_edit_content.md +295 -0
  26. package/templates/.agent/skills/minimax-docx/references/scenario_c_apply_template.md +456 -0
  27. package/templates/.agent/skills/minimax-docx/references/track_changes_guide.md +200 -0
  28. package/templates/.agent/skills/minimax-docx/references/troubleshooting.md +506 -0
  29. package/templates/.agent/skills/minimax-docx/references/typography_guide.md +294 -0
  30. package/templates/.agent/skills/minimax-docx/references/xsd_validation_guide.md +158 -0
  31. package/templates/.agent/skills/minimax-docx/scripts/doc_to_docx.sh +40 -0
  32. package/templates/.agent/skills/minimax-docx/scripts/docx_preview.sh +37 -0
  33. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Cli/MiniMaxAIDocx.Cli.csproj +19 -0
  34. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Cli/Program.cs +18 -0
  35. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/AnalyzeCommand.cs +147 -0
  36. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/ApplyTemplateCommand.cs +322 -0
  37. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/CreateCommand.cs +324 -0
  38. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/DiffCommand.cs +155 -0
  39. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/EditContentCommand.cs +487 -0
  40. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/FixOrderCommand.cs +108 -0
  41. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/MergeRunsCommand.cs +122 -0
  42. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/ValidateCommand.cs +107 -0
  43. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/MiniMaxAIDocx.Core.csproj +15 -0
  44. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/CommentSynchronizer.cs +169 -0
  45. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/ElementOrder.cs +80 -0
  46. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/NamespaceConstants.cs +42 -0
  47. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/RunMerger.cs +81 -0
  48. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/StyleAnalyzer.cs +81 -0
  49. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/TrackChangesHelper.cs +99 -0
  50. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/UnitConverter.cs +23 -0
  51. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples.cs +1832 -0
  52. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch1.cs +910 -0
  53. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch2.cs +999 -0
  54. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch3.cs +1048 -0
  55. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch4.cs +1038 -0
  56. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/CharacterFormattingSamples.cs +1020 -0
  57. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/DocumentCreationSamples.cs +1121 -0
  58. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/FieldAndTocSamples.cs +624 -0
  59. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/FootnoteAndCommentSamples.cs +675 -0
  60. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/HeaderFooterSamples.cs +838 -0
  61. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ImageSamples.cs +917 -0
  62. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ListAndNumberingSamples.cs +826 -0
  63. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ParagraphFormattingSamples.cs +1199 -0
  64. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/StyleSystemSamples.cs +1487 -0
  65. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/TableSamples.cs +1163 -0
  66. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/TrackChangesSamples.cs +595 -0
  67. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/CjkHelper.cs +39 -0
  68. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/FontDefaults.cs +24 -0
  69. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/PageSizes.cs +20 -0
  70. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/BusinessRuleValidator.cs +224 -0
  71. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/GateCheckValidator.cs +148 -0
  72. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/ValidationResult.cs +23 -0
  73. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/XsdValidator.cs +69 -0
  74. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.slnx +4 -0
  75. package/templates/.agent/skills/minimax-docx/scripts/env_check.sh +196 -0
  76. package/templates/.agent/skills/minimax-docx/scripts/setup.ps1 +274 -0
  77. package/templates/.agent/skills/minimax-docx/scripts/setup.sh +504 -0
  78. package/templates/.agent/skills/minimax-multimodal-toolkit/SKILL.md +359 -0
  79. package/templates/.agent/skills/minimax-pdf/README.md +222 -0
  80. package/templates/.agent/skills/minimax-pdf/SKILL.md +201 -0
  81. package/templates/.agent/skills/minimax-pdf/design/design.md +381 -0
  82. package/templates/.agent/skills/minimax-pdf/scripts/cover.py +1579 -0
  83. package/templates/.agent/skills/minimax-pdf/scripts/fill_inspect.py +200 -0
  84. package/templates/.agent/skills/minimax-pdf/scripts/fill_write.py +242 -0
  85. package/templates/.agent/skills/minimax-pdf/scripts/make.sh +491 -0
  86. package/templates/.agent/skills/minimax-pdf/scripts/merge.py +112 -0
  87. package/templates/.agent/skills/minimax-pdf/scripts/palette.py +559 -0
  88. package/templates/.agent/skills/minimax-pdf/scripts/reformat_parse.py +374 -0
  89. package/templates/.agent/skills/minimax-pdf/scripts/render_body.py +1055 -0
  90. package/templates/.agent/skills/minimax-pdf/scripts/render_cover.cjs +111 -0
  91. package/templates/.agent/skills/minimax-xlsx/SKILL.md +138 -0
  92. package/templates/.agent/skills/minimax-xlsx/references/create.md +691 -0
  93. package/templates/.agent/skills/minimax-xlsx/references/edit.md +684 -0
  94. package/templates/.agent/skills/minimax-xlsx/references/fix.md +37 -0
  95. package/templates/.agent/skills/minimax-xlsx/references/format.md +768 -0
  96. package/templates/.agent/skills/minimax-xlsx/references/ooxml-cheatsheet.md +231 -0
  97. package/templates/.agent/skills/minimax-xlsx/references/read-analyze.md +97 -0
  98. package/templates/.agent/skills/minimax-xlsx/references/validate.md +772 -0
  99. package/templates/.agent/skills/minimax-xlsx/scripts/formula_check.py +422 -0
  100. package/templates/.agent/skills/minimax-xlsx/scripts/libreoffice_recalc.py +248 -0
  101. package/templates/.agent/skills/minimax-xlsx/scripts/shared_strings_builder.py +163 -0
  102. package/templates/.agent/skills/minimax-xlsx/scripts/style_audit.py +575 -0
  103. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_add_column.py +395 -0
  104. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_insert_row.py +274 -0
  105. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_pack.py +87 -0
  106. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_reader.py +362 -0
  107. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_shift_rows.py +396 -0
  108. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_unpack.py +130 -0
  109. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/[Content_Types].xml +9 -0
  110. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/_rels/.rels +6 -0
  111. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/_rels/workbook.xml.rels +19 -0
  112. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/sharedStrings.xml +33 -0
  113. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/styles.xml +160 -0
  114. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/workbook.xml +30 -0
  115. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/worksheets/sheet1.xml +70 -0
  116. package/templates/.agent/skills/pptx-generator/SKILL.md +249 -0
  117. package/templates/.agent/skills/pptx-generator/references/design-system.md +392 -0
  118. package/templates/.agent/skills/pptx-generator/references/editing.md +162 -0
  119. package/templates/.agent/skills/pptx-generator/references/pitfalls.md +112 -0
  120. package/templates/.agent/skills/pptx-generator/references/pptxgenjs.md +420 -0
  121. package/templates/.agent/skills/pptx-generator/references/slide-types.md +413 -0
  122. package/templates/.agent/skills/tutorial-video-expert/SKILL.md +88 -0
  123. package/templates/.agent/skills/ui-ux-pro-max/SKILL.md +170 -585
  124. package/templates/.agent/skills/vision-analysis/SKILL.md +174 -0
  125. package/templates/.agent/workflows/analyze.md +3 -0
  126. package/templates/.agent/workflows/brand-report.md +44 -0
  127. package/templates/.agent/workflows/report.md +49 -0
@@ -0,0 +1,684 @@
1
+ # Minimal-Invasive Editing of Existing xlsx
2
+
3
+ Make precise, surgical changes to existing xlsx files while preserving everything you do not touch: styles, macros, pivot tables, charts, sparklines, named ranges, data validation, conditional formatting, and all other embedded content.
4
+
5
+ ---
6
+
7
+ ## 1. When to Use This Path
8
+
9
+ Use the edit (unpack → XML edit → pack) path whenever the task involves **modifying an existing xlsx file**:
10
+
11
+ - Template filling — populating designated input cells with values or formulas
12
+ - Data updates — replacing outdated numbers, text, or dates in a live file
13
+ - Content corrections — fixing wrong values, broken formulas, or mistyped labels
14
+ - Adding new data rows to an existing table
15
+ - Renaming a sheet
16
+ - Applying a new style to specific cells
17
+
18
+ Do NOT use this path for creating a brand-new workbook from scratch. For that, see `create.md`.
19
+
20
+ ---
21
+
22
+ ## 2. Why openpyxl round-trip Is Forbidden for Existing Files
23
+
24
+ openpyxl `load_workbook()` followed by `workbook.save()` is a **destructive operation** on any file that contains advanced features. The library silently drops content it does not understand:
25
+
26
+ | Feature | openpyxl behavior | Consequence |
27
+ |---------|-------------------|-------------|
28
+ | VBA macros (`vbaProject.bin`) | Dropped entirely | All automation is lost; file saved as `.xlsx` not `.xlsm` |
29
+ | Pivot tables (`xl/pivotTables/`) | Dropped | Interactive analysis is destroyed |
30
+ | Slicers | Dropped | Filter UI is lost |
31
+ | Sparklines (`<sparklineGroups>`) | Dropped | In-cell mini-charts disappear |
32
+ | Chart formatting details | Partially lost | Series colors, custom axes may revert |
33
+ | Print area / page breaks | Sometimes lost | Print layout changes |
34
+ | Custom XML parts | Dropped | Third-party data bindings broken |
35
+ | Theme-linked colors | May be de-themed | Colors converted to absolute, breaking theme switching |
36
+
37
+ Even on a "plain" file without these features, openpyxl may normalize whitespace in XML that Excel relies on, alter namespace declarations, or reset `calcMode` flags.
38
+
39
+ **The rule is absolute: never open an existing file with openpyxl for the purpose of re-saving it.**
40
+
41
+ The XML direct-edit approach is safe because it operates on the raw bytes. You only change the nodes you touch. Everything else is byte-equivalent to the original.
42
+
43
+ ---
44
+
45
+ ## 3. Standard Operating Procedure
46
+
47
+ ### Step 1 — Unpack
48
+
49
+ ```bash
50
+ python3 SKILL_DIR/scripts/xlsx_unpack.py input.xlsx /tmp/xlsx_work/
51
+ ```
52
+
53
+ The script unzips the xlsx, pretty-prints every XML and `.rels` file, and prints a categorized inventory of key files plus a warning if high-risk content is detected (VBA, pivot tables, charts).
54
+
55
+ Read the printed output carefully before proceeding. If the script reports `xl/vbaProject.bin` or `xl/pivotTables/`, follow the constraints in Section 7.
56
+
57
+ ### Step 2 — Reconnaissance
58
+
59
+ Map the structure before touching anything.
60
+
61
+ **Identify sheet names and their XML files:**
62
+
63
+ ```
64
+ xl/workbook.xml → <sheet name="Revenue" sheetId="1" r:id="rId1"/>
65
+ xl/_rels/workbook.xml.rels → <Relationship Id="rId1" Target="worksheets/sheet1.xml"/>
66
+ ```
67
+
68
+ The sheet named "Revenue" lives in `xl/worksheets/sheet1.xml`. Always resolve this mapping before editing a worksheet.
69
+
70
+ **Understand the shared strings table:**
71
+
72
+ ```bash
73
+ # Count existing entries in xl/sharedStrings.xml
74
+ grep -c "<si>" /tmp/xlsx_work/xl/sharedStrings.xml
75
+ ```
76
+
77
+ Every text cell uses a zero-based index into this table. Know the current count before appending.
78
+
79
+ **Understand the styles table:**
80
+
81
+ ```bash
82
+ # Count existing cellXfs entries
83
+ grep -c "<xf " /tmp/xlsx_work/xl/styles.xml
84
+ ```
85
+
86
+ New style slots are appended after existing ones. The index of the first new slot = current count.
87
+
88
+ **Scan for high-risk XML regions in the target worksheet:**
89
+
90
+ Look for these elements in the target `sheet*.xml` before editing:
91
+
92
+ - `<mergeCell>` — merged cell ranges; row/column insertion shifts these
93
+ - `<conditionalFormatting>` — condition ranges; row/column insertion shifts these
94
+ - `<dataValidations>` — validation ranges; row/column insertion shifts these
95
+ - `<tableParts>` — table definitions; row insertion inside a table needs `<tableColumn>` updates
96
+ - `<sparklineGroups>` — sparklines; preserve without modification
97
+
98
+ ### Step 3 — Map Intent to Minimal XML Changes
99
+
100
+ Before writing a single character, produce a written list of exactly which XML nodes change. This prevents scope creep.
101
+
102
+ | User intent | Files to change | Nodes to change |
103
+ |-------------|----------------|-----------------|
104
+ | Change a cell's numeric value | `xl/worksheets/sheetN.xml` | `<v>` inside target `<c>` |
105
+ | Change a cell's text | `xl/sharedStrings.xml` (append) + `xl/worksheets/sheetN.xml` | New `<si>`, update cell `<v>` index |
106
+ | Change a cell's formula | `xl/worksheets/sheetN.xml` | `<f>` text inside target `<c>` |
107
+ | Add a new data row at the bottom | `xl/worksheets/sheetN.xml` + possibly `xl/sharedStrings.xml` | Append `<row>` element |
108
+ | Apply a new style to cells | `xl/styles.xml` + `xl/worksheets/sheetN.xml` | Append `<xf>` in `<cellXfs>`, update `s` attribute on `<c>` |
109
+ | Rename a sheet | `xl/workbook.xml` | `name` attribute on `<sheet>` element |
110
+ | Rename a sheet (with cross-sheet formulas) | `xl/workbook.xml` + all `xl/worksheets/*.xml` | `name` attribute + `<f>` text referencing old name |
111
+
112
+ ### Step 4 — Execute Changes
113
+
114
+ Use the Edit tool. Edit the minimum. Never rewrite whole files.
115
+
116
+ See Section 4 for precise XML patterns for each operation type.
117
+
118
+ ### Step 5 — Cascade Check
119
+
120
+ After any change that shifts row or column positions, audit all affected XML regions. See Section 5.
121
+
122
+ ### Step 6 — Pack and Validate
123
+
124
+ ```bash
125
+ python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
126
+ python3 SKILL_DIR/scripts/formula_check.py output.xlsx
127
+ ```
128
+
129
+ The pack script validates XML well-formedness before creating the ZIP. Fix any reported parse errors before packing. After packing, run `formula_check.py` to confirm no formula errors were introduced.
130
+
131
+ ---
132
+
133
+ ## 4. Precise XML Patterns for Common Edits
134
+
135
+ ### 4.1 Changing a Numeric Cell Value
136
+
137
+ Find the `<c r="B5">` element in the worksheet XML and replace the `<v>` text.
138
+
139
+ **Before:**
140
+ ```xml
141
+ <c r="B5">
142
+ <v>1000</v>
143
+ </c>
144
+ ```
145
+
146
+ **After (new value 1500):**
147
+ ```xml
148
+ <c r="B5">
149
+ <v>1500</v>
150
+ </c>
151
+ ```
152
+
153
+ Rules:
154
+ - Do not add or remove the `s` attribute (style) unless explicitly changing the style.
155
+ - Do not add a `t` attribute — numbers omit `t` or use `t="n"`.
156
+ - Do not change the `r` attribute (cell reference).
157
+
158
+ ---
159
+
160
+ ### 4.2 Changing a Text Cell Value
161
+
162
+ Text cells reference the shared strings table by index (`t="s"`). You cannot edit the string in-place without affecting every other cell that uses the same index. The safe approach is to append a new entry.
163
+
164
+ **Before — shared strings file (`xl/sharedStrings.xml`):**
165
+ ```xml
166
+ <sst count="4" uniqueCount="4">
167
+ <si><t>Revenue</t></si>
168
+ <si><t>Cost</t></si>
169
+ <si><t>Margin</t></si>
170
+ <si><t>Old Label</t></si>
171
+ </sst>
172
+ ```
173
+
174
+ **After — append new string, increment counts:**
175
+ ```xml
176
+ <sst count="5" uniqueCount="5">
177
+ <si><t>Revenue</t></si>
178
+ <si><t>Cost</t></si>
179
+ <si><t>Margin</t></si>
180
+ <si><t>Old Label</t></si>
181
+ <si><t>New Label</t></si>
182
+ </sst>
183
+ ```
184
+
185
+ New string is at index 4 (zero-based).
186
+
187
+ **Before — cell in worksheet XML:**
188
+ ```xml
189
+ <c r="A7" t="s">
190
+ <v>3</v>
191
+ </c>
192
+ ```
193
+
194
+ **After — point to new index:**
195
+ ```xml
196
+ <c r="A7" t="s">
197
+ <v>4</v>
198
+ </c>
199
+ ```
200
+
201
+ Rules:
202
+ - Never modify or delete existing `<si>` entries. Only append.
203
+ - Both `count` and `uniqueCount` must be incremented together.
204
+ - If the new string contains `&`, `<`, or `>`, escape them: `&amp;`, `&lt;`, `&gt;`.
205
+ - If the string has leading or trailing spaces, add `xml:space="preserve"` to `<t>`:
206
+ ```xml
207
+ <si><t xml:space="preserve"> indented text </t></si>
208
+ ```
209
+
210
+ ---
211
+
212
+ ### 4.3 Changing a Formula
213
+
214
+ Formulas are stored in `<f>` elements **without a leading `=`** (unlike what you type in Excel's UI).
215
+
216
+ **Before:**
217
+ ```xml
218
+ <c r="C10">
219
+ <f>SUM(C2:C9)</f>
220
+ <v>4800</v>
221
+ </c>
222
+ ```
223
+
224
+ **After (extended range):**
225
+ ```xml
226
+ <c r="C10">
227
+ <f>SUM(C2:C11)</f>
228
+ <v></v>
229
+ </c>
230
+ ```
231
+
232
+ Rules:
233
+ - Clear `<v>` to an empty string when changing the formula. The cached value is now stale.
234
+ - Do not add `t="s"` or any type attribute to formula cells. The `t` attribute is absent or uses a result-type value, not a formula marker.
235
+ - Cross-sheet references use `SheetName!CellRef`. If the sheet name contains spaces, wrap in single quotes: `'Q1 Data'!B5`.
236
+ - The `<f>` text must not include the leading `=`.
237
+
238
+ **Before (converting a hardcoded value to a live formula):**
239
+ ```xml
240
+ <c r="D15">
241
+ <v>95000</v>
242
+ </c>
243
+ ```
244
+
245
+ **After:**
246
+ ```xml
247
+ <c r="D15">
248
+ <f>SUM(D2:D14)</f>
249
+ <v></v>
250
+ </c>
251
+ ```
252
+
253
+ ---
254
+
255
+ ### 4.4 Adding a New Data Row
256
+
257
+ Append after the last `<row>` element inside `<sheetData>`. Row numbers in OOXML are 1-based and must be sequential.
258
+
259
+ **Before (last row is row 10):**
260
+ ```xml
261
+ <row r="10">
262
+ <c r="A10" t="s"><v>3</v></c>
263
+ <c r="B10"><v>2023</v></c>
264
+ <c r="C10"><v>88000</v></c>
265
+ <c r="D10"><f>C10*1.1</f><v></v></c>
266
+ </row>
267
+ </sheetData>
268
+ ```
269
+
270
+ **After (new row 11 appended):**
271
+ ```xml
272
+ <row r="10">
273
+ <c r="A10" t="s"><v>3</v></c>
274
+ <c r="B10"><v>2023</v></c>
275
+ <c r="C10"><v>88000</v></c>
276
+ <c r="D10"><f>C10*1.1</f><v></v></c>
277
+ </row>
278
+ <row r="11">
279
+ <c r="A11" t="s"><v>4</v></c>
280
+ <c r="B11"><v>2024</v></c>
281
+ <c r="C11"><v>96000</v></c>
282
+ <c r="D11"><f>C11*1.1</f><v></v></c>
283
+ </row>
284
+ </sheetData>
285
+ ```
286
+
287
+ Rules:
288
+ - Every `<c>` inside the row must have `r` set to the correct cell address (e.g., `A11`).
289
+ - Text cells need `t="s"` and a sharedStrings index in `<v>`. Numeric cells omit `t`.
290
+ - Formula cells use `<f>` and an empty `<v>`.
291
+ - Copy the `s` attribute from the row above if you want matching styles. Do not invent a style index that does not exist in `styles.xml`.
292
+ - If the sheet contains a `<dimension>` element (e.g., `<dimension ref="A1:D10"/>`), update it to include the new row: `<dimension ref="A1:D11"/>`.
293
+ - If the sheet contains a `<tableparts>` referencing a table, update the table's `ref` attribute in the corresponding `xl/tables/tableN.xml` file.
294
+
295
+ ---
296
+
297
+ ### 4.5 Adding a New Column
298
+
299
+ Append new `<c>` elements to each existing `<row>` and, if present, update the `<cols>` section.
300
+
301
+ **Before (rows have columns A–C):**
302
+ ```xml
303
+ <cols>
304
+ <col min="1" max="3" width="14" customWidth="1"/>
305
+ </cols>
306
+ <sheetData>
307
+ <row r="1">
308
+ <c r="A1" t="s"><v>0</v></c>
309
+ <c r="B1" t="s"><v>1</v></c>
310
+ <c r="C1" t="s"><v>2</v></c>
311
+ </row>
312
+ <row r="2">
313
+ <c r="A2"><v>100</v></c>
314
+ <c r="B2"><v>200</v></c>
315
+ <c r="C2"><v>300</v></c>
316
+ </row>
317
+ </sheetData>
318
+ ```
319
+
320
+ **After (adding column D):**
321
+ ```xml
322
+ <cols>
323
+ <col min="1" max="3" width="14" customWidth="1"/>
324
+ <col min="4" max="4" width="14" customWidth="1"/>
325
+ </cols>
326
+ <sheetData>
327
+ <row r="1">
328
+ <c r="A1" t="s"><v>0</v></c>
329
+ <c r="B1" t="s"><v>1</v></c>
330
+ <c r="C1" t="s"><v>2</v></c>
331
+ <c r="D1" t="s"><v>5</v></c>
332
+ </row>
333
+ <row r="2">
334
+ <c r="A2"><v>100</v></c>
335
+ <c r="B2"><v>200</v></c>
336
+ <c r="C2"><v>300</v></c>
337
+ <c r="D2"><f>A2+B2+C2</f><v></v></c>
338
+ </row>
339
+ </sheetData>
340
+ ```
341
+
342
+ Rules:
343
+ - Adding a column at the end (after the last existing column) is safe — no existing formula references shift.
344
+ - Inserting a column in the middle shifts all columns to the right, which requires the same cascade updates as row insertion (see Section 5).
345
+ - Update the `<dimension>` element if present.
346
+
347
+ ---
348
+
349
+ ### 4.6 Modifying or Adding Styles
350
+
351
+ Styles use a multi-level indirect reference chain. Read `ooxml-cheatsheet.md` for the full chain. The key rule: **only append new entries, never modify existing ones**.
352
+
353
+ **Scenario:** Add a blue-font style (for hardcoded input cells) that doesn't yet exist.
354
+
355
+ **Step 1 — Check if a matching font already exists in `xl/styles.xml`:**
356
+ ```xml
357
+ <!-- Look inside <fonts> for an existing blue font -->
358
+ <font>
359
+ <color rgb="000000FF"/>
360
+ <!-- other attributes -->
361
+ </font>
362
+ ```
363
+
364
+ If found, note its index (zero-based position in the `<fonts>` list). If not found, append.
365
+
366
+ **Step 2 — Append the new font if needed:**
367
+
368
+ Before:
369
+ ```xml
370
+ <fonts count="3">
371
+ <font>...</font> <!-- index 0 -->
372
+ <font>...</font> <!-- index 1 -->
373
+ <font>...</font> <!-- index 2 -->
374
+ </fonts>
375
+ ```
376
+
377
+ After:
378
+ ```xml
379
+ <fonts count="4">
380
+ <font>...</font> <!-- index 0 -->
381
+ <font>...</font> <!-- index 1 -->
382
+ <font>...</font> <!-- index 2 -->
383
+ <font>
384
+ <b/>
385
+ <sz val="11"/>
386
+ <color rgb="000000FF"/>
387
+ <name val="Calibri"/>
388
+ </font> <!-- index 3 (new) -->
389
+ </fonts>
390
+ ```
391
+
392
+ **Step 3 — Append a new `<xf>` in `<cellXfs>`:**
393
+
394
+ Before:
395
+ ```xml
396
+ <cellXfs count="5">
397
+ <xf .../> <!-- index 0 -->
398
+ <xf .../> <!-- index 1 -->
399
+ <xf .../> <!-- index 2 -->
400
+ <xf .../> <!-- index 3 -->
401
+ <xf .../> <!-- index 4 -->
402
+ </cellXfs>
403
+ ```
404
+
405
+ After:
406
+ ```xml
407
+ <cellXfs count="6">
408
+ <xf .../> <!-- index 0 -->
409
+ <xf .../> <!-- index 1 -->
410
+ <xf .../> <!-- index 2 -->
411
+ <xf .../> <!-- index 3 -->
412
+ <xf .../> <!-- index 4 -->
413
+ <xf numFmtId="0" fontId="3" fillId="0" borderId="0" xfId="0"
414
+ applyFont="1"/> <!-- index 5 (new) -->
415
+ </cellXfs>
416
+ ```
417
+
418
+ **Step 4 — Apply to target cells:**
419
+
420
+ Before:
421
+ ```xml
422
+ <c r="B3">
423
+ <v>0.08</v>
424
+ </c>
425
+ ```
426
+
427
+ After:
428
+ ```xml
429
+ <c r="B3" s="5">
430
+ <v>0.08</v>
431
+ </c>
432
+ ```
433
+
434
+ Rules:
435
+ - Never delete or reorder existing entries in `<fonts>`, `<fills>`, `<borders>`, `<cellXfs>`.
436
+ - Always update the `count` attribute when appending.
437
+ - The new `cellXfs` index = the old `count` value before appending (zero-based: if count was 5, new index is 5).
438
+ - Custom `numFmt` IDs must be 164 or above. IDs 0–163 are built-in and must not be re-declared.
439
+ - If the desired style already exists elsewhere in the file (on a similar cell), reuse its `s` index rather than creating a duplicate.
440
+
441
+ ---
442
+
443
+ ### 4.7 Renaming a Sheet
444
+
445
+ **Only `xl/workbook.xml` needs to change** — unless cross-sheet formulas reference the old name.
446
+
447
+ **Before (`xl/workbook.xml`):**
448
+ ```xml
449
+ <sheet name="Sheet1" sheetId="1" r:id="rId1"/>
450
+ ```
451
+
452
+ **After:**
453
+ ```xml
454
+ <sheet name="Revenue" sheetId="1" r:id="rId1"/>
455
+ ```
456
+
457
+ **If any formula in any worksheet references the old name, update those too:**
458
+
459
+ Before (`xl/worksheets/sheet2.xml`):
460
+ ```xml
461
+ <c r="B5"><f>Sheet1!C10</f><v></v></c>
462
+ ```
463
+
464
+ After:
465
+ ```xml
466
+ <c r="B5"><f>Revenue!C10</f><v></v></c>
467
+ ```
468
+
469
+ If the new name contains spaces:
470
+ ```xml
471
+ <c r="B5"><f>'Q1 Revenue'!C10</f><v></v></c>
472
+ ```
473
+
474
+ Scan all worksheet XML files for the old name:
475
+ ```bash
476
+ grep -r "Sheet1!" /tmp/xlsx_work/xl/worksheets/
477
+ ```
478
+
479
+ Rules:
480
+ - The `.rels` file and `[Content_Types].xml` do NOT need to change — they reference the XML file path, not the sheet name.
481
+ - `sheetId` must not change; it is a stable internal identifier.
482
+ - Sheet names are case-sensitive in formula references.
483
+
484
+ ---
485
+
486
+ ## 5. High-Risk Operations — Cascade Effects
487
+
488
+ ### 5.1 Inserting a Row in the Middle
489
+
490
+ Inserting a row at position N shifts all rows from N downward. Every reference to those rows in every XML file must be updated.
491
+
492
+ **Files to check and update:**
493
+
494
+ | XML region | What to update | Example shift |
495
+ |------------|---------------|---------------|
496
+ | Worksheet `<row r="...">` attributes | Increment row number for all rows >= N | `r="7"` → `r="8"` |
497
+ | All `<c r="...">` within those rows | Increment row number in cell address | `r="A7"` → `r="A8"` |
498
+ | All `<f>` formula text in any sheet | Shift absolute row references >= N | `B7` → `B8` |
499
+ | `<mergeCell ref="...">` | Shift start and end rows | `A7:C7` → `A8:C8` |
500
+ | `<conditionalFormatting sqref="...">` | Shift range | `A5:D20` → `A5:D21` |
501
+ | `<dataValidations sqref="...">` | Shift range | `B6:B50` → `B7:B51` |
502
+ | `xl/charts/chartN.xml` data source ranges | Shift series ranges | `Sheet1!$B$5:$B$20` → `Sheet1!$B$6:$B$21` |
503
+ | `xl/pivotTables/*.xml` source ranges | Shift source data range | Handle with extreme care — see Section 7 |
504
+ | `<dimension ref="...">` | Expand to include new extent | `A1:D20` → `A1:D21` |
505
+ | `xl/tables/tableN.xml` `ref` attribute | Expand table boundary | `A1:D20` → `A1:D21` |
506
+
507
+ **Do not attempt row insertion manually in large or formula-heavy files.** Use the dedicated shift script instead:
508
+
509
+ ```bash
510
+ # Insert 1 row at row 5: all rows 5 and below shift down by 1
511
+ python3 SKILL_DIR/scripts/xlsx_shift_rows.py /tmp/xlsx_work/ insert 5 1
512
+
513
+ # Delete 1 row at row 8: all rows 9 and above shift up by 1
514
+ python3 SKILL_DIR/scripts/xlsx_shift_rows.py /tmp/xlsx_work/ delete 8 1
515
+ ```
516
+
517
+ The script updates in one pass: `<row r="...">` attributes, `<c r="...">` cell addresses, all `<f>` formula text across every worksheet, `<mergeCell>` ranges, `<conditionalFormatting sqref="...">`, `<dataValidation sqref="...">`, `<dimension ref="...">`, table `ref` attributes in `xl/tables/`, chart series ranges in `xl/charts/`, and pivot cache source ranges in `xl/pivotCaches/`.
518
+
519
+ **After running the shift script, always repack and validate:**
520
+ ```bash
521
+ python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
522
+ python3 SKILL_DIR/scripts/formula_check.py output.xlsx
523
+ ```
524
+
525
+ **What the script does NOT update (review manually):**
526
+ - Named ranges in `xl/workbook.xml` `<definedNames>` — check and update if they reference shifted rows.
527
+ - Structured table references (`Table[@Column]`) inside formulas.
528
+ - External workbook links in `xl/externalLinks/`.
529
+
530
+ ### 5.2 Inserting a Column in the Middle
531
+
532
+ Same cascade logic as row insertion, but for columns. Column references in formulas (`B`, `$C`, etc.) and in merged cell ranges, conditional formatting ranges, and chart data sources all need updating.
533
+
534
+ Column letter shifting is harder to automate safely. Prefer **appending columns at the end** whenever possible.
535
+
536
+ ### 5.3 Deleting a Row or Column
537
+
538
+ Deletion is more dangerous than insertion because any formula that referenced a deleted row or column will become `#REF!`. Before deleting:
539
+
540
+ 1. Search all `<f>` elements for references to the deleted range.
541
+ 2. If any formula references a cell in the deleted row/column, do not delete — instead, either clear the row's data or consult the user.
542
+ 3. After deletion, shift all references to rows/columns beyond the deletion point downward/leftward.
543
+
544
+ ---
545
+
546
+ ## 6. Template Filling — Identifying and Populating Input Cells
547
+
548
+ Templates designate certain cells as input zones. Common patterns to recognize them:
549
+
550
+ ### 6.1 How Templates Signal Input Zones
551
+
552
+ | Signal | XML manifestation | What to look for |
553
+ |--------|-------------------|-----------------|
554
+ | Blue font color | `s` attribute pointing to a `cellXfs` entry with `fontId` → `<color rgb="000000FF"/>` | Check `styles.xml` to decode `s` values |
555
+ | Yellow fill (highlight) | `s` → `fillId` → `<fill><patternFill><fgColor rgb="00FFFF00"/>` | |
556
+ | Empty `<v>` element | `<c r="B5"><v></v></c>` or cell entirely absent from `<row>` | The cell has no value yet |
557
+ | Comment/annotation near cell | `xl/comments1.xml` with `ref="B5"` | Comments often label input fields |
558
+ | Named ranges | `xl/workbook.xml` `<definedName>` elements | Template may define `InputRevenue` etc. |
559
+
560
+ ### 6.2 Filling a Template Cell
561
+
562
+ Do not change `s` attributes. Do not change `t` attributes unless you must change from empty to typed. Only change `<v>` or add `<f>`.
563
+
564
+ **Before (empty input cell with style preserved):**
565
+ ```xml
566
+ <c r="C5" s="3">
567
+ <v></v>
568
+ </c>
569
+ ```
570
+
571
+ **After (filled with a number, style unchanged):**
572
+ ```xml
573
+ <c r="C5" s="3">
574
+ <v>125000</v>
575
+ </c>
576
+ ```
577
+
578
+ **After (filled with text — requires shared string entry first):**
579
+ ```xml
580
+ <!-- 1. Append to sharedStrings.xml: <si><t>North Region</t></si> at index 7 -->
581
+ <c r="C5" t="s" s="3">
582
+ <v>7</v>
583
+ </c>
584
+ ```
585
+
586
+ **After (filled with a formula, preserving style):**
587
+ ```xml
588
+ <c r="C5" s="3">
589
+ <f>Assumptions!D12</f>
590
+ <v></v>
591
+ </c>
592
+ ```
593
+
594
+ ### 6.3 Locating Input Zones Without Opening the File in Excel
595
+
596
+ After unpacking, decode the style index on suspected input cells to determine if they have the template's input color:
597
+
598
+ 1. Note the `s` value on the cell (e.g., `s="4"`).
599
+ 2. In `xl/styles.xml`, find `<cellXfs>` and look at the 5th entry (index 4).
600
+ 3. Note its `fontId` (e.g., `fontId="2"`).
601
+ 4. In `<fonts>`, look at the 3rd entry (index 2) and check for `<color rgb="000000FF"/>` (blue) or other input marker.
602
+
603
+ If the template uses named ranges as input fields, read them from `xl/workbook.xml`:
604
+ ```xml
605
+ <definedNames>
606
+ <definedName name="InputGrowthRate">Assumptions!$B$5</definedName>
607
+ <definedName name="InputDiscountRate">Assumptions!$B$6</definedName>
608
+ </definedNames>
609
+ ```
610
+
611
+ Fill the target cells (`Assumptions!B5`, `Assumptions!B6`) directly.
612
+
613
+ ### 6.4 Template Filling Rules
614
+
615
+ - Fill only cells the template designated as inputs. Do not fill cells that are formula-driven.
616
+ - Do not apply new styles when filling. The template's formatting is the deliverable.
617
+ - Do not add or remove rows inside the template's data area unless the template explicitly has an "append here" zone.
618
+ - After filling, verify that no formula errors were introduced: some templates have input-validation formulas that produce `#VALUE!` if the wrong data type is entered.
619
+
620
+ ---
621
+
622
+ ## 7. Files You Must Never Modify
623
+
624
+ ### 7.1 Absolute no-touch list
625
+
626
+ | File / location | Why |
627
+ |-----------------|-----|
628
+ | `xl/vbaProject.bin` | Binary VBA bytecode. Any byte modification corrupts the macro project. Editing even one bit makes the macros fail to load. |
629
+ | `xl/pivotCaches/pivotCacheDefinition*.xml` | The cache definition ties the pivot table to its source data. Editing it without also updating the corresponding `pivotTable*.xml` will corrupt the pivot. |
630
+ | `xl/pivotTables/*.xml` | Pivot table XML is tightly coupled with the cache definition and with internal state Excel rebuilds on load. Do not edit. If you shifted rows and the pivot's source range now points to wrong data, update only the `<cacheSource>` range in the cache definition, and only the `ref` attribute in the pivot table — no other changes. |
631
+ | `xl/slicers/*.xml` | Slicers are connected to specific cache IDs and pivot fields. Breaking these connections silently corrupts the file. |
632
+ | `xl/connections.xml` | External data connections. Editing breaks live data refresh. |
633
+ | `xl/externalLinks/` | External workbook links. The binary `.bin` files in here must not be modified. |
634
+
635
+ ### 7.2 Conditionally safe files (update only specific attributes)
636
+
637
+ | File | What you may update | What to leave alone |
638
+ |------|--------------------|--------------------|
639
+ | `xl/charts/chartN.xml` | Data series range references (`<numRef><f>`) after a row/column shift | Chart type, formatting, layout |
640
+ | `xl/tables/tableN.xml` | `ref` attribute on `<table>` after adding rows | Column definitions, style info |
641
+ | `xl/pivotCaches/pivotCacheDefinition*.xml` | `ref` attribute on `<cacheSource><worksheetSource>` after shifting source data | All other content |
642
+
643
+ ---
644
+
645
+ ## 8. Validation After Every Edit
646
+
647
+ Never skip validation. Even a one-character change in a formula can cause cascading errors.
648
+
649
+ ```bash
650
+ # Pack
651
+ python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
652
+
653
+ # Static formula validation (always run)
654
+ python3 SKILL_DIR/scripts/formula_check.py output.xlsx
655
+
656
+ # Dynamic validation (if LibreOffice available)
657
+ python3 SKILL_DIR/scripts/libreoffice_recalc.py output.xlsx /tmp/recalc.xlsx
658
+ python3 SKILL_DIR/scripts/formula_check.py /tmp/recalc.xlsx
659
+ ```
660
+
661
+ If `formula_check.py` reports any error:
662
+ 1. Unpack the output file again (it is the packed version).
663
+ 2. Locate the reported cell in the worksheet XML.
664
+ 3. Fix the `<f>` element.
665
+ 4. Repack and re-validate.
666
+
667
+ Do not deliver the file until `formula_check.py` reports zero errors.
668
+
669
+ ---
670
+
671
+ ## 9. Absolute Rules Summary
672
+
673
+ | Rule | Rationale |
674
+ |------|-----------|
675
+ | Never use openpyxl `load_workbook` + `save` on an existing file | Round-trip destroys pivot tables, VBA, sparklines, slicers |
676
+ | Never delete or reorder existing `<si>` entries in sharedStrings | Breaks every cell referencing that index |
677
+ | Never delete or reorder existing `<xf>` entries in `<cellXfs>` | Breaks every cell using that style index |
678
+ | Never modify `vbaProject.bin` | Binary file; any change corrupts VBA |
679
+ | Never change `sheetId` when renaming a sheet | Internal ID is stable; changing it breaks relationships |
680
+ | Never skip post-edit validation | Leaves broken references undetected |
681
+ | Never edit more XML nodes than required | Extra changes risk introducing subtle corruption |
682
+ | Clear `<v>` to empty string when changing a formula | Prevents stale cached value from misleading downstream consumers |
683
+ | Append-only to sharedStrings | Existing indexes must remain valid |
684
+ | Append-only to styles collections | Existing style indexes must remain valid |