Hi,
As a volunteer on a Welsh Heritage Railway I undertake their Electrical
Equipment testing, for which I use a Megger PAT420. This device stores
data in 'sqlite', which using Python I can read and generate a number of
reports in 'csv' format. I now wish to collate asset data for various
locations, and as I use OpenOffice I want to generate an 'ods' document
with a 'sheet' for each location.
At present I generate a 'csv' file for each location, but as there are
20 locations this is a bit cumbersome. I use the 20 locations as a
method to make the handing of over 500 assets somewhat manageable.
I have found 'odswriter' on GitHub
https://github.com/mmulqueen/odswriter which appears to provide what I
want. However, I have come to a halt, due to the limitation of my knowledge.
I admit that I am confounded as to where/how to access this code.
I am using Python 3.6.4, in IDLE on a PC running windows.
I am using the following code as a starting point , Test_ODS#1.py
import datetime
import decimal
##import odswriter as ods
try:
from OdsWriter import odswriter as ods
except RuntimeError:
print("Error importing OdsWriter!")
# Single sheet mode
with ods.writer(open("test.ods","wb")) as odsfile:
odsfile.writerow(["String", "ABCDEF123456", "123456"])
# Lose the 2L below if you want to run this example code on
Python 3, Python 3 has no long type.
odsfile.writerow(["Float", 1, 123, 123.123,
decimal.Decimal("10.321")])
odsfile.writerow(["Date/DateTime", datetime.datetime.now(),
datetime.date(1989, 11, 9)])
odsfile.writerow(["Time",datetime.time(13,
37),datetime.time(16, 17, 18)])
odsfile.writerow(["Bool", True, False, True])
odsfile.writerow(["Formula", 1, 2, 3,
ods.Formula("IF(A1=2,B1,C1)")])
# Multiple sheet mode
with ods.writer(open("test-multi.ods","wb")) as odsfile:
bears = odsfile.new_sheet("Bears")
bears.writerow(["American Black Bear", "Asiatic Black Bear",
"Brown Bear", "Giant Panda", "Qinling Panda",
"Sloth Bear", "Sun Bear", "Polar Bear",
"Spectacled Bear"])
sloths = odsfile.new_sheet("Sloths")
sloths.writerow(["Pygmy Three-Toed Sloth", "Maned Sloth",
"Pale-Throated Sloth", "Brown-Throated Sloth",
"Linneaeus's Two-Twoed Sloth", "Hoffman's
Two-Toed Sloth"])
I get the following error
Traceback (most recent call last):
File "C:\Code\Python\ODS_Writer\Test_ODS#1.py", line 5, in <module>
from OdsWriter import odswriter as ods
File "C:\Code\Python\ODS_Writer\OdsWriter.py", line 7, in <module>
from . import ods_components
ImportError: attempted relative import with no known parent package
I have put the code from GitHub in various locations subject to my
limited knowledge of Python, but I have no idea what the following
extract means, and searching online on & off for two days has proved
unfruitful.
from __future__ import unicode_literals
from zipfile import ZipFile
import decimal
import datetime
from xml.dom.minidom import parseString
from . import ods_components
from .formula import Formula
I understand the use of 'import' and have written my own modules, but
from . import ods_components has me floored.
Thank you in advance for any help.
Dave
import datetime
import decimal
##import odswriter as ods
try:
from OdsWriter import odswriter as ods
except RuntimeError:
print("Error importing OdsWriter!")
# Single sheet mode
with ods.writer(open("test.ods","wb")) as odsfile:
odsfile.writerow(["String", "ABCDEF123456", "123456"])
# Lose the 2L below if you want to run this example code on Python 3,
Python 3 has no long type.
odsfile.writerow(["Float", 1, 123, 123.123, decimal.Decimal("10.321")])
odsfile.writerow(["Date/DateTime", datetime.datetime.now(),
datetime.date(1989, 11, 9)])
odsfile.writerow(["Time",datetime.time(13, 37),datetime.time(16, 17, 18)])
odsfile.writerow(["Bool", True, False, True])
odsfile.writerow(["Formula", 1, 2, 3, ods.Formula("IF(A1=2,B1,C1)")])
# Multiple sheet mode
with ods.writer(open("test-multi.ods","wb")) as odsfile:
bears = odsfile.new_sheet("Bears")
bears.writerow(["American Black Bear", "Asiatic Black Bear", "Brown Bear",
"Giant Panda", "Qinling Panda",
"Sloth Bear", "Sun Bear", "Polar Bear", "Spectacled Bear"])
sloths = odsfile.new_sheet("Sloths")
sloths.writerow(["Pygmy Three-Toed Sloth", "Maned Sloth", "Pale-Throated
Sloth", "Brown-Throated Sloth",
"Linneaeus's Two-Twoed Sloth", "Hoffman's Two-Toed Sloth"])
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor