Updating¶
Edits to existing files that keep everything else in the package.
XlsxUpdater
¶
XlsxUpdater(path: str | PathLike[str])
Bases: _UpdaterBase, XlsxEditMixin, XlsxSheetsMixin
Replace the data region of sheets in an existing XLSX or XLSM file.
The workbook, styles, drawings and all unrelated ZIP members are kept in place. Only the selected worksheet XML, shared strings and pivot-cache metadata are changed. Macro parts in an XLSM package are copied as opaque ZIP members and are never parsed or rewritten.
Source code in src/xlspy/xlsx_updater.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
get_sheet_states
¶
get_sheet_states() -> dict[str, str]
Sheet visibility (visible, hidden or veryHidden) by name.
Source code in src/xlspy/_xlsx_sheets.py
90 91 92 93 94 95 96 97 98 99 100 | |
get_active_sheet
¶
get_active_sheet() -> int
Index of the sheet Excel shows when the workbook opens.
Source code in src/xlspy/_xlsx_sheets.py
102 103 104 105 106 107 108 | |
set_active_sheet
¶
set_active_sheet(index: int) -> None
Make the sheet at 0-based index the active one.
Source code in src/xlspy/_xlsx_sheets.py
110 111 112 113 114 115 116 117 118 119 120 121 | |
set_sheet_state
¶
set_sheet_state(name: str, state: str) -> None
Set a sheet to "visible", "hidden" or "veryHidden".
Source code in src/xlspy/_xlsx_sheets.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
add_sheet
¶
add_sheet(name: str, index: int | None = None, *, state: str = 'visible') -> str
Add an empty worksheet at index (default: last); return its part path.
Source code in src/xlspy/_xlsx_sheets.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
remove_sheet
¶
remove_sheet(name: str) -> None
Remove a sheet, its part and the parts only it refers to.
References to it become #REF! and names local to it are dropped.
Source code in src/xlspy/_xlsx_sheets.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
rename_sheet
¶
rename_sheet(old: str, new: str) -> None
Rename sheet old to new; raises KeyError when old is absent.
Source code in src/xlspy/_xlsx_sheets.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
reorder_sheets
¶
reorder_sheets(order: Iterable[str]) -> None
Put the sheets in order (every sheet name, once).
Source code in src/xlspy/_xlsx_sheets.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
get_comments
¶
get_comments(sheet_name: str) -> dict[str, Comment]
Read classic note text and authors from the current staged package.
Source code in src/xlspy/_xlsx_edit.py
165 166 167 168 169 | |
get_threaded_comments
¶
get_threaded_comments(sheet_name: str) -> dict[str, ThreadedComment]
Read Excel 365 conversations from the current staged package.
Source code in src/xlspy/_xlsx_edit.py
171 172 173 174 175 176 177 178 179 180 | |
set_comments
¶
set_comments(sheet_name: str, comments: Mapping[str, Comment | None]) -> None
Set selected classic notes; None removes a note, other notes are kept.
Source code in src/xlspy/_xlsx_edit.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
set_threaded_comments
¶
set_threaded_comments(sheet_name: str, comments: Mapping[str, ThreadedComment | None]) -> None
Set selected Excel 365 conversations; None removes a conversation.
The first message of each conversation owns its replies. Excel needs a
classic note whose author is tc={id} to link a conversation to its
cell, so this method writes that companion note too.
Source code in src/xlspy/_xlsx_edit.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | |
set_hyperlinks
¶
set_hyperlinks(sheet_name: str, links: Mapping[str, Hyperlink | None]) -> None
Set selected cells' hyperlinks; None removes one, other links are kept.
Only the link changes: the cell's value and style stay as they are. A link whose range starts at a given cell is replaced as a whole.
Source code in src/xlspy/_xlsx_edit.py
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
get_defined_names
¶
get_defined_names() -> list[DefinedName]
Return user-defined global and worksheet-local names.
Source code in src/xlspy/_xlsx_edit.py
615 616 617 | |
set_defined_name
¶
set_defined_name(definition: DefinedName) -> None
Add a defined name, replacing one with the same name and scope.
Source code in src/xlspy/_xlsx_edit.py
619 620 621 | |
set_defined_names
¶
set_defined_names(definitions: Iterable[DefinedName]) -> None
Add many defined names in one workbook rewrite (linear, not quadratic).
Source code in src/xlspy/_xlsx_edit.py
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 | |
remove_defined_name
¶
remove_defined_name(name: str, scope: str | None = None) -> None
Remove a defined name; with scope, the one local to that sheet.
Source code in src/xlspy/_xlsx_edit.py
692 693 694 | |
remove_defined_names
¶
remove_defined_names(names: Iterable[tuple[str, str | None]]) -> None
Remove many defined names in one workbook rewrite.
Source code in src/xlspy/_xlsx_edit.py
696 697 698 699 700 701 702 703 704 705 706 707 708 709 | |
set_sheet_protection
¶
set_sheet_protection(sheet_name: str, protection: SheetProtection) -> None
Set or replace the protection of a sheet.
Source code in src/xlspy/_xlsx_edit.py
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | |
set_merged_cells
¶
set_merged_cells(sheet_name: str, ranges: Iterable[str]) -> None
Replace the sheet's merged ranges with ranges (A1 range strings).
Source code in src/xlspy/_xlsx_edit.py
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 | |
set_data_validations
¶
set_data_validations(sheet_name: str, rules: Sequence[DataValidation]) -> None
Replace the sheet's data validation rules with rules.
Source code in src/xlspy/_xlsx_edit.py
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | |
set_workbook_protection
¶
set_workbook_protection(protection: WorkbookProtection) -> None
Set or replace the workbook protection.
Source code in src/xlspy/_xlsx_edit.py
780 781 782 783 784 785 786 | |
update_cells
¶
update_cells(sheet_name: str, cells: Mapping[str, object], *, styles: Mapping[str, int] | None = None) -> None
Update sparse cells, preserving styles, notes and untouched cell XML.
styles maps addresses to cell XF indexes. An address only in
styles keeps its value (or becomes a styled blank).
Source code in src/xlspy/_xlsx_edit.py
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 | |
close
¶
close() -> None
Release temporary files held by the updater.
While in use, the updater keeps shared-string data and staged package
parts on disk. Calling close (or simply dropping the updater)
removes them.
Source code in src/xlspy/_updater_base.py
82 83 84 85 86 87 88 89 90 91 92 | |
get_sheet_names
¶
get_sheet_names() -> list[str]
Return worksheet and chartsheet names in workbook order.
Source code in src/xlspy/_updater_base.py
112 113 114 115 | |
get_worksheet_names
¶
get_worksheet_names() -> list[str]
The names of the worksheets alone, in workbook order.
Source code in src/xlspy/_updater_base.py
117 118 119 120 | |
get_chartsheet_names
¶
get_chartsheet_names() -> list[str]
The chartsheet names, in workbook order.
Source code in src/xlspy/_updater_base.py
122 123 124 125 | |
replace_sheet_data
¶
replace_sheet_data(sheet_name: str, rows: Iterable[Sequence[Any]], *, headers: Sequence[str] | None = None, style_fallback: StyleFallback = 'inherit') -> None
Replace one worksheet's used data region.
rows is materialised once, so generators are supported but the
operation remains atomic with respect to the in-memory package. A
(value, format_string) cell is accepted for compatibility with the
writers; its value is used and no new style is created. Once a
streaming shared-string store is loaded, the call is forwarded to
replace_sheet_data_stream.
Source code in src/xlspy/_updater_base.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
replace_sheet_data_stream
¶
replace_sheet_data_stream(sheet_name: str, rows: Iterable[Sequence[Any]], *, headers: Sequence[str] | None = None, style_fallback: StyleFallback = 'inherit') -> None
Replace worksheet data atomically while streaming rows.
The package and disk-backed shared-string index are committed only after the one-pass row source and all metadata updates succeed. A failure therefore leaves this updater reusable for a later attempt.
Source code in src/xlspy/_updater_base.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
save
¶
save(output_path: str | PathLike[str] | None = None) -> None
Save to a new path or atomically replace the input file.
Source code in src/xlspy/_updater_base.py
317 318 319 320 | |
to_bytes
¶
to_bytes() -> bytes
Return the current package as bytes in the updater's format.
Source code in src/xlspy/_updater_base.py
322 323 324 325 | |
XlsbUpdater
¶
XlsbUpdater(path: str | PathLike[str])
Bases: _UpdaterBase, XlsbSheetsMixin, XlsbEditMixin
Replace the data region of sheets in an existing XLSB file.
Source code in src/xlspy/xlsb_updater.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
DataValidation
dataclass
¶
DataValidation(type: str, sqref: str | tuple[str, ...] | list[str], formula1: object = None, formula2: object = None, operator: str | None = None, allow_blank: bool = True, show_dropdown: bool = True, show_input_message: bool = False, prompt_title: str | None = None, prompt: str | None = None, show_error_message: bool = True, error_title: str | None = None, error: str | None = None, error_style: str = 'stop', ime_mode: str | None = None)
A validation rule applied to one or more cell ranges.
type is one of list, whole, decimal, date, time,
text_length or custom. For list the formula1 is either a
literal list such as '"New,Active,Closed"' or a range such as
"Lists!$A$2:$A$9". For custom it is a formula that must evaluate to
true for valid input. operator applies to the numeric, date, time and
text-length types only, and defaults to between.
show_dropdown=False hides the arrow of a list rule. allow_blank
accepts empty cells. Prompts and error messages are shown when their
show_* flag is true.
Examples:
Add a dropdown, a numeric range and a date rule to one sheet:
import datetime
from xlspy import DataValidation, XlsxWriter
rows = [["Region", "Amount", "Date"], ["North", 10, datetime.date(2026, 1, 5)]]
with XlsxWriter("validated.xlsx") as workbook:
workbook.add_sheet("Data")
workbook.write_sheet(
rows,
data_validations=[
DataValidation("list", "A2:A50", formula1='"North,South,East"'),
DataValidation("whole", "B2:B50", formula1=1, formula2=100),
DataValidation("date", "C2:C50", formula1=datetime.date(2026, 1, 1),
operator="greater_than"),
],
)
Invalid combinations raise ValueError when the rule is created.
See Also
Formula for custom rules, and ExcelTable for structured
references in a validation formula.
showDropDown
property
¶
showDropDown: bool
openpyxl's raw OOXML flag: True hides the in-cell list.
It is the inverse of show_dropdown.
Hyperlink
dataclass
¶
Hyperlink(target: str, text: str | None = None, tooltip: str | None = None)
A link written as the value of a cell.
target is an http, https, mailto or ftp URL, or an
internal location written as "#Sheet Name!B2" (quote the sheet name
with single quotes when it contains spaces: "#'Sales Data'!B2"). Other
schemes and relative file paths are refused. text is the displayed
label and defaults to the target; tooltip is shown on hover. Linked
cells use the built-in hyperlink look unless the cell has its own style.
Examples:
A Hyperlink is a cell value, so it goes where the text belongs:
from xlspy import Hyperlink, XlsxWriter
rows = [
["Report", Hyperlink("https://example.com/report", text="Open report")],
["Back", Hyperlink("#Links!A1", text="Back to top")],
]
with XlsxWriter("links.xlsx") as workbook:
workbook.add_sheet("Links")
workbook.write_sheet(rows)
See Also
Comment for a note attached to a cell, and Shape for a linked
shape.
ThreadedComment
dataclass
¶
ThreadedComment(text: str, author: str, created: datetime | None = None, resolved: bool = False, id: str | None = None, replies: list[ThreadedComment] = list(), _person: Person | None = None, _parent_id: str | None = None)
One message in an Excel 365 threaded conversation.
The first message owns replies and resolved. Replies are one level
deep; reply() appends one. created is optional: when it is None
the message carries no timestamp, which keeps a save deterministic. id
is generated on save when it is None.
Examples:
Write a conversation and a reply into a new workbook:
from xlspy import ThreadedComment, XlsxWriter
thread = ThreadedComment("Confirm the amount", "Jan")
thread.reply("Confirmed", "Ola")
with XlsxWriter("review.xlsx") as workbook:
workbook.add_sheet("Data")
workbook.write_sheet(
[["Amount"], [120]],
threaded_comments={"A2": thread},
)
See Also
Comment for classic notes, and XlsxUpdater.set_threaded_comments
for conversations in an existing workbook.
parent_id
property
¶
parent_id: str | None
The id of the message this one answers; None on the first message.
reply
¶
reply(text: str, author: str, created: datetime | None = None, id: str | None = None) -> ThreadedComment
Append a reply to this conversation and return it.
Source code in src/xlspy/threaded_comments.py
123 124 125 126 127 128 129 130 131 132 133 | |
DiskStringIndex
¶
DiskStringIndex(directory: str | PathLike[str], *, total_count: int = 0)
Disk-backed shared-string lookup with an append-only pending file.
The indexes of the strings looked up last are kept in memory as well (at
most _CACHE_LIMIT, so memory stays bounded): an index never changes
once given, except by add_existing and a rollback, which drop them.
Source code in src/xlspy/_zip_package.py
60 61 62 63 64 65 66 67 68 69 70 71 72 | |
add_existing
¶
add_existing(value: str, index: int) -> None
Add one original SST value using its stable zero-based index.
Source code in src/xlspy/_zip_package.py
79 80 81 82 83 84 85 86 87 88 89 | |
flush
¶
flush() -> None
Commit pending lookup-index inserts without clearing new values.
Source code in src/xlspy/_zip_package.py
142 143 144 145 146 147 | |
begin_transaction
¶
begin_transaction() -> None
Start a disk-backed transaction for one streamed replacement.
Source code in src/xlspy/_zip_package.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
commit_transaction
¶
commit_transaction() -> None
Commit the current streamed replacement transaction.
Source code in src/xlspy/_zip_package.py
180 181 182 183 184 185 186 187 188 189 190 191 192 | |
rollback_transaction
¶
rollback_transaction() -> None
Restore the index and pending values to the transaction snapshot.
Source code in src/xlspy/_zip_package.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
set_pending_tables
¶
set_pending_tables(pending: Iterable[Any], removed: Iterable[tuple[int, str]] = ()) -> None
The tables a save is about to write, each with its id (empty when the save is done).
Source code in src/xlspy/_xlsb_edit.py
179 180 181 182 | |
get_comments
¶
get_comments(sheet_name: str) -> dict[str, Comment]
The classic notes of a sheet, keyed by cell reference.
The compatibility notes of Excel 365 conversations are not included;
use get_threaded_comments for those.
Source code in src/xlspy/_xlsb_edit.py
212 213 214 215 216 217 218 219 220 221 222 223 224 | |
get_threaded_comments
¶
get_threaded_comments(sheet_name: str) -> dict[str, ThreadedComment]
Read the sheet's Excel 365 conversations, keyed by cell reference.
Source code in src/xlspy/_xlsb_edit.py
226 227 228 229 230 231 232 233 234 235 | |
set_comments
¶
set_comments(sheet_name: str, comments: Mapping[str, Comment | None]) -> None
Add or replace notes on a sheet, keyed by cell reference; None removes one.
Source code in src/xlspy/_xlsb_edit.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
set_threaded_comments
¶
set_threaded_comments(sheet_name: str, comments: Mapping[str, ThreadedComment | None]) -> None
Editing Excel 365 conversations in XLSB is not supported.
Source code in src/xlspy/_xlsb_edit.py
300 301 302 303 304 | |
get_defined_names
¶
get_defined_names() -> list[DefinedName]
The workbook's defined names.
Source code in src/xlspy/_xlsb_edit.py
328 329 330 | |
set_defined_name
¶
set_defined_name(definition: DefinedName) -> None
Add a defined name, replacing one with the same name and scope.
Source code in src/xlspy/_xlsb_edit.py
332 333 334 | |
set_defined_names
¶
set_defined_names(definitions: Iterable[DefinedName]) -> None
Add many defined names in one workbook rewrite (linear, not quadratic).
Source code in src/xlspy/_xlsb_edit.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
remove_defined_name
¶
remove_defined_name(name: str, scope: str | None = None) -> None
Remove a defined name; with scope, the one local to that sheet.
Source code in src/xlspy/_xlsb_edit.py
355 356 357 | |
remove_defined_names
¶
remove_defined_names(names: Iterable[tuple[str, str | None]]) -> None
Remove many defined names in one workbook rewrite.
Source code in src/xlspy/_xlsb_edit.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
set_sheet_protection
¶
set_sheet_protection(sheet_name: str, protection: SheetProtection) -> None
Set or replace the protection of a sheet.
Source code in src/xlspy/_xlsb_edit.py
380 381 382 383 384 385 386 387 388 389 390 391 | |
set_merged_cells
¶
set_merged_cells(sheet_name: str, ranges: Iterable[str]) -> None
Replace the sheet's merged ranges with ranges (A1 range strings).
Source code in src/xlspy/_xlsb_edit.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
set_hyperlinks
¶
set_hyperlinks(sheet_name: str, links: Mapping[str, Hyperlink | None]) -> None
Set selected cells' hyperlinks; None removes one, other links are kept.
Only the link changes: the cell's value and style stay as they are. A link whose range starts at a given cell is replaced as a whole. External targets reuse the sheet's hyperlink relationships, new ones get fresh ids, and a removed link's relationship goes unless another link uses it.
Source code in src/xlspy/_xlsb_edit.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
set_data_validations
¶
set_data_validations(sheet_name: str, rules: Sequence[DataValidation]) -> None
Replace the sheet's data validation rules with rules.
Source code in src/xlspy/_xlsb_edit.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
set_conditional_formats
¶
set_conditional_formats(sheet_name: str, formats: Iterable[tuple[str, bool | None, list[Any]]], dxf_id: Callable[[Any], int], links: Mapping[int, bytes] | None = None) -> None
Replace the sheet's conditional formats with formats, an
iterable of (sqref, pivot, rules); dxf_id(dxf) returns the
index of a rule's differential style in the style sheet. links maps
id(rule) to the BrtCFRuleExt payload of a rule whose Excel 2010
extension is kept as it is in the file.
Source code in src/xlspy/_xlsb_edit.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
set_workbook_protection
¶
set_workbook_protection(protection: WorkbookProtection) -> None
Set or replace the workbook protection.
Source code in src/xlspy/_xlsb_edit.py
551 552 553 554 555 556 557 558 559 | |
update_cells
¶
update_cells(sheet_name: str, cells: Mapping[str, object], *, styles: Mapping[str, int] | None = None) -> None
Set cell values; styles maps addresses to cell XF indexes.
An address only in styles keeps its value (or becomes a styled blank).
Source code in src/xlspy/_xlsb_edit.py
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | |
get_sheet_states
¶
get_sheet_states() -> dict[str, str]
Sheet visibility (visible, hidden or veryHidden) by name.
Source code in src/xlspy/_xlsb_sheets.py
113 114 115 116 117 118 | |
get_active_sheet
¶
get_active_sheet() -> int
Index of the sheet Excel shows when the workbook opens.
Source code in src/xlspy/_xlsb_sheets.py
120 121 122 123 124 125 126 | |
add_sheet
¶
add_sheet(name: str, index: int | None = None, *, state: str = 'visible') -> str
Add an empty worksheet at index (default: last); return its part path.
Source code in src/xlspy/_xlsb_sheets.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
remove_sheet
¶
remove_sheet(name: str) -> None
Remove a sheet, its part and its relationships.
References to it become #REF! and names local to it are dropped.
Source code in src/xlspy/_xlsb_sheets.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
rename_sheet
¶
rename_sheet(old: str, new: str) -> None
Rename sheet old to new; raises KeyError when old is absent.
Source code in src/xlspy/_xlsb_sheets.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
reorder_sheets
¶
reorder_sheets(order: Iterable[str]) -> None
Put the sheets in order (every sheet name, once).
Source code in src/xlspy/_xlsb_sheets.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
set_sheet_state
¶
set_sheet_state(name: str, state: str) -> None
Set a sheet to "visible", "hidden" or "veryHidden".
Source code in src/xlspy/_xlsb_sheets.py
253 254 255 256 257 258 259 260 261 262 263 264 | |
set_active_sheet
¶
set_active_sheet(index: int) -> None
Make the sheet at 0-based index the active one.
Source code in src/xlspy/_xlsb_sheets.py
266 267 268 269 270 271 272 273 274 | |
close
¶
close() -> None
Release temporary files held by the updater.
While in use, the updater keeps shared-string data and staged package
parts on disk. Calling close (or simply dropping the updater)
removes them.
Source code in src/xlspy/_updater_base.py
82 83 84 85 86 87 88 89 90 91 92 | |
get_sheet_names
¶
get_sheet_names() -> list[str]
Return worksheet and chartsheet names in workbook order.
Source code in src/xlspy/_updater_base.py
112 113 114 115 | |
get_worksheet_names
¶
get_worksheet_names() -> list[str]
The names of the worksheets alone, in workbook order.
Source code in src/xlspy/_updater_base.py
117 118 119 120 | |
get_chartsheet_names
¶
get_chartsheet_names() -> list[str]
The chartsheet names, in workbook order.
Source code in src/xlspy/_updater_base.py
122 123 124 125 | |
replace_sheet_data
¶
replace_sheet_data(sheet_name: str, rows: Iterable[Sequence[Any]], *, headers: Sequence[str] | None = None, style_fallback: StyleFallback = 'inherit') -> None
Replace one worksheet's used data region.
rows is materialised once, so generators are supported but the
operation remains atomic with respect to the in-memory package. A
(value, format_string) cell is accepted for compatibility with the
writers; its value is used and no new style is created. Once a
streaming shared-string store is loaded, the call is forwarded to
replace_sheet_data_stream.
Source code in src/xlspy/_updater_base.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
replace_sheet_data_stream
¶
replace_sheet_data_stream(sheet_name: str, rows: Iterable[Sequence[Any]], *, headers: Sequence[str] | None = None, style_fallback: StyleFallback = 'inherit') -> None
Replace worksheet data atomically while streaming rows.
The package and disk-backed shared-string index are committed only after the one-pass row source and all metadata updates succeed. A failure therefore leaves this updater reusable for a later attempt.
Source code in src/xlspy/_updater_base.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
save
¶
save(output_path: str | PathLike[str] | None = None) -> None
Save to a new path or atomically replace the input file.
Source code in src/xlspy/_updater_base.py
317 318 319 320 | |
to_bytes
¶
to_bytes() -> bytes
Return the current package as bytes in the updater's format.
Source code in src/xlspy/_updater_base.py
322 323 324 325 | |