Summary: Talk page for ConvertTABLE.
Maintainer: Brooks Kelley
Users: (View? / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.


I had this same issue, but was using WinXP and SED for Windows. What's worse is, I'd only used SED once before and that was a few years ago, so forgive me if this isn't very elegant. Below is a .BAT file (you can also use .CMD as the extension). It expects a single parameter, a filename to process. The commands are a combination of SED and some DOS batch commands, so you must have SED loaded and running on the Windows path before this .BAT file will work.

The other caveat is that this process expects a "DOS CSV file" as saved by Excel. After a bit of flogging, I figured out that it was much simpler to start with a very simple format and then use some fairly simple SED commands to format. So, you can use Excel to open an HTML file, then isolate the data you want, and make sure you delete everything else on the spreadsheet you don't want, then do the "Save As..." and save the data as a DOS CSV file. This creates a very simple comma-delimited file.

At that point, just run the ConvertCSVtoPMWikiTABLE.bat program with the file name as the sole parameter. When it finishes, Notepad will open with the converted results, ready to be cut-n-pasted into PmWiki.

 if %1'==' goto err1
 goto start

 echo off
 echo ---------------------------
 echo ConvertCSVtoPMWikiTABLE.BAT
 echo ---------------------------
 echo '
 echo You must input the name of the CSV file as the one and only parameter, e.g.
 echo '
 echo '    ConvertCSVtoPMWikiTABLE ips.csv
 echo '
 echo This process assumes you have imported a table into Excel, then exported
 echo the rows/columns that you want as a MS-DOS CSV file.
 echo '
 echo '
 echo ' written by Robert Laird, 12/20/2005
 goto end


 rem -----3 steps to this SED pipe...
 rem -----  Step 1: replace all comma's with a comma plus a HTML hard space
 rem -----  Step 2: append (:cellnr:) to the beginning of each line
 rem -----  Step 3: replace all comma's with (:cell:)
 rem -----
 sed "s/,/&\ /g"  %1 | sed "s/^/(:cellnr:)/" | sed s/,/\n(:cell:)/g > temp1.csv 

 rem -----Add the table header
 echo (:table border=1 cellpadding=0:) > temp1hdr.txt
 copy temp1hdr.txt+temp1.csv temp2.csv

 rem -----Add the table end
 echo (:tableend:) > temp1ftr.txt
 copy temp2.csv+temp1ftr.txt temp3.csv

 rem -----Clean up
 del temp1.csv
 del temp2.csv

 rem -----Display the final CSV file for cut-n-paste into PmWiki
 notepad temp3.csv


Talk page for the ConvertTABLE recipe (users?).