How can one create a WikiText table from a copied CSV block, such as data pasted from an Excel sheet?
One can create an inputbox and then process the input by replacing the csv delimiters like comma or tab into pipe and then copy the result to clipboard. Below is a small UI that help to create a wikitext table from csv block. It accepts both tab
and comma
as delimiter.
Code
\procedure convert-csv()
<!-- create the setting row -->
CSV delimiter:
<$tiddler tiddler="$:/temp/convertxls">
<$radio field=delimiter value="tab" default="tab"> tab</$radio>
<$radio field=delimiter value="comma" default="tab"> comma</$radio>
</$tiddler> |
<$checkbox tiddler="$:/temp/convertxls" field="header" checked="yes" unchecked="no" default="no"> Has header?</$checkbox><br/>
<!--Create the input textbox -->
<$macrocall $name="copy-to-clipboard-above-right" src=<<output>> />
<$edit-text tiddler="$:/temp/convertxls" tag=textarea class="tc-max-width"/>
<!-- Preview output checkbox-->
<$checkbox tiddler="$:/temp/convertxls" field="preview" checked="open" unchecked="closed" default="closed"> Prview?</$checkbox>
<!--Define required variables-->
<$let
newline={{{ [charcode[10]] }}}
th= {{{ [<newline>addprefix[h]] }}}
tab= {{{ [charcode[9]] }}}
delim= {{{ [[$:/temp/convertxls]get[delimiter]match[comma]then[,]else<tab>] }}}
header= {{{ [[$:/temp/convertxls]get[header]match[yes]else[no]] }}}
input= {{$:/temp/convertxls}}
output= {{{ [<input>split<newline>!is[blank]search-replace:g:<delim>,[|]addprefix[|]addsuffix[|]join<newline>] }}}
output= {{{ [<header>match[yes]]:then[<output>search-replace<newline>,<th>]:else[<output>] }}}} >
<!-- Preview output-->
<%if [[$:/temp/convertxls]get[preview]match[open]] %>
<$transclude $variable="output" $mode="block"/>
<%endif%>
</$let>
\end
<!-- Example-->
<<convert-csv>>
To give a try:
- Download Table from CSV.json (1.6 KB)
- Go to https://tiddlywiki.com
- Drag and drop the downloaded code into into https://tiddlywiki.com
- Paste a chunk of data from Excel, Google Sheet or a CSV file
- Click on copy to clipboard and paste the result in any tiddler you like
- You may click on preview and see the result before use
Screencast
References
- Shiraz 2.9.7 β create stylish contents in Tiddlywiki
- Is there a tool to create a table by inserting values either as a block copied from excel or colums by column - Discussion - Talk TW
- tb5 β Welcome
- Special thanks to @stobot Is there a tool to create a table by inserting values either as a block copied from excel or colums by column - #3 by stobot