« Introduction on testing pyUNO programs with doctests | Main | OOoEclipseIntegration release 1.0.3 »

Jun 26, 2006

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>

(Post originally written by Laurent Godard on the old Nuxeo blogs.)

Comments

About Us

We're the friendly employees of Nuxeo, a leading open source software vendor, which develops a complete Enterprise Content Management (ECM) software platform to help companies better produce, process, publish, archive, expose and find their information from digital assets to transactional documents.

» Follow us @nuxeo (Twitter)

» Connect on LinkedIn

» Visit Nuxeo.com

 

Customize & Configure
Nuxeo • Studio

Nuxeo • DM
Online Trial

Nuxeo • DM
Download

Nuxeo • DAM
Download

Nuxeo Connect support