Анализ файла Excel, сохраненного в формате XML 2003 (после сохранения в формате XML откройте в блокноте и удалите первые две строки)
// XML
var main_xml:XML = new XML();
main_xml.ignoreWhite = true;
main_xml.load(_global.path + "main.xml"+_global.randomprm)
main_xml.onLoad = function(success) {
var s:String = xmlValueOnPageByColTitleAndRow("your_worksheet_title", "cell_value_in_any_row_in_interested_column_OR_column_title_in_table", 2); // 2 - row number in table
trace(s);
};
function xmlValueOnPageByColTitleAndRow(PageName:String, ColTitle:String, Row:Number) {
var worksheet:XMLNode = xmlNodeByNameWithValue(main_xml.firstChild, "Worksheet", PageName);
var column = xmlColumnByValue(worksheet, ColTitle);
var rowNode:XMLNode = xmlNodeByNameWithOrder(worksheet, "Row", Row);
var cell:XMLNode = xmlNodeByNameWithOrder(rowNode, "Cell", column);
return cell.firstChild.firstChild.nodeValue;
}
function xmlColumnByValue(node:XMLNode, Value:String) {
if (node.firstChild.nodeName == "Cell") {
var n = 0;
for (var childnode:XMLNode = node.firstChild; childnode != null; childnode = childnode.nextSibling, n++) {
if (childnode.firstChild.firstChild.nodeValue == Value) return n;
}
} else
for (var childnode:XMLNode = node.firstChild; childnode != null; childnode = childnode.nextSibling) {
res = xmlColumnByValue(childnode, Value);
if (res > -1) return res;
}
return -1;
}
function xmlNodeByNameWithOrder(node:XMLNode, Name:String, Order:Number) {
var n = 0;
for (var childnode:XMLNode = node.firstChild; childnode != null; childnode = childnode.nextSibling)
if (childnode.nodeName == Name) {
n++;
if (n == Order) return childnode;
}
for (var childnode:XMLNode = node.firstChild; childnode != null; childnode = childnode.nextSibling) {
finded = xmlNodeByNameWithOrder(childnode, Name, Order);
if (finded != NULL) return finded;
}
return NULL;
}
function xmlHasValue(node:XMLNode, Value:String) {
for (attr in node.attributes) {
if (node.attributes[attr] == Value) return true;
}
return false;
}
function xmlNodeByNameWithValue(node:XMLNode, Name:String, Value:String) {
if (node.nodeName == Name) {
if (xmlHasValue(node, Value))
return node;
else
return null;
} else {
for (var childnode:XMLNode = node.firstChild; childnode != null; childnode = childnode.nextSibling) {
finded = xmlNodeByNameWithValue(childnode, Name, Value);
if (finded != NULL) return finded;
}
}
return NULL;
}
var depth = 0;
var str = "";
function traceAllChilds(node:XMLNode) {
depth++;
str = ""; for (var i=0; i<depth; i++) str = str + " ";
if (node.nodeValue) trace(str + node.nodeName + " = " + node.nodeValue);
else trace(str + node.nodeName);
for (attr in node.attributes)
trace (str + " [" + attr + " = " + node.attributes[attr]+"]");
for (var childnode:XMLNode = node.firstChild; childnode != null; childnode = childnode.nextSibling)
traceAllChilds(childnode);
str = ""; for (var i=0; i<depth; i++) str = str + " ";
trace(str+""+ node.nodeName);
depth--;
return true;
}