Skip to main content

Edit .xlsx with openpyxl without breaking OneDrive/SharePoint sync or version history

Project description

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.xmldcterms: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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onedrive_safe_xlsx-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onedrive_safe_xlsx-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

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

Hashes for onedrive_safe_xlsx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c7a6a160f80af0114dfd97cab282bda574c833e144b15864e822130e21bcd8b8
MD5 a169d88b11cf0be9ca6df1c4a69415ed
BLAKE2b-256 932fdf756e5d487ee38d80c957ddb0768b366a052c650fe29bb0f6f08d0ac349

See more details on using hashes here.

Provenance

The following attestation bundles were made for onedrive_safe_xlsx-0.1.0.tar.gz:

Publisher: publish.yml on jonnymaserati/onedrive-safe-xlsx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onedrive_safe_xlsx-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for onedrive_safe_xlsx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32849915e051f422fb463b4894d7cde287206a3b59a159bce9e0c92510cd1906
MD5 2ef76edea0a85783ff56c0f3c133d5df
BLAKE2b-256 915fcc177a181f2900d27c570e501b46fb8aaeceb803da59764a77eff40a7b68

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page