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.


enter image description here

$ 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:

enter image description here


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:tab‌​le-cell office:value-type="string" calcext:value-type="string"><text:p>b3b3b3</text:p></table:table-cell></table:ta‌​ble-row>" $ sed "s#$from#$to$from#" content.xml 

the "#" seperator. if have "#" in text use else.


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User

sql server - "Configuration file does not exist", Event ID 274 - Super User