[scribus] Scripter 2 examples

a.l.e ale.comp_06 at xox.ch
Wed Dec 12 08:46:26 UTC 2012


On 12/11/12 8:15 PM, Gregory Pittman wrote:
> On 12/11/2012 03:33 AM, a.l.e wrote:
>> hi greg,
>>> A while ago I was trying to find a way to load CSV files with Scripter,
>>> but this doesn't seem possible either.
>> whaaaat? :-)
>>
>> just use python to load a csv in a list... then you can loop through 
>> it as you want.
>> should be almost trivial to do... i guess that by googling "python 
>> csv" you should be able to find everything you need to get started 
>> (and finished :-)
>>
> and so I did.
> I'll post on the wiki when I get a chance, for others reference.
> One interesting thing probably relates to a discuss vlada and I were 
> having on #scribus about the infamous No Style -- if you insertText, 
> then setStyle, the first line does not get the style you set. If you 
> look in Story Editor, it's labeled as No Style.
> The solution was to setStyle, then insertText, in which case the first 
> line is still No Style, but what's actually there is the correct one.
>

for those reading this archives and are not yet python programmers, the 
relevant part is:


import csv

csvfiledata = scribus.fileDialog('CSV file', 'CSV files(*.csv)')
with open(csvfiledata, 'rb') as csvfile:
     census = csv.reader(csvfile)
     for row in census:
         scribus.insertText('\t'.join(row) + '\n', -1, textbox)



which lets you choose a .csv file and inserts the text as tab separated rows into the currently selected text frame.

of course you can do what you want with the "columns" and insert the fields in "row" in different frames, and ignore some of them.

thanks greg for sharing!
a.l.e

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scribus.net/pipermail/scribus/attachments/20121212/379b6bd3/attachment.html>


More information about the scribus mailing list