Coder Social home page Coder Social logo

oodocx's Introduction

oodocx

Note: I cut my teeth programming this project. As a result, the code is questionably written, poorly modularized, and lacks anything even remotely resembling a testing suite. That said, everything works as it should, and it contains several features that the superiorly constructed python-docx currently lacks. As a result, for the time being at least, this repository will remain available.

Installation

First, ensure that you have the appropriate version of lxml installed. Then, clone this repository, navigate your shell window to the oodocx directory folder that contains the setup.py file, and enter "python setup.py install" (or just "setup.py install", depending on how you execute python files on your computer)

How do I...

First of all, be sure to check out the /examples folder for basic examples of this module

Create a new document, insert a paragraph of text, and save it

d = oodocx.Docx()
d.body.append(oodocx.paragraph('Hello world!'))
d.save('hello.docx')

Open a document, insert a paragraph after the paragraph containing the word "apple", and save it somewhere else

d = oodocx.Docx(r'C:\users\applecart\apples.docx')
apple_para = d.search('apple', result_type='paragraph')
pos = body.index(apple_para) + 1 #lxml
d.body.insert(pos, oodocx.paragraph('Bananas!')) #lxml
d.save(r'C:\users\bananstand\there's always money here.docx')

Note that the index() and insert() methods in the fourth and fifth lines of the above code are from the underlying lxml module. Check out the documentation here.

oodocx's People

Contributors

ajmirsky avatar etfre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

oodocx's Issues

Style shortcut keys don't work after saving

Using microsoft word 2011 for mac, you can assign a shortcut key to a specific style. Attached are the screenshots of where it is located in Word. By comparing two docx where the only difference is adding a shortcut key to the Quote style, it seems that an extra file gets added to the word/ directory called customizations.xml which contains this snippet:

   <wne:keymaps>
    <wne:keymap wne:kcmprimary="105A">
     <wne:acd wne:acdname="acd0">
     </wne:acd>
    </wne:keymap>
   </wne:keymaps>

Did some research through the OOXML standard and I haven't found any documentation that describes this file. Or describes the keymap or keymaps tags. Perhaps it's just a matter of including this file, if it exists, from the original docx that was opened?

Can't upload them here but I can send you the two docx files if it would be helpful.

shortcut key screen 1
shortcut key screen 2

paragraph() got an unexpected keyword argument 'jc'

While using the table() function i encountered the stated error.
The statement causing it is in line 957:
cell.append(paragraph(h, jc='center'))

is jc=center a legacy call? The paragraph() function signature doesn't have that parameter, but it is still present in the function documentation.

Error installing oodocx

I found this error while trying to install oodocx. I tried the same in a virtualenv, with still the same error.

$ sudo python setup.py install
running install
running bdist_egg
running egg_info
writing oodocx.egg-info/PKG-INFO
writing top-level names to oodocx.egg-info/top_level.txt
writing dependency_links to oodocx.egg-info/dependency_links.txt
reading manifest template 'MANIFEST.in'
writing manifest file 'oodocx.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/oodocx
copying build/lib/oodocx/oodocx.py -> build/bdist.linux-x86_64/egg/oodocx
copying build/lib/oodocx/write_files.py -> build/bdist.linux-x86_64/egg/oodocx
copying build/lib/oodocx/init.py -> build/bdist.linux-x86_64/egg/oodocx
creating build/bdist.linux-x86_64/egg/oodocx/template
creating build/bdist.linux-x86_64/egg/oodocx/template/word
copying build/lib/oodocx/template/word/webSettings.xml -> build/bdist.linux-x86_64/egg/oodocx/template/word
copying build/lib/oodocx/template/word/document.xml -> build/bdist.linux-x86_64/egg/oodocx/template/word
copying build/lib/oodocx/template/word/stylesWithEffects.xml -> build/bdist.linux-x86_64/egg/oodocx/template/word
creating build/bdist.linux-x86_64/egg/oodocx/template/word/theme
copying build/lib/oodocx/template/word/theme/theme1.xml -> build/bdist.linux-x86_64/egg/oodocx/template/word/theme
copying build/lib/oodocx/template/word/settings.xml -> build/bdist.linux-x86_64/egg/oodocx/template/word
creating build/bdist.linux-x86_64/egg/oodocx/template/word/_rels
copying build/lib/oodocx/template/word/_rels/document.xml.rels -> build/bdist.linux-x86_64/egg/oodocx/template/word/_rels
copying build/lib/oodocx/template/word/fontTable.xml -> build/bdist.linux-x86_64/egg/oodocx/template/word
copying build/lib/oodocx/template/word/styles.xml -> build/bdist.linux-x86_64/egg/oodocx/template/word
creating build/bdist.linux-x86_64/egg/oodocx/template/docProps
copying build/lib/oodocx/template/docProps/core.xml -> build/bdist.linux-x86_64/egg/oodocx/template/docProps
copying build/lib/oodocx/template/docProps/app.xml -> build/bdist.linux-x86_64/egg/oodocx/template/docProps
creating build/bdist.linux-x86_64/egg/oodocx/examples
copying build/lib/oodocx/examples/example1.py -> build/bdist.linux-x86_64/egg/oodocx/examples
copying build/lib/oodocx/init.pyc -> build/bdist.linux-x86_64/egg/oodocx
copying build/lib/oodocx/helper_functions.py -> build/bdist.linux-x86_64/egg/oodocx
byte-compiling build/bdist.linux-x86_64/egg/oodocx/oodocx.py to oodocx.pyc
SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/oodocx/oodocx.py', 630, 34, " attributes={'val', 'subscript'})\n"))

byte-compiling build/bdist.linux-x86_64/egg/oodocx/write_files.py to write_files.pyc
byte-compiling build/bdist.linux-x86_64/egg/oodocx/examples/example1.py to example1.pyc
byte-compiling build/bdist.linux-x86_64/egg/oodocx/helper_functions.py to helper_functions.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying oodocx.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying oodocx.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying oodocx.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying oodocx.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/oodocx-0.1.0-py2.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing oodocx-0.1.0-py2.6.egg
removing '/usr/lib/python2.6/site-packages/oodocx-0.1.0-py2.6.egg' (and everything under it)
creating /usr/lib/python2.6/site-packages/oodocx-0.1.0-py2.6.egg
Extracting oodocx-0.1.0-py2.6.egg to /usr/lib/python2.6/site-packages
SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/oodocx-0.1.0-py2.6.egg/oodocx/oodocx.py', 630, 34, " attributes={'val', 'subscript'})\n"))

oodocx 0.1.0 is already the active version in easy-install.pth

Installed /usr/lib/python2.6/site-packages/oodocx-0.1.0-py2.6.egg
Processing dependencies for oodocx==0.1.0
Finished processing dependencies for oodocx==0.1.0

Add Comment

Hi,

i know this library hasn't been active for a couple of years,
but i wonder if you could point me to a simple solution.

I found the function
add_comment(document, text, start, end, username, initials)

But it won't work properly. What kind of parameter do i have to pass to the function for 'start' ?

Thanks in advance

Markus

Applying styles to paragraphs

when creating an oodocx.paragraph it seems the style parameter isn't used any longer, so i tried adding it using pprops={'pstyle':{'val':'Heading1'}} but that doesn't seem to work either. The xml around a paragraph generated from oodocx vs python-docx vs. saved from word all look pretty much the same.

Is there a better way of applying a style?

[Critical] Duplicate code in oodocx.py

In file: oodocx.py

Function: paragraph

Issue:

  • Duplicate lines of code
  • Code from lines 818-850 was repeated again starting 852
  • With 'return' at line 850, code following it is unreachable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.