Enhancing OOo Calc CSV files recognition

CSV files are widely used for data import/export with spreadsheets

Openoffice.org Calc can obviously handle them but restrict the handling of CSV-like files to only some extenstions (csv, txt, tab). The default behaviour is to open unknown files in Writer as plain text ones.

Some months ago i gave the method for handling .dat files by default in OOo 1.1.x as CSV file [fr], so that they open directly in Calc.

Here is the update for OOo 2.x : the sipirit remains the same, the details slightly changed

Making the changes persistent


The filters definition in OOo 2.x are stored in /opt/openoffice.org2.0/share/registry/modules/org/openoffice/TypeDetection/Types
An xcu file is an xml file used by OOo for its configuration

In this directory, you'll find a lot of file dealing with OOo filters definition
The one concerned bu our CSV defibnition is fcfg_calc_types.xcu

Searching for csv string inside it, we will find this structure
    <node oor:name="calc_Text_txt_csv_StarCalc" oor:op="replace" >
<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
<prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>csv txt tab</value></prop>
<prop oor:name="MediaType"><value>text/plain</value></prop>
<prop oor:name="Preferred"><value>false</value></prop>
<prop oor:name="PreferredFilter"><value>Text - txt - csv (StarCalc)</value></prop>
<prop oor:name="UIName">
<value>Text - txt - csv (StarOffice Calc)</value>
</prop>
<prop oor:name="ClipboardFormat"/>
</node>

One can the notice that inside this calc_Text_txt_csv_StarCalc node, we find an Extensions property listing all the extension actually handled for csv files

So, the solution is only to append dat or zzz to this property
        <prop oor:name="Extensions"><value>csv txt tab dat zzz</value></prop>

Be carefull that this file is in the main OOo directory, not the user one, so you may need some writing rights on this file

Deploying the solution

Thanks to OOo configuration model and great package manager, one can deploy this configuration easilly
Seeing OOo Configuration as layers (share > User > Packages), we can then define a package taht the user will add using its Tools > Package manager
The modified configuration will me merged to the Configuration XML tree provided the adminsitrator has not finalized the node

This package is straightforward to create :
  • Create a myConf.xcu file taking the heading of fcfg_calc_types.xcu and reproducing the calc_Text_txt_csv_StarCalc node with the desired modification.
  • zip the file
  • you're ready

Here is the example that configures calc to open .dat aand .zzz file sby default once the pacakge installed

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE oor:component-data SYSTEM "../../../../component-update.dtd">
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:package="org.openoffice.TypeDetection" oor:name="Types">
<node oor:name="Types">
<node oor:name="calc_Text_txt_csv_StarCalc" oor:op="replace" >
<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
<prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>csv txt tab dat zzz</value></prop>
<prop oor:name="MediaType"><value>text/plain</value></prop>
<prop oor:name="Preferred"><value>false</value></prop>
<prop oor:name="PreferredFilter"><value>Text - txt - csv (StarCalc)</value></prop>
<prop oor:name="UIName">
<value>Text - txt - csv (StarOffice Calc)</value>
</prop>
<prop oor:name="ClipboardFormat"/>
</node>
</node>
</oor:component-data>

Important announcement: Join the Nuxeo team and contribute to the Nuxeo project! We have open positions in France and the UK for open source Java EE developers and sales engineers, both junior and senior.

Like this post? Share it:

Posted by Laurent Godard @ 02/24/2006 11:30 AM. - Categories: openoffice -  12 comments

Nuxeo Bloggers: Log in!
Nuxeo - Indesko - Nuxeo 5 Project
All content is copyrighted by their author.
CPSSkins is Copyright © 2003-2006 by Jean-Marc Orliaguet. | CPS is Copyright © 2002-2006 by Nuxeo SAS.