Thread: how to view .ods as text?

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    56

    how to view .ods as text?

    Hello,

    I am trying to open an open office calc .ods file and view it as text. I want to be able to add new data to this file. When I try to open a test.ods file I am getting all kinds of gibberish. I believe .ods uses xml. If I can view the xml code in the file then I can write a program to insert new data into the .ods file at specified areas. Am I correct in assuming that opening a .ods file should look similar to the source of a web page?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    According to the ODF wiki page, the file format can be plain XML, or it can be ZIP. Since your test file appears to be gibberish, I would assume that it's using the ZIP format.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    56
    Thanks for the info. This is from the .odf wiki page.
    A basic OpenDocument file consists of an XML document that has <document> as its root element. OpenDocument files can also take the format of a ZIP compressed archive containing a number of files and directories; these can contain binary content and benefit from ZIP's lossless compression to reduce file size. OpenDocument benefits from separation of concerns by separating the content, styles, metadata and application settings into four separate XML files.
    Any ideas how to uncompress the file? Or is there a way that I can view the source in the Open Office Calc program?
    Last edited by CornedBee; 07-23-2009 at 06:45 AM. Reason: Code instead of Quote

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Any zip archive program should be able to decompress it. I would use 7-ZIP on Windows, or unzip on Linux.

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    56
    Thanks,

    I was able to unzip the file by right clicking the file and selecting extract here. However, I don't have anything that says compress here to compress the file when done. I guess I'll find a zip program to do that.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If you're on windows, 7-ZIP or WinZIP or WinRAR should be able to re-compress the data for you.

    Just out of curiosity -- why do you want to add data to a .ods file? It seems like an annoying thing to do by hand, and if you're planning on manipulating this data with a program, then wouldn't it be easier to use a different format . . . ?

    FWIW, there are command-line programs to convert between OpenOffice formats and other formats. I imagine they'd be able to run in Windows with a little tweaking.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    56
    Just out of curiosity -- why do you want to add data to a .ods file? It seems like an annoying thing to do by hand, and if you're planning on manipulating this data with a program, then wouldn't it be easier to use a different format . . . ?
    I want to be able to add data from a banking statement to an open office spread sheet to balance my account. I would like to write a C++ program to handle this. Is there another format that I can convert .ods to to make it easier to work with than xml? I would then convert it back to .ods when finished adding data. What would be the best way to do this? BTW, this would have to be done in linux.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by swappo View Post
    I want to be able to add data from a banking statement to an open office spread sheet to balance my account. I would like to write a C++ program to handle this. Is there another format that I can convert .ods to to make it easier to work with than xml? I would then convert it back to .ods when finished adding data. What would be the best way to do this? BTW, this would have to be done in linux.
    What's wrong with good old comma-separated (CSV)? (Edit: Naturally, I'm assuming you can just save your OpenOffice spreadsheet in CSV from OpenOffice.)

  9. #9
    Registered User
    Join Date
    Nov 2008
    Posts
    56
    What's wrong with good old comma-separated (CSV)? (Edit: Naturally, I'm assuming you can just save your OpenOffice spreadsheet in CSV from OpenOffice.)
    I just came to that conclusion myself. I can save the .ods as a .csv, but it would be even better if I could convert it from .ods to .csv in my program, append the data to the .csv and convert it back to .ods. However, I don't know how to convert the files in my program. I'm not even sure where to start to figure out how to convert files.

  10. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    You'll need to write a XML parser, or use an existing library, then use it to parse the ODS, and convert it to csv again from your internal format. There's no magical ods_to_csv() function. In short, forget about it, unless you have too much time on your hands. Why not just save it as csv?

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Have you considered writing the spreadsheet so that it fetches the values from a data source you define, and you simply modify the data source in your program? OpenOffice's formula language has the DDE function, which you might be able to use to import an external CSV file. If that doesn't work, you could still write a macro that imports the CSV file and updates the cells with it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting Edit Control Text
    By yoonkwun in forum Windows Programming
    Replies: 2
    Last Post: 07-12-2009, 08:48 AM
  2. Text adventure engine idea. thoughts?
    By suzakugaiden in forum Game Programming
    Replies: 16
    Last Post: 01-15-2006, 05:13 AM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM