Skip to main content

onedrive_safe_xlsx

tests

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.xml unchanged, its dcterms:modified / cp:revision stay the same, so SharePoint decides nothing changed and won't record a new version.

The fix

save_preserving() edits the data via openpyxl but:

  1. Keeps every non-data part from the original file (identity preserved).
  2. Updates the change-tracking in core.xml — dcterms:modified → now, cp:lastModifiedBy, and bumps cp: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 rsid co-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.

Metadata

Release files for onedrive-safe-xlsx 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for onedrive-safe-xlsx 0.1.0
File Size Uploaded
onedrive_safe_xlsx-0.1.0.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for onedrive-safe-xlsx 0.1.0
File Interpreter ABI Platform
onedrive_safe_xlsx-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / onedrive_safe_xlsx-0.1.0.tar.gz

Download URL onedrive_safe_xlsx-0.1.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c7a6a160f80af0114dfd97cab282bda574c833e144b15864e822130e21bcd8b8
BLAKE2b-256 checksum
How to use checksums
932fdf756e5d487ee38d80c957ddb0768b366a052c650fe29bb0f6f08d0ac349
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.

Transparency log

Release files / onedrive_safe_xlsx-0.1.0-py3-none-any.whl

Download URL onedrive_safe_xlsx-0.1.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32849915e051f422fb463b4894d7cde287206a3b59a159bce9e0c92510cd1906
BLAKE2b-256 checksum
How to use checksums
915fcc177a181f2900d27c570e501b46fb8aaeceb803da59764a77eff40a7b68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page