Tabulate

Summary: Handles tab-delimited tables so you can cut and paste to and from spreadsheet applications
Version: 2008-09-08
Prerequisites: PmWiki 2.2.0-beta series, untested on 2.1.27 and earlier
Status: beta
Maintainer: EemeliAro
Categories: Editing Tables

Questions answered by this recipe

  • How can I cut and paste table data between PmWiki and a spreadsheet application?

Description

Tabulate lets PmWiki handle tab-delimited data as tables. As this is the format that is used when you copy cells to a text field from MS Excel, OpenOffice Calc or most other spreadsheet applications, you can use Tabulate to easily import or maintain data from external applications.

Tabulate also provides for a simple way to manage the appearance of tables in PmWiki outside the data itself.

To install this recipe:

  • download tabulate.phpΔ to your cookbook directory
  • add the following line to your configuration file:
    include_once("$FarmD/cookbook/tabulate.php");

What it does

Tabulate identifies a tab-delimited table from the tab character itself, which otherwise doesn't often appear inside wiki markup -- pressing tab in the edit box will in most cases move the focus to the edit summary box. Once it finds a tab character, it builds a table from that and subsequent rows of text until it reaches a row that doesn't have a tab character.

Markup

Tables themselves are recognised from their inherent tab characters, but to manage their appearance you can use the following optional directive:

(:tab-table tgt=# all=style row#=style col#=style etc...:)

All parameters are optional, # indicates a number

tgt= Which table to apply these settings to; for example use tgt=2 to refer to the page's second table. By default increments on each call.
all=, row#=, col#= Which cells to apply the following style to.
style the style to apply, in a shorthand: cell styling values surrounded by text formatting. Missing left or right part of text formatting is copied from the other side. Valid styling values include the following, in any order:
##px and ##% — cell width
#abcdef — RGB background colors (# here is the # sign itself)
left|center|right|justify — horizontal alignment
top|middle|bottom|baseline — vertical alignment
The text formatting to apply should surround the above string, for example "{+80px #00ff00 right+}" indicates inserted text, cell width=80px, bgcolor=#00ff00, align=right. Double quotes are required to account for the white space; note that single quotes can't be used due to their common use indicating for example '''bold''' text.
etc... Any other formatting commands are passed directly to the PmWiki Table Directives handler to apply as formatting to the (:table:) directive.

Example

If the extension were enabled, this markup would produce the subsequent table:

(:tab-table col2=''@@100px@@'' row1="'''baseline #cccc00 center'''" width=80% border=1 rules=cols:)
blah3 	blah1 	blah2 	
blah3 bob 	blah1 	blah2 	
blah3|bing 	blah1 	blah2 	
blahz 	blahx 	blahy 	
blah3 	blah1 	blah2 	blah1 
blah3 blah1 blah2
blah3 bob blah1 blah2
blah3|bing blah1 blah2
blahz blahx blahy
blah3 blah1 blah2 blah1

Configuration

The following variables may be set in your config.php file to configure the way Tabulate works. Shown values are the defaults

$TabMinRows = 2; and $TabMinRows = 2;
The minimum size of the table for Tabulate to render it as such. Prevents incidental tab signs from producing tables
$TabZeroIndexing = FALSE;
Set to TRUE to have indices in (:tab-table:) start from 0 instead of 1.

Notes

It would appear that great minds think alike, and that Peter Bowers has implemented something rather similar to this in his Cookbook.Text2Tbl recipe.

This is very much a work in progress, and some bits that mostly work aren't included here yet, such as support for CSV data.

Release Notes

See Also

Contributors

Comments

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.