Copy link to clipboard
Copied
Hi, I want to find and alert contens of a cell in a table. Matrix method.
I found a stupid idea to find it.
Well i could get the Number of Column and row. but i cant able to select the contents of a cell (3,1).
(I'm trying to get alert of a content which is having header "Mate" and reference number 71247.
Title | Song | Mate | Film | Two | |
50% | 250 | 500 | 270 | 520 | 71247 |
11% | 125 | Fecker | iNJAMAN | RAH | 71248 |
13 | 222 | IQUE | WATER | WAFER | 71246 |
UNIQUE | FAREST | FAR | TAB | VALUE | 71249 |
var every = app.activeDocument.pages.everyItem(0).textFrames.everyItem().tables.everyItem().cells.everyItem().getElements();
var T = [];
var m = [];
for(i=0; i<every.length; i++) {
if(every.contents =="Mate") {
app.findGrepPreferences.findWhat = "71247";
app.activeDocument.findGrep(true);
var fnd = app.activeDocument.findGrep();
for(y=0; y<fnd.length; y++) {
if(fnd
T.push(fnd
m.push(every.name);
var f= (m).join("\r").replace(":", ".");
var e = (T).join("\r").replace(":", ".");
var u = e-f;
var n = [];
n.push(u);
}
}
}
alert(n);
Many thanks for the support.
If you want to find 500 try this:
...var curDoc = app.activeDocument;
var everyHeaderRow = curDoc.pages.everyItem(0).textFrames.everyItem().tables.everyItem().rows[0].getElements();
for( var i = 0; i<everyHeaderRow.length; i++ ) {
var curHR = everyHeaderRow;
var allHC = curHR.cells;
for ( var j = 0; j < allHC.length; j++ ) {
if ( allHC
.contents == "Mate" ) { var curCol = allHC
.columns[0].index; var curTableCells = curHR.parent.cells;
for ( var c = 0; c < curTableCells.length; c++ ) {
Copy link to clipboard
Copied
Hi,
first I realize that with InDesign CC everyItem() is verry slow, even I have only two tables on one page?!
Why has your last column no header "Mate"? If I understand the question correct, I would do it in this way:
var curDoc = app.activeDocument;
var everyHeaderRow = curDoc.pages.everyItem(0).textFrames.everyItem().tables.everyItem().rows[0].getElements();
for( var i = 0; i<everyHeaderRow.length; i++ ) {
var curHR = everyHeaderRow;
var allHC = curHR.cells;
for ( var j = 0; j < allHC.length; j++ ) {
if ( allHC
.contents == "Mate" ) { var curCol = allHC
.columns[0]; for ( var c = 0; c < curCol.cells.length; c++ ) {
var curCell = curCol.cells
; if ( curCell.contents == "71247" ) {
curCell.select();
var cellName = curCell.name;
var co = Number(curCell.name.split(":")[0])+1;
var ro = Number(curCell.name.split(":")[1])+1;
alert("Found\r" + "Column: " + co + "\r" + "Row: " + ro + "\r" + "Contents: " + curCell.contents);
}
}
}
}
}
Copy link to clipboard
Copied
Sorry for the confusion Kai,
I do want to find the contents which is in column "Mate" and row 71247.
just a x-y co-ordinates which meet at the column Mate and Row which has cell contents "71247"
thanks for the reply Kai.
Copy link to clipboard
Copied
@Unique – every cell has a parentRow property. So if you found a cell, look at its parentRow.cells[-1] to get the last cell of that parent row and read out its contents.
Uwe
Copy link to clipboard
Copied
@Unique – there is a fantastic documentation of the DOM (Document Object Model) where you can look up all properties and methods for the objects. I recommend downloading the chm-files, because they are easily searchable:
Jongware
InDesign JavaScript Reference Guide
http://www.jongware.com/idjshelp.html
Uwe
Copy link to clipboard
Copied
If you want to find 500 try this:
var curDoc = app.activeDocument;
var everyHeaderRow = curDoc.pages.everyItem(0).textFrames.everyItem().tables.everyItem().rows[0].getElements();
for( var i = 0; i<everyHeaderRow.length; i++ ) {
var curHR = everyHeaderRow;
var allHC = curHR.cells;
for ( var j = 0; j < allHC.length; j++ ) {
if ( allHC
.contents == "Mate" ) { var curCol = allHC
.columns[0].index; var curTableCells = curHR.parent.cells;
for ( var c = 0; c < curTableCells.length; c++ ) {
var curCell = curTableCells
; if ( curCell.contents == "71247" ) {
var curRow = curCell.parentRow.index;
var x = curCol + ":" + curRow;
var curName = curTableCells.item(x);
alert(curName.contents);
}
}
}
}
}
Copy link to clipboard
Copied
Hi Laubender & 5.Kai Rübsamen,
Many apologise for my request.
I m not a programmer like you people.
I tried in this way before i got answer from you people.
var every = app.activeDocument.pages.everyItem(0).textFrames.everyItem().tables.everyItem().cells.everyItem().getElements();
// Would be so cool:
var T = [];
var m = [];
var sn = [];
for(i=0; i<every.length; i++) {
if(every.contents =="71247") {
//~
app.findGrepPreferences.findWhat = "Null";
app.activeDocument.findGrep(true);
var fnd = app.activeDocument.findGrep();
for(y=0; y<fnd.length; y++) {
if(fnd
T.push(fnd
m.push(every.name);
var f= (m).join("\r").replace(":", ".");
var e = (T).join("\r").replace(":", ".");
r = [];
r.push(e.split('.')[0]);
//alert (r);
g = [];
g.push(f.split('.')[0]);
//alert(g);
var u = f-e;
var n = [];
n.push(u);
Found = [];
Found.push(g-r);
app.select((every[i-Found]));
sn.push(every[i-Found].contents);
}
}
}
alert (sn);
Sorry for troubling you guys. I want to learn the proper method to create script like you people have created. I m really happy the way you have presented. and im ashamed of what i have done. but i want to simply my method.
Laubender. As far i known, whenever anyone post in the forum you and jump_over [jareak] would always answer for any kind of stupid questions.
thanks Laubender and let me know how can i learn from you.
my id. is. raji27_siva@yahoo.co.in.
many thanks.
Copy link to clipboard
Copied
i got what i need from you,
my is is raji27_siva@yahoo.co.in.
many many thanks or this kai.... please keep in touch with me...