-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStyle.php
More file actions
107 lines (98 loc) · 2.26 KB
/
Style.php
File metadata and controls
107 lines (98 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/*
* style父类
*/
abstract class Style{
private $filename;
private $name;
private $content;
private $ns;
private $outlinelvl;
private $id;
private $basedOn;
private $next;
private $qFormat;
private $results;
private $pPr = array();
function __construct(){
}
function __destruct(){
}
function chk(){
}
function eleToArrNS($ele,$ns = array(),$filename){
$styleArr = array();
if($ele->hasAttributes()){
/*
* 检查是否有属性
*/
$i = 0;
$temp = array();
while($ele->attributes->item($i)){
//echo $ele->attributes->item($i)->localName,":\n";
$temp[$ele->attributes->item($i)->localName]=
$ele->attributes->item($i)->nodeValue;
$i++;
}
//var_dump($temp);
$styleArr = array_merge($styleArr,$temp);
}
if($ele->hasChildNodes()){
/*
* 检查是否有字节点
*/
foreach ($ele->childNodes as $chEle){
$styleArr[$chEle->localName] = eleToArr($chEle, $ns,$filename);
//$styleArr = $styleArr + $tempstyleArr;
}
}
foreach ($ele->getElementsByTagNameNS($ns['w'],'basedOn') as $pele){
$pId = $pele->getAttributeNS($ns['w'],'val');
//echo "baseOn: $pId","\n";
$pstyle = idToStyle($pId, $filename);
//$styleArr = $styleArr + eleToArr($pstyle, $ns, $filename,$styleArr);
$styleArr = array_merge(eleToArr($pstyle, $ns, $filename),$styleArr);
}
}
function idToStyle($id,$filename){
/*
* 根据传进来的styleId
* 返回styleId对应的style节点..
*/
$scontent = getContent('word/styles.xml', $filename);
$sxml = new DOMDocument();
$sxml->loadXML($scontent);
$sns = getNS($scontent);
foreach ($sxml->getElementsByTagNameNS($sns['w'],'style') as $style){
if($style->getAttributeNS($sns['w'],'styleId') == $id){
echo "success $id\n";
return $style;
}
}
}
function eleToArr($ele){
}
function getNS($content){
//$fcomment = getContent($xmlfile, $filename);
$xml = new SimpleXMLElement($content);
$ns = $xml->getDocNamespaces();
return $ns;
}
function getContent($name,$filename)
{
$zip = new ZipArchive();
$res = $zip->open($filename);
if($res == TRUE)
{
$fcomment = $zip->getFromName($name);
return $fcomment;
}
else
{
echo"failed to open $filename"."\n";
return;
}
$zip->close();
}
}
?>