Smartart
smartart是office中一个比较特殊的插入样式,该样式数据在openxml里存储在[word|xl|ppt]/diagrams/data([0-9]+).xml中,在word/excel中需采取代码解压后读取xml的方式读取信息,在aspose.slides中有相应的类可直接处理.smartart节点为多层(级)节点,节点之间按父子节点作为节点关系;本文使用递归的方式读取子节点节点的位置信息可以通过node.getPosition()方法获取,本文不同级的节点用”,”隔开后拼接为字符串存储,将文本及位置信息存放在数据库后,外部修改文本后可保证写回数据时的位置关系一一对应
if(shape
instanceof SmartArt){
SmartArt smartArt = (SmartArt) shape;
for (ISmartArtNode node : smartArt.getNodes()){
int postion =
0;
paras = node.getTextFrame().getParagraphs();
int len = paras.getCount();
for (int paraNum =
0; paraNum < len; paraNum++) {
portions = paras.get_Item(paraNum).getPortions();
readStyle(portions);
postion = node.getPosition();
String postionNum =
String.valueOf(postion) ;
}
String parentPostion =
String.valueOf(postion++);
readSmartArtChildNode(node, parentPostion);
}
}
读取子节点
private void readSmartArtChildNode(ISmartArtNode node,String parentPostion) {
if (node.getChildNodes() !=
null) {
ISmartArtNodeCollection childNodes = node.getChildNodes();
int index =
0;
for (ISmartArtNode childNode : childNodes) {
String postionNum = parentPostion +
","+ String.valueOf(
index)+
",";
IParagraphCollection paras = childNode.getTextFrame().getParagraphs();
int len = paras.getCount();
for (
int paraNum =
0; paraNum < len; paraNum++) {
IPortionCollection portions = paras.get_Item(paraNum).getPortions();
readStyle(portions);
}
++
index;
readSmartArtChildNode(childNode, postionNum);
}
}
}