0

我尝试在 Flex 应用程序中读取 .xlsx 文件。现在我试图确定我的信息在哪里。因此,我从 .xlsx 文件中获取了 XML 数据:

var x:XML = <worksheet mc:Ignorable="x14ac"
  xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
  xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">
     <dimension ref="A1:F77"/>
</worksheet>;

现在我想获得维度属性“ref”。因此我使用以下代码:

var test:Object = x.dimension;
var value:Object = x.dimension.@ref;

如果我将模式表达式留在工作表中,两者都可以完美运行。如何通过包含模式获得正确的结果?有没有一种很好的方法来获取没有模式的 XML?

坦克为您提供帮助。

4

1 回答 1

3

这是因为维度在默认命名空间中xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"

因此,您可以简单地获取 xml 的默认命名空间并像这样使用它:

var ns:Namespace = x.namespace();
var value:Object=x.ns::dimension.@ref;

或自己创建并以相同的方式使用它:

var ns2:Namespace=new Namespace("http://schemas.openxmlformats.org/spreadsheetml/2006/main");
var value2:Object=x.ns2::dimension.@ref;

这里是 Wonderfl 的现场测试: http ://wonderfl.net/c/7XwU

于 2012-08-01T11:27:41.067 回答