使用PHP

时间:2016-08-01 13:38:02

标签: php xml

我觉得我在这里遗漏了一些非常基本的东西,但我真的无法理解。

我正在使用PHP中的SimpleXML解析格式为excel的xml文件。

我的xml文件如下所示:

SimpleXMLElement Object ( 

[DocumentProperties] => SimpleXMLElement Object ( 
    [Author] => Surname Name 
    [LastAuthor] => Name Surname 
    [Created] => 2016-08-01T10:15:25Z 
    [Version] => 14.00 ) 

[OfficeDocumentSettings] => SimpleXMLElement Object ( [AllowPNG] => SimpleXMLElement Object ( ) ) 

[ExcelWorkbook] => SimpleXMLElement Object ( [WindowHeight] => 9375 [WindowWidth] => 9705 [WindowTopX] => 270 [WindowTopY] => 615 [ProtectStructure] => False [ProtectWindows] => False ) 

[Styles] => SimpleXMLElement Object ( [Style] => SimpleXMLElement Object ( [Alignment] => SimpleXMLElement Object ( ) [Font] => SimpleXMLElement Object ( ) ) ) 

[Worksheet] => Array ( 

[0] => SimpleXMLElement Object ( 
    [Table] => SimpleXMLElement Object (
            [Column] => Array (
                [0] => SimpleXMLElement Object ( ) 
                [1] => SimpleXMLElement Object ( ) 
                [2] => SimpleXMLElement Object ( ) )

            [Row] => Array ( 
                [0] => SimpleXMLElement Object ( 
                    [Cell] => Array ( 
                        [0] => SimpleXMLElement Object ( [Data] => Model ) 
                        [1] => SimpleXMLElement Object ( [Data] => Qty ) 
                        [2] => SimpleXMLElement Object ( [Data] => Description ) 
                        [3] => SimpleXMLElement Object ( [Data] => Tags ) ) ) 

                [1] => SimpleXMLElement Object (
                    [Cell] => Array ( 
                        [0] => SimpleXMLElement Object ( [Data] => model_name ) 
                        [1] => SimpleXMLElement Object ( [Data] => 1 ) 
                        [2] => SimpleXMLElement Object ( [Data] => This is my item ) ) ) 

[....code repeats with other rows/worksheets....]

现在,如果我想显示作者姓名,我可以简单地做:     echo $ xml-> DocumentProperties-> LastAuthor; 我会得到预期的结果。如何在各行/单元格中显示值(请记住,xml文件将具有非常多样的行和行并不总是完全填充)?

我尝试过以下内容:

echo $xml->Worksheet[0]->Table->Row[0]->Cell[0];

但这样做并不会带来任何价值。我还希望能够循环遍历所有行,以便我可以将它们显示为HTML表格。

有什么想法吗?

非常感谢您的帮助!

0 个答案:

没有答案