Edit Libreoffice-Files from Command Line - Ask Ubuntu
i want add lines libreoffice calc table command line. have no idea how.
figured out how start libreoffice command line.
for example iam looking for: -the test.ods-file
before
name text hans bla christian blablub
i enter...
ubuntu> [a command -insert] alf|test -file=test.ods
so "alf" , "test" added next line in table.
-the test.ods-file
after:
name text hans bla christian blablub alf test
.ods
archive. need extract archive.
from documentation:
xml file structure
documents in opendocument file format stored compressed zip archives contain xml files. view these xml files, can open opendocument file unzip program. following files , directories contained within opendocument files:
- the text content of document located in content.xml.
so not simple
[a command -insert] alf|test -file=test.ods
since need insert xml parts.
$ cd ~/tmp/ $ unzip ../test.ods archive: test.ods extracting: mimetype extracting: thumbnails/thumbnail.png inflating: settings.xml inflating: content.xml inflating: meta.xml inflating: styles.xml inflating: manifest.rdf creating: configurations2/images/bitmaps/ creating: configurations2/toolpanel/ creating: configurations2/progressbar/ inflating: configurations2/accelerator/current.xml creating: configurations2/floater/ creating: configurations2/statusbar/ creating: configurations2/toolbar/ creating: configurations2/popupmenu/ creating: configurations2/menubar/ inflating: meta-inf/manifest.xml
when @ content.xml , want add new row below last 1 need add ...
<table:table-row table:style-name="ro1"> <table:table-cell office:value-type="string" calcext:value-type="string"><text:p>a2a2a2</text:p> </table:table-cell><table:table-cell office:value-type="string" calcext:value-type="string"> <text:p>b2b2b2</text:p> </table:table-cell></table:table-row>
before
<table:named-expressions/>
and zip files again (zip -r ../test2.ods .
directory files).
result:
to edit file command line used command. put example in ~/downloads , made tmp/ in there test. commands used this:
cd ~/downloads/tmp/ unzip ../test.ods sed 's#</table:table><table:named-expressions/>#<table:table-row table:style-name="ro1"><table:table-cell office:value-type="string" calcext:value-type="string"><text:p>a3a3a3</text:p></table:table-cell><table:table-cell office:value-type="string" calcext:value-type="string"><text:p>b3b3b3</text:p></table:table-cell></table:table-row>&#' content.xml > content2.xml mv content2.xml content.xml zip -r ../test2.ods .
all need replace text segments own.
newer version courtesy of terdon (it uses variables make better readable):
$ from="</table:table><table:named-expressions/>" $ to="<table:table-row table:style-name="ro1"><table:table-cell office:value-type="string" calcext:value-type="string"><text:p>a3a3a3</text:p></table:table-cell><table:table-cell office:value-type="string" calcext:value-type="string"><text:p>b3b3b3</text:p></table:table-cell></table:table-row>" $ sed "s#$from#$to$from#" content.xml
the "#" seperator. if have "#" in text use else.
Comments
Post a Comment