我正在使用 Scribus 为我的设备打印带有序列号的标签。有没有办法可以自动从文本文件(甚至是 Google 文档)读取我想要打印的序列号并将其插入到 Scribus 中?
想法如下:我在 Scribus 中定义字段,并从文本文件自动填充这些字段的值。
这可能吗?
答案1
我使用 python 来编辑该文件。
#!/usr/bin/python
# this script populates the scribus template for the SN of FuelSpy
# Olmo Mezger
import re # regular expression
import os.path #for os path operations
#config
myFile_Tempate = "SN_Template.sla"
myFile_Out = "SN_Tier_01.sla"
i_start = 1
i_number = 27*7
# check if file exists
if os.path.isfile(myFile_Out):
print 'aborting, output file exist and I dont want to overwrite it. Delete it manually if you want to continue',
#quit()
else:
print 'continue'
#
f_in = open(myFile_Tempate, 'r')
f_out =open(myFile_Out, 'w')
# loop
i = i_start
for line in f_in:
#print line
myString = line
if myString.find('%') == -1: # it does not have %
f_out.write(myString)
else:
myNumber = '%0*d' % (4, i)
myNewString = myString.replace('%',myNumber)
#print myNewString
f_out.write(myNewString)
print i
i = i+1
f_in.close()
f_out.close()
print "done"
答案2
另外还有 Scribus Generator,它可以从 CSV 文件获取数据并替换 Scribus 文档中的变量。请参阅http://wiki.scribus.net/canvas/Scribus_Generator
答案3
读取串行.ps1:
$xmldata=[xml](gc 'C:\1\menu_template1.sla')
($xmldata.SelectNodes("/SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT[@ANNAME='Text1232']/ITEXT/@CH")).itemof(0)."#text"
输出:
Tested number
写入串行.ps1:
$xmldata=[xml](gc 'C:\1\menu_template1.sla')
$xmldata.SelectNodes("/SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT[@ANNAME='Text1232']/ITEXT") | Set-Variable xmlnode
$xmlnode.SetAttribute("CH", "New Serial")
$xmldata.Save('C:\1\menu_template1.sla')