Hi,

Maybe it exists already, but I made a simple MATLAB script to convert a 
spreadsheet to tiddlers in .tid format (so one can just drag and drop them 
to a wiki). The top row in the spreadsheet should be field names, where one 
cell needs to contain "title" and another "text". If standard fields are 
not provided (created, type...), MATLAB will create and populate them. 
There is no filtering of field values, so I guess one might run into 
trubble if one is using exotic characters.

I know MATLAB is quite expensive, so maybe someone knows if similar tools 
(or maybe not-plugin scripts in general?) have been created in python or 
c++ etc?


Best,
Anders

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/4770da37-6946-40c7-a64e-a559313b79d1%40googlegroups.com.
clear all, clc

%
% Simple script to convert spreadsheet to tiddlers (.tid)
% The first row in the spreadsheet should be fieldnames. One column has to
% have the header "title" and another "text".
% The filenames will be spreadsheet_1.tid, spreadsheet_2.tid, ...
%

%% Configuration
myName = 'AHJ'; % will use this if creator or modifier is empty in spreadsheet
filename = uigetfile('*.xls;*.xlsx');
if ~filename
   error('A file has to be chosen') 
end

requiredColumns = {'title','text'};

%% Import data
data = readtable(filename);

%% Add missing standard fields
headers = data.Properties.VariableNames;
for i = 1:length(requiredColumns)
    if ~sum(ismember(headers,requiredColumns{i}))
        errStr = ['The spreadsheet needs a column with header "' requiredColumns{i} '"'];
        error(errStr)
    end
end
if ~sum(ismember(headers,'created'))
    for i = 1:size(data,1)
        data.created{i} = {datestr(now,'yyyymmddHHMMSSFFF')};
    end
end
if ~sum(ismember(headers,'creator'))
    for i = 1:size(data,1)
        data.created{i} = {myName};
    end
end
if ~sum(ismember(headers,'modified'))
    for i = 1:size(data,1)
        data.modified{i} = {datestr(now,'yyyymmddHHMMSSFFF')};
    end
end
if ~sum(ismember(headers,'modifier'))
    for i = 1:size(data,1)
        data.modifier{i} = {myName};
    end
end
if ~sum(ismember(headers,'type'))
    for i = 1:size(data,1)
        data.type{i} = {'text/vnd.tiddlywiki'};
    end
end

%% Save tiddlers
for i = 1:size(data,1)
    tiddlerFilename = ['spreadheet_' num2str(i)];
    fid = fopen([tiddlerFilename '.tid'],'w');
    for j = 1:length(headers)
        if ~strcmp(headers{j},'text')
            if iscell(data{i,j})
                fprintf(fid,'%s: %s\n',headers{j},data{i,j}{1});
            else
                fprintf(fid,'%s: %s\n',headers{j},num2str(data{i,j}));
            end
        else
            textID = j;
        end
    end
    fprintf(fid,'\n%s',data.text{i});
    fclose(fid);
end

Reply via email to