LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > Michael Uplawski
User Name
Password

Notices


Rate this Entry

Text-mode spreadsheet viewer

Posted 08-29-2016 at 12:59 PM by Michael Uplawski
Updated 01-04-2024 at 01:17 AM by Michael Uplawski (It is ruby-filemagic!)

Edit 01/04/2024:
  • A new version of Viewworkbook is available on Rubygems.org (See Readme under “Documentation”.

Edit 01/30/2021:
  • The example-output is now a screenshot from a terminal window
  • Attached to this blog-entry, you find the man-page to viewworkbook as PDF (see sub-folder doc of the gem)


A little corniness

My favorite Office-Suite is SoftMaker Office. This is normally a closed source, commercial software package and I would not dare to expatiate on the merits of the SoftMaker Inc., if I weren't using their office programs for about 20 years and convinced of their superiority over all other commercial and free office-suites.

Put differently: they are more compatible with Microsoft® Office than the Microsoft® Office suite itself, in general faster than the competitors (maybe with the exception of Gnumeric), less buggy and more communicative. I remember a Sunday morning, when I posted a question on Usenet because of a printer incompatibility, when minutes afterwards the SoftMaker CEO responded and promised a fix; or years later, when a different fix was not only announced in the Web-Forum, but immediately produced and mailed to me ASAP and prior integration in the next release. I also remember two job-interviews, but mention this only for completeness.
Scripting
The Windows-versions come with a Basic derivate and can be accessed with any programming language for which exist OLE/COM interfaces, but for the Linux package, there is no scripting support.

Switching to the free Gnumeric spreadsheet program would have brought me Python support, which should in theory allow python programs to alter spreadsheet data via GObject introspection.
And the AbiWord text-processor, too, is free software!

I do not like LibreOffice, I never liked OpenOffice and I hate Basic. Let me assure you, that I have experience with all three and in the past had been able to master even complex scripting jobs with VB or VBA. However, I prefer scripting OLE with Ruby.
Prodigal Son
As the Python-support for Gnumeric (1.12.32 at this time) is not really working as needed, and as some of today's long-standing bug-reports on AbiWord (3.x probably) are authored by myself, I returned to SoftMaker just in time to benefit from the (gratuitous, closed source) FreeOffice-version that they give away, now.

Interestingly, the default file-types, created by the SoftMaker spreadsheet program (“PlanMaker”), are close cousins of the Microsoft® equivalents. Until recently this was PMD (a lot like XLS), nowadays it is PMDX which resembles (at least) XLSX.

With a little effort, you rearrange the letters and get XSL. And XLSX is XML, as is PMDX! Here is my scripting support, at last.., I thought. Yeah. Look it up: Microsoft OOXML. Oh. You did not really try. Try harder... Okay, let's forget XSL/FO. And I have not even mentioned the divergence of PMDX from the OOXML standard...

BUT I WANT TO SCRIPT SPREADSHEETS WITH RUBY!!
Dang“, says the search-engine. “Why didn't you say so?
Entrance: The Roo gem
Quote:
Roo implements read access for all common spreadsheet types. It can handle:

Excel 2007 - 2013 formats (xlsx, xlsm)
LibreOffice / OpenOffice.org formats (ods)
CSV
Excel 97, Excel 2002 XML, and Excel 2003 XML formats when using the roo-xls gem (xls, xml)
Google spreadsheets with read/write access when using roo-google
Who needs Google.

I may be projecting too far into the future when the missing write access for XLS and XLSX does not yet appear to be an insurmountable obstacle.
The SoftMaker program can import CSV and while doing so, discerns text from numbers. Even without the help of a Ruby-gem, I deem myself capable to write a CSV-file. Other cell-formats and styling will be lost, but for my uses, this is a minor problem.
First spreadsheet access with Roo
The above quoted section from the Roo documentation says more or less “read anything from any type of spreadsheet” and I made this my first project: A “workbook-viewer” for the supported file-types (plus the in-officially supported SoftMaker-formats). And to keep it simple, I wanted the viewer to work in text-mode in a terminal window.., as if drawing a table as pure text were “simple”. But I am a little dumb, that way.
Once again, the helpful Usenet-community provided ingenuous example code, which draws tables of arbitrary size and allocates values to the right cell-coordinates...

In the end, my own best contribution to the viewer-program is a shortcut menu that can easily be fit with actions and sub-menus, so that new functionality can quickly be integrated, should it become necessary.

The text mode workbook viewer is now available as a Ruby-Gem “viewworkbook”. Install it with the help of the gem utility:
Code:
user@machine:~$ sudo gem install viewworkbook
In addition to this gem, you need to install roo (gem install roo) and filemagic (gem install ruby-filemagic).

The latter is needed as a binding to the magic library. I use it to recognize the mime-type of spreadsheet files and to derive their presumed filename-extension, as the roo-gem needs this information. It gives me the opportunity to decoy roo into believing that a PMD file were XLS and a PMDX file XLSX. This works remarkably well. Here is the output from a command like
Code:
user@machine:/tmp$ viewworkbook.rb example.pmd


For a few days, I thought it would be a nice addition if spreadsheets could be piped-in to viewworkbook. This way, I could use it to display spreadsheets which come as email-attachments. As I use the Mutt email-client, I would not have to first save the attachment to a file, then run a graphical program, but could use a simple keyboard-shortcut to see the spreadsheet content right away. But I have still much to learn and this thread on LQ helped me understand why my idea with the pipe did never work: Cannot read from stdin after piping-in a file.
Attached Images
File Type: png viewworkbook_sc.png (2.6 KB, 13 views)
File Type: pdf viewworkbook.pdf (15.7 KB, 3 views)
Views 226 Comments 1
« Prev     Main     Next »
Total Comments 1

Comments

  1. Old Comment
    See Apache-Poi for a complete programming interface to most Microsoft® file-formats. Unfortunately, it is first of all a Java-library.
    Posted 10-08-2016 at 05:24 AM by Michael Uplawski Michael Uplawski is offline
 

  



All times are GMT -5. The time now is 08:57 PM.

Main Menu
Advertisement
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