LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-10-2011, 11:01 AM   #1
devdol
Member
 
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 68

Rep: Reputation: 17
Post [SOLVED] Export AutoCorrect Entries from LibreOffice to CSV


After having discovered AutoKey, I wanted make a subset of my numerous "AutoCorrect" entries (ACE) from inside LibreOffice available desktop-wide.
Unfortunately there is no easy way to export them into a flat file, and I did not find any solution yet. There is a macro to export "AutoText" entries, but they are a different class (to be triggered by pressing F3, not just by automatic replacement just while typing).

On Linux, AutoCorrect definitions are stored in files like
~/.libreoffice/3/user/autocorr/acor_*.dat, which are ZIP files (each one for a given language). They contain a file DocumentList.xml, which holds all ACE definitions as an xml tree structure.

As LibreOffice's Website does not yet have a place to share Macros, Snippets and so on, I take the liberty of placing a recipe here using python, for those who want to use, improve or extend it:

Code:
#-*- coding: utf-8 -*-
import os, sys, zipfile, xml.dom.minidom
##########################################################
# Script to export LibreOffice Auto Correct Entries
# into a flat file (e.g. to reuse some of them with autokey)
##########################################################
ACEfile='.libreoffice/3/user/autocorr/acor_de-DE.dat'    # This is a ZIP where LibreOffice stores its auto correct entries
ifname='DocumentList.xml'                                # Name of the file inside the ZIP archive that contains auto correct entries
ofname='AutoCorrectEntries.csv'                          # any desired output file name for the export
tagname= 'block-list:block'                              # (as in DocumentList.xml)
schema=['block-list:abbreviated-name','block-list:name'] # (as in DocumentList.xml)
default_encoding='UTF-8'                                 # (as in DocumentList.xml)
ofdelimiter=";"                                          # any desired delimiter for export
##########################################################

of = open(ofname,"w")
oACE = zipfile.ZipFile(os.path.join(os.path.expanduser("~"), ACEfile))
zif = oACE.open(ifname, "r") # access as read-only ZipExtFile object
doctree = xml.dom.minidom.parse(zif)  # Parse the input file as DOM (document object model, xml-tree) into memory
if doctree.encoding:
    encoding = doctree.encoding
else:
	encoding = default_encoding
for elem in doctree.getElementsByTagName(tagname):
	acEntry=[]
	for fieldname in schema:
		acEntry.append(elem.getAttribute(fieldname))
	of.write(ofdelimiter.join(acEntry).encode(encoding)+"\n")
of.close()     # Close output file
doctree.unlink # and deallocate DOM object
 
Old 03-11-2011, 01:45 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hello,

Thank you for sharing your solution. Off the Zero Reply List.

Kind regards,

Eric
 
  


Reply

Tags
autocomplete, csv, export, openoffice.org


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] can I export a laptop's partition as an external HD? potuz Linux - Software 4 10-29-2010 03:58 AM
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 09:15 PM
how to sort output at latest entries without disturbing the previous entries record nabmufti Programming 4 02-11-2008 11:36 PM
export redhat linux csv file to xls bbgtilak Linux - General 4 12-27-2006 07:53 AM
OpenOffice AutoCorrect DavidMcCann Linux - Software 2 11-10-2006 10:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration