Help importing catalog data from a text file (import from csv, tab-delimited, excel)
hi all-
i've been banging head on 1 couple of days now. seems that's been done before , shouldn't difficult, i've found little if in adobe's documentation (and many many google searchs).
i have 100-page retail catalog 1000 products in indesign cs5. have excel spreadsheet year's product names, prices, , updated descriptions. normally, go through one-by-one , cut , paste. year thought i'd try bypass step. there plugins this, they're not cheap, , we're not big. upgrading cs5 cs2 big investment in , of itself.
here's example of data (i'm using pipe character delimiter):
28392779|3627|super top|get handle on fun. wind cord around spindle , let 'er rip.|6½” long
|$10
so... standard excel file exported delimited format (i use openoffice export avoid problem of excel quoting damn near *everything*). in indesign file have text pane each name, description , price grouped together. group has script label of product id , each field within group labeled accordingly (name, id, description). so, group: 3627, item: description (or name or price).
pseudo code:
open file
parse data array
step through indesign file group group
check group script label, in array, assign values fields
easy right?
i'm not new javascript, it's not strongest language. effort i've had problems simple syntax identifying groups label. anyway, here's code (it ain't pretty way run step through data array line line , step through entire indesign file each data line. and, yes, takes hour run -- *does* run):
var mydocument = app.activedocument;
var datafile = file("/users/reddfoxx/desktop/2010sept8catdesc.csv");
datafile.open("r");
var data = datafile.read()
data = data.split("\n");
// data array 0 indexed
// field 0 internal id
// field 1 product id
// field 2 product name
// field 3 description
// field 4 dimensions
// field 5 price
for(x = 0; x < data.length; x++){
data[x] = data[x].split("|");
for(var z = 0; z < mydocument.groups.count(); z++) {
if(mydocument.groups.item(z).label == data[x][1]) {
mygroup = mydocument.groups.item(z);
for(var y = 0; y < mygroup.textframes.count(); y++) {
if(mygroup.textframes.item(y).label == "name")
{
mygroup.textframes.item(y).contents = data[x][2];}
if(mygroup.textframes.item(y).label == "description")
{
mygroup.textframes.item(y).contents = data[x][3];
}
if(mygroup.textframes.item(y).label == "dimensions")
{
mygroup.textframes.item(y).contents = data[x][4];
}
if(mygroup.textframes.item(y).label == "price")
{
mygroup.textframes.item(y).contents = data[x][5];
}
}
}
}
}
for who's unfamiliar groups , scripting, unfortunately, can't address text frames inside group without using group. @ least, that's understand.
any appreciated. figuring out how address particular group in document, don't have step through entire file , compare every item vast improvement.
thanks in advance.
-redd
hey!
you have nice little problem here
well, unfortunately, indesign cs5 little heavy on script labels, there changes , stuff. in cs4 , before, when call pageitem.item(myitemname), script label, in cs5 changed, , name of item can found in layers palette. now, can copy script labels, new place, , easy access items item name.
this copy current script labels item name:
for(var = 0; < app.activedocument.allpageitems.length; i++) app.activedocument.allpageitems[i].name = app.activedocument.allpageitems[i].label;
now, when have names set up, can access them this:
app.activedocument.groups.item(data[x][1]).textframes.item("name").contents = data[x][2]; app.activedocument.groups.item(data[x][1]).textframes.item("description").contents = data[x][3]; app.activedocument.groups.item(data[x][1]).textframes.item("dimensions").contents = data[x][4]; app.activedocument.groups.item(data[x][1]).textframes.item("price").contents = data[x][5];
hope helps!
--
tomaxxi
More discussions in InDesign Scripting
adobe
Comments
Post a Comment