Coder Social home page Coder Social logo

t0ha / ezodf Goto Github PK

View Code? Open in Web Editor NEW
61.0 12.0 24.0 4.88 MB

ezodf is a Python package to create new or open existing OpenDocument (ODF) files to extract, add, modify or delete document data, forked from dead project https://bitbucket.org/mozman/ezodf

License: Other

Shell 0.03% Python 99.97%

ezodf's Introduction

EzODF.py

https://travis-ci.org/T0ha/ezodf.svg?branch=master

If you want to support us

https://api.flattr.com/button/flattr-badge-large.png

Abstract

ezodf is a Python package to create new or open existing OpenDocument (ODF) files to extract, add, modify or delete document data.

a simple example:

from ezodf import newdoc, Paragraph, Heading, Sheet

odt = newdoc(doctype='odt', filename='text.odt')
odt.body += Heading("Chapter 1")
odt.body += Paragraph("This is a paragraph.")
odt.save()

ods = newdoc(doctype='ods', filename='spreadsheet.ods')
sheet = Sheet('SHEET', size=(10, 10))
ods.sheets += sheet
sheet['A1'].set_value("cell with text")
sheet['B2'].set_value(3.141592)
sheet['C3'].set_value(100, currency='USD')
sheet['D4'].formula = "of:=SUM([.B2];[.C3])"
pi = sheet[1, 1].value
ods.save()

for more examples see: /examples folder

Dependencies

For CPython 2.6 compatibility:

The target platform is CPython 2.7 and CPython 3.2+, work on compability with CPython 2.6 is in progress.

Installation

with pip:

pip install ezodf

or from source:

python setup.py install

Documentation

http://packages.python.org/ezodf

send feedback to [email protected]

ezodf can be found on GitHub at:

https://github.com/T0ha/ezodf

ezodf's People

Contributors

chfw avatar davekr avatar davidovitch avatar graingert avatar kenchou avatar t0ha avatar

Stargazers

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

Watchers

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

ezodf's Issues

ODS sheets: Wrong results with sparse tables

At least the following function return wrong results when I create a sheet that contains data only in the cells (for example) G1, Z1, CD1, CE1:
sheet.ncols()
sheet["CD1"].value
and many more.
It seems as if the table:number-columns-repeated attribute is simply ignored.

newdoc without doctype

See this from your docu

# create a new text document
doc = ezodf.newdoc(doctype='odt', filename='text.odt')
# or open an existing text document
doc = ezodf.opendoc('text.odt')

opendoc doesn't need a doctype because it recoginize it from the filename or the filecontent.
newdoc shouldn't need doctype, too. Because it can recoginize the needed type from the filename suffix.

doctype should be optional (per default None)

pyexcel-ezodf, a fork of this reprository will take the maintenance task

Due to the long deplay of #18, I have decided to publish the my version of ezodf out to pypi. Namespace and other functionality are backward compatible.

Due to my limited knowledge of open document specs, anyone interested join the maintainer team will be welcome to join.

When @T0ha will be coming back to continue the leadership, I am happy to push the changes back.

pyexcel#2

Table in text document

Is it possible to add a table in a text document ? I don't find any information in the documentation

ODS: Add rows and columns automatically

Hi, this is more a nice to have enhancement request than an issue.

Is it possible/easy for spreadsheets to create columns and rows automatically when adding a value instead of raising an index out of range error?

For example:

sheet = ezodf.Table('Sheet')
print(sheet.nrows(), sheet. ncols())
#0 0
sheet[10, 20].set_value('A value')
print(sheet.nrows(), sheet. ncols())
#10 20

Cheers

Improve README.md with project status

Dear folks,

could you please update the README with a section describing your project organisation and the current status.

I assume this is a one-person-freetime-project. But people need to know.

And the question is if that project is still maintained. The question is if new contributions (e.g. PRs) will be handled.

Or is the project still orphaned?

how to assign styles to columns in a table in a odt file ?

Hello,
I would like to add a table in a odt file with columns with precise dimensions using existing styles in this file as already done for an existing table.

<text:p text:style-name="P21"/><table:table table:name="Exigence" table:style-name="Exigence"><table:table-column table:style-name="Exigence.A"/><table:table-column table:style-name="Exigence.B"/><table:table-column table:style-name="Exigence.C"/><table:table-column table:style-name="Exigence.D

I can assign a style to a cell in a table creates :

table = ezodf.Table(size=(1, 4))
table.set_cell(pos=(0,0),cell=ezodf.Cell(style_name="Exigence.A1"))

So how can I assign a style in the columns?

Add support for Flat XML OpenDocumentFormat files

When I try to open a .odt file, I get:

>>> textproc = ezodf.opendoc("foo.fodt")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/ezodf/document.py", line 54, in opendoc
    mime_type = __detect_mime_type(fm)
  File "/usr/local/lib/python2.7/dist-packages/ezodf/document.py", line 69, in __detect_mime_type
    mime_type = MIMETYPES[ext]
KeyError: '.fodt'

Same for .ods files

Support for .fods, .fodt, etc. files

The .fxxx variants are the same as the standard variants, but not compressed. Thus, they play nicely with GitHub. See LibreOffice for reference... It should be easy to add support for these files, since they are the "same" just remove the decompression step.

support = operator

This is a wish.

Currently you have to do
sheet['B2'].set_value(3.141592)

IMO it would be more "natural" if it could be done like this, too:
sheet['B2'] = 3.141592

How to use nested list?

Hello,I have a trouble to make a nested list.
The code is :
temp = ezodf.newdoc("odt","")
a = ezodf.List()
b = ezodf.List()
a.append(ezodf.ListItem('1'))
b.append(ezodf.ListItem('2'))
a += b
temp.saveas("temp.odt")

And i load the file(temp.odt) with Openoffice4.1.2 , (python3.4 ,win10 64bit environment)
Openoffice only shows the "a" list in the document, i feel frustrated about the situation.
Did i misunderstand something about the module or the function?
Please let me know.

At the end, thanks for the efforts what you devoted.It saves my time.

Useless error message if wrong file path is given

If one calls opendoc() with a non-existing path:

opened = ezodf.opendoc("/home/user/path/that/does/not/exist.ods")

This is what one gets:

Traceback (most recent call last):
  File "/home/yyyyyyy/loop_list_test.py", line 9, in <module>
    adapted_ods = ezodf.opendoc(adapted)
  File "/usr/local/lib/python2.7/dist-packages/ezodf/document.py", line 54, in opendoc
    mime_type = __detect_mime_type(fm)
  File "/usr/local/lib/python2.7/dist-packages/ezodf/document.py", line 69, in __detect_mime_type
    mime_type = MIMETYPES[ext]
KeyError: '.ods'

It's just a suggestion but a simple check if that file actually exists and a more meaningful error message would be very helpful here.

__detect_mime_type is broken

__detect_mime_type has a bug in line 66/67:

ezodf/ezodf/document.py

Lines 56 to 68 in f9675c1

def __detect_mime_type(file_manager):
mime_type = file_manager.get_text('mimetype')
if mime_type is not None:
return mime_type
# Fall-through to next mechanism
entry = file_manager.manifest.find('/')
if entry is not None:
mime_type = entry.get(CN('manifest:media-type'))
else:
# use file ext name
ext = os.path.splitext(file_manager.zipname)[1]
mime_type = MIMETYPES[ext]
return mime_type

os.path.splitext returns the file extension with a leading dot (e. g. .ods). But MIMETYPES only contains the extensions without the dot:

'ots': "application/vnd.oasis.opendocument.spreadsheet-template",

Importing requirements in setup

This library requires the lxml package, but there are imports in setup.py file causing the requirement to import before setup can be run and lxml can be installed.

    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/dave/venvs/individualcar/build/ezodf/setup.py", line 14, in <module>
        from ezodf import VERSION
      File "ezodf/__init__.py", line 27, in <module>
        from .document import opendoc, newdoc
      File "ezodf/document.py", line 16, in <module>
        from .xmlns import subelement, CN, etree, wrap, ALL_NSMAP, fake_element
      File "ezodf/xmlns.py", line 10, in <module>
        from lxml import etree
    ImportError: No module named lxml

Line break in ods

I tried to add line breaks in spreadsheet like CTRL+ENTER. Is there a way to perform this?

Best regards

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.