Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 59088bd

Browse files
author
Steve Canny
committed
pkg: add .main_document property
Locates the main document part, e.g. word/document.xml for a Word package, ppt/presentation.xml for a PowerPoint document.
1 parent 4dca747 commit 59088bd

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎opc/package.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Provides an API for manipulating Open Packaging Convention (OPC) packages.
1212
"""
1313

14+
from opc.constants import RELATIONSHIP_TYPE as RT
1415
from opc.oxml import CT_Relationships
1516
from opc.packuri import PACKAGE_URI
1617
from opc.pkgreader import PackageReader
@@ -27,6 +28,17 @@ def __init__(self):
2728
super(OpcPackage, self).__init__()
2829
self._rels = RelationshipCollection(PACKAGE_URI.baseURI)
2930

31+
@property
32+
def main_document(self):
33+
"""
34+
Return a reference to the main document part for this package.
35+
Examples include a document part for a WordprocessingML package, a
36+
presentation part for a PresentationML package, or a workbook part
37+
for a SpreadsheetML package.
38+
"""
39+
rel = self._rels.get_rel_of_type(RT.OFFICE_DOCUMENT)
40+
return rel.target_part
41+
3042
@staticmethod
3143
def open(pkg_file):
3244
"""

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /