hopia
hopia

Reputation: 5006

How can I convert an Excel table into Trac Wiki Table format?

I've seen copy & paste converters to MediaWiki or HTML format. But I could not find one that converts to the Trac Wiki format (WikiFormattting) which uses pipes to separate cells, such as:

||Cell 1||Cell 2||Cell 3|| 
||Cell 4||Cell 5||Cell 6||

Upvotes: 4

Views: 2959

Answers (3)

thdoan
thdoan

Reputation: 19097

My port of Shan Carter's Mr. Data Converter now supports Wiki in the format you specified. You can copy & paste directly from Excel or from a CSV file.

http://thdoan.github.io/mr-data-converter/

UPDATE: I've added Trac-specific formatting under the "Trac" option.

Upvotes: 1

cjbarth
cjbarth

Reputation: 4479

I made a jsFiddle to do just this, just put your CSV test in the HTML box and run the script. The content that you would paste into a TracWiki page would be in the Result box then.

In case something happens to the jsFiddle, here is the JavaScript I used (I probably didn't need to use jQuery, but it was faster for me then to have to think of the non-jQuery way to do it:

var csv = $('body').html().trim();
csv = csv.replace(/,/g, "||");
csv = csv.replace(/$/gm, "||<br />");
csv = csv.replace(/^/gm, "||");
// set to false if you don't want empty cells
if (true) {
    while (csv.indexOf("||||") > -1) {
        csv = csv.replace(/\|\|\|\|/g, "|| ||");
    }
}
$('body').html(csv);

Upvotes: 1

user468649
user468649

Reputation: 76

You could save your excel sheet as a CSV file. Then from a command prompt (assuming you are running Windows XP or newer) type this command:

for /f "tokens=1,2,3 delims=," %a in (mycsvfile.csv) do ((echo ^|^|%a^|^|%b^|^|%c^|^|) >> mywikifile.txt)

The number of tokens depends on how many columns you have. You could do up to 26 columns this way in a single pass by increasing the number of tokens and adding the corresponding number of variable names %d, %e, etc.

Upvotes: 6

Related Questions