Skip to content

Instantly share code, notes, and snippets.

@moluapple
Created December 21, 2011 04:43
Show Gist options
  • Save moluapple/1504626 to your computer and use it in GitHub Desktop.
Save moluapple/1504626 to your computer and use it in GitHub Desktop.
ID_Get All Tables of ActiveDocument
function extractAllTables () {
var oTables = [];
function getTables (oParent) {
var outTables = oParent[oParent.constructor.name == 'Table' ? 'cells' : 'stories'].everyItem().tables.everyItem().getElements(),
len = outTables.length,
i = 0;
oTables = oTables.concat(outTables);
for (; i < len; i++) outTables[i].cells.everyItem().tables.everyItem().getElements().length && getTables(outTables[i]);
}
getTables(app.activeDocument);
return oTables
}
function findAllTables () {
app.findTextPreferences.findWhat = '<0016>';
var oTables = [],
oChars = app.activeDocument.findText(),
len = oChars.length,
i = 0;
for (; i < len; i++) oTables.push(oChars[i].tables[0]);
app.findTextPreferences.findWhat = NothingEnum.nothing;
return oTables
}
// *********************** 测试代码
$.writeln('抽出法');
var oTables = extractAllTables(), i = 0, len = oTables.length;
for (; i < len; i++) $.writeln(oTables[i].cells[0].contents);
$.writeln('查找法');
var oTables = findAllTables(), i = 0, len = oTables.length;
for (; i < len; i++) $.writeln(oTables[i].cells[0].contents);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment