Convert spreadsheet cells into TW tables

569 views
Skip to first unread message

stevesuny

unread,
Dec 9, 2015, 8:14:58 PM12/9/15
to TiddlyWiki
Hello, folks.

In a rather old TWClassic, I found this function that converted pasted cells from spreadsheet (either excel or google sheets) into a TW Table.

I was wondering if anyone has code that works in TW5? (I seem to have pasted the source into my old tiddler, but that wiki seems to be gone...).

Thanks in advance for any help!

//steve.

----------------
(code snipped found in old tiddlywiki)

<html>
    <p align="center">
        <textarea id="xclToTw" rows="10" cols="60"></textarea><br />
        <button onclick="(function(){var ta=document.getElementById('xclToTw'); displayMessage('original: ' + ta.value); ta.value=ta.value.replace(/^|$|\t/gm, '|');})();" > Translate</button>
    </p>
</html>
!!! Usage
This function will insert {{{|}}} at the beginning and end of each line, and in between each column of your spreadsheet data. To use,
# Copy spreadsheet rows/columns.
# Paste in box above. Click Translate.
# Select and copy contents of box above.
# Paste into new tiddler and name the new tiddler.
#Save.

Hint: adding an {{{h}}} to the end of the first row will make your table sortable.

[[Source|http://oldwiki.tiddlywiki.org/wiki/How_To/Converting_Excel_Spreadsheets_to_TiddlyWiki_Tables]]

Sergey Shishkin

unread,
Aug 27, 2016, 5:33:47 AM8/27/16
to TiddlyWiki
For all TW5 as well?


четверг, 10 декабря 2015 г., 2:14:58 UTC+1 пользователь stevesuny написал:

Tobias Beer

unread,
Aug 27, 2016, 11:37:22 AM8/27/16
to TiddlyWiki
Hi Steve,

long time no peep from me.

Here's a quick shot for your converter (also see attachment):

/*\
title: $:/plugins/tobibeer/convertable.js
type: application/javascript
module-type: widget

A widget to convert a pasted excel or google spreadsheet to a tiddlywiki table.

\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

var Widget = require("$:/core/modules/widgets/widget.js").widget;

var ConvertableWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};

ConvertableWidget.prototype = new Widget();

ConvertableWidget.prototype.render = function(parent,nextSibling) {
this.parentDomNode = parent;
this.computeAttributes();
var textNode = this.document.createElement("textarea"),
buttonNode = this.document.createElement("button");
textNode.style.width = "100%";
buttonNode.style.clear = "left";
buttonNode.innerHTML="Convert to Wikitext";
buttonNode.addEventListener("click",function (event) {
textNode.value = textNode.value.replace(/^|$|\t/gm, '|');
});
textNode.value = this.getAttribute("text") || "";
this.domNodes.push(textNode);
parent.insertBefore(textNode,nextSibling);
this.domNodes.push(buttonNode);
parent.insertBefore(buttonNode,nextSibling);
};

ConvertableWidget.prototype.refresh = function(changedTiddlers) {
return false;
};

exports.convertable = ConvertableWidget;

})();

Will publish later.

Best wishes,

Tobias.
tobibeer-convertable.js.tid
Reply all
Reply to author
Forward
0 new messages