Edit .xlsx with openpyxl without breaking OneDrive/SharePoint sync or version history
Project description
onedrive_safe_xlsx
Edit .xlsx files with openpyxl without breaking OneDrive / SharePoint sync and version history.
The problem
openpyxl rebuilds a workbook from its own minimal model when it saves. A real Excel file
has ~26 OOXML parts; openpyxl writes ~9 — it silently drops customXml/*,
docProps/custom.xml, printerSettings, calcChain, and more.
On OneDrive/SharePoint those parts carry the document's identity and library binding. Strip them and your edits can:
- lose the file's version lineage (each save looks like a new/foreign file rather than a new version of the same document), and
- if you do preserve the parts but copy
docProps/core.xmlunchanged, itsdcterms:modified/cp:revisionstay the same, so SharePoint decides nothing changed and won't record a new version.
The fix
save_preserving() edits the data via openpyxl but:
- Keeps every non-data part from the original file (identity preserved).
- Updates the change-tracking in
core.xml—dcterms:modified→ now,cp:lastModifiedBy, and bumpscp:revision— so SharePoint logs a genuine new version.
Usage
import openpyxl
from onedrive_safe_xlsx import save_preserving
wb = openpyxl.load_workbook("Report.xlsx") # an Excel/SharePoint-saved file
wb.active["A1"] = "edited"
save_preserving("Report.xlsx", wb, modified_by="Jane Doe")
Caveats
- Start from an Excel/SharePoint-saved copy — it has the parts to preserve. A file only ever written by openpyxl has nothing to preserve (open + save it in Excel once first).
- Uses
datetime.now(timezone.utc)for the timestamp — cross-platform (Windows/macOS/Linux). - Doesn't manage
rsidco-authoring markers — intended for sequential (not concurrent) edits.
How to cite
If it helps your work, a credit is appreciated — GitHub's "Cite this repository" button
uses CITATION.cff. The licence is permissive (Apache-2.0), so this is a request, not a
requirement.
Licence
Apache-2.0 — see LICENSE. Copyright 2026 Jonathan Corcutt; attribution terms in NOTICE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file onedrive_safe_xlsx-0.1.0.tar.gz.
File metadata
- Download URL: onedrive_safe_xlsx-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7a6a160f80af0114dfd97cab282bda574c833e144b15864e822130e21bcd8b8
|
|
| MD5 |
a169d88b11cf0be9ca6df1c4a69415ed
|
|
| BLAKE2b-256 |
932fdf756e5d487ee38d80c957ddb0768b366a052c650fe29bb0f6f08d0ac349
|
Provenance
The following attestation bundles were made for onedrive_safe_xlsx-0.1.0.tar.gz:
Publisher:
publish.yml on jonnymaserati/onedrive-safe-xlsx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
onedrive_safe_xlsx-0.1.0.tar.gz -
Subject digest:
c7a6a160f80af0114dfd97cab282bda574c833e144b15864e822130e21bcd8b8 - Sigstore transparency entry: 2164896291
- Sigstore integration time:
-
Permalink:
jonnymaserati/onedrive-safe-xlsx@f8732c6ba6a8e0d0f3b0cfbea2f3e37fdb07ecd2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/jonnymaserati
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f8732c6ba6a8e0d0f3b0cfbea2f3e37fdb07ecd2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file onedrive_safe_xlsx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: onedrive_safe_xlsx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32849915e051f422fb463b4894d7cde287206a3b59a159bce9e0c92510cd1906
|
|
| MD5 |
2ef76edea0a85783ff56c0f3c133d5df
|
|
| BLAKE2b-256 |
915fcc177a181f2900d27c570e501b46fb8aaeceb803da59764a77eff40a7b68
|
Provenance
The following attestation bundles were made for onedrive_safe_xlsx-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on jonnymaserati/onedrive-safe-xlsx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
onedrive_safe_xlsx-0.1.0-py3-none-any.whl -
Subject digest:
32849915e051f422fb463b4894d7cde287206a3b59a159bce9e0c92510cd1906 - Sigstore transparency entry: 2164896306
- Sigstore integration time:
-
Permalink:
jonnymaserati/onedrive-safe-xlsx@f8732c6ba6a8e0d0f3b0cfbea2f3e37fdb07ecd2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/jonnymaserati
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f8732c6ba6a8e0d0f3b0cfbea2f3e37fdb07ecd2 -
Trigger Event:
release
-
Statement type: