How does Open Office compress its files?

前端 未结 4 1234
一向
一向 2020-12-29 10:45

I\'m trying to create an Open Office spreadsheet programmatically but for some reason simply compressing a folder with all the necessary files makes Open Office flag the fil

4条回答
  •  情话喂你
    2020-12-29 11:42

    The shell script worked for me, too :) I had problems zipping back up, after unzipping an odt file. Guess the manifest part was what's missing.

    The shell script above did not handle inline pictures/graphics, however, so I made some small adjustments which worked for me (also, the script had a bug in that END_HEREDOC was not on a dedicated line):

    #!/bin/sh
    
    # Convert folder (unzipped OpenDocument file) to OpenDocument file (odt, ods, etc.)
    # Usage: ./folder2od.sh "path/to/folder" "file.odt"
    
    cmdfolder=$(cd `dirname "$0"`; pwd -P)
    folder=$(cd `dirname "$2"`; pwd -P)
    file=$(basename "$2")
    absfile="$folder/$file"
    
    cd "$1"
    zip -0 -X "$file" "mimetype"
    
    list=$(cat <<'END_HEREDOC'
    meta.xml
    settings.xml
    content.xml
    Pictures/
    Thumbnails/
    Configurations2/
    styles.xml
    manifest.rdf
    META-INF/manifest.xml
    END_HEREDOC
    )
    
    for f in $list
    do
        zip -r "$absfile" "$f"
    done
    
    cd "$cmdfolder"
    

提交回复
热议问题