Aspose.slides记录(二)

来源:互联网 发布:怎么查询域名注册商 编辑:程序博客网 时间:2024/06/13 17:28

形状及表格

    public void readShapes(File inFile) throws FileNotFoundException {        InputStream in = null;        if (inFile != null) {            in = new FileInputStream(inFile);        }        // 生成presentation对象        Presentation pres = new Presentation(in);        // 获取幻灯片        ISlideCollection slides = pres.getSlides();        for (ISlide slide : slides) {            // 判断是否为隐藏幻灯片            if (slide.getHidden()) {                continue;            }            // 获取广义的图形对象            IShapeCollection shapes = slide.getShapes();            IPortionCollection portions = null;            IParagraphCollection paras = null;            for (IShape shape : shapes) {                /** 形状及文本框 */                if (shape instanceof IAutoShape) {                    IAutoShape autoShape = (IAutoShape) shape;                    paras = autoShape.getTextFrame().getParagraphs();                    int len = paras.getCount();                    // 文本中段落                    for (int paraNum = 0; paraNum < len; paraNum++) {                        portions = paras.get_Item(paraNum).getPortions();                        readStyle(portions);                    }                /**表格*/                 } else if (shape instanceof ITable) {                    ITable table = (ITable) shape;                    int rowLen = table.getRows().size();                    //行                    for (int rowNum = 0; rowNum < rowLen; rowNum++) {                        int columnLen = table.getColumns().size();                        //列                        for (int columnNum = 0; columnNum < columnLen; columnNum++) {                            //单元格                            ICell cell = table.getRows().get_Item(rowNum).get_Item(columnNum);                            if (rowNum != cell.getFirstRowIndex() || columnNum != cell.getFirstColumnIndex()) {                                continue;                            }                            paras = cell.getTextFrame().getParagraphs();                            for (int paraNum = 0,paraLen = paras.getCount(); paraNum < paraLen; paraNum++) {                                portions = paras.get_Item(paraNum).getPortions();                                readStyle(portions);                            }                        }                    }                }            }        }    }

获取样式

public void readStyle(IPortionCollection portions) {        IHyperlink hyperlink = null;        String font = "";        for (IPortion portion : portions) {            // 文本            String text = portion.getText();            System.out.println("文本:"+text);            // 字体            IPortionFormat portFormart = portion.getPortionFormat();            if (portFormart.getLatinFont() != null) {                font = portFormart.getLatinFont().getFontName();            } else if (portFormart.getEastAsianFont() != null) {                font = portFormart.getEastAsianFont().getFontName();            }            System.out.println("字体:"+font);            // 颜色            Color color = null;            if (portFormart.getFillFormat().getSolidFillColor() != null                    && portFormart.getFillFormat().getSolidFillColor().getColor() != null) {                color = portFormart.getFillFormat().getSolidFillColor().getColor();            }            System.out.println("颜色:"+color.getRGB());            // 字高            Float fontSize = portFormart.getFontHeight();            if (!fontSize.isNaN()) {                System.out.println("字高:" + fontSize);            }            // 删除线            if (portFormart.getStrikethroughType() == TextStrikethroughType.Single) {                System.out.println("单行删除线");            }            // 加粗            if (portFormart.getFontBold() == NullableBool.True) {                System.out.println("加粗");            }            // 下划线            if (portFormart.getFontUnderline() == TextUnderlineType.Single) {                System.out.println("加粗");            }            // 斜体            if (portFormart.getFontItalic() == NullableBool.True) {                System.out.println("斜体");            }            // 下标            if (portFormart.getEscapement() < 0) {                System.out.println("下标");            }            // 上标            if (portFormart.getEscapement() > 0) {                System.out.println("上标");            }            // 超链接            if (portFormart.getHyperlinkClick() != null) {                hyperlink = portFormart.getHyperlinkClick();            } else if (portFormart.getHyperlinkMouseOver() != null) {                hyperlink = portFormart.getHyperlinkMouseOver();            }            String linkAddress = "";            if (hyperlink != null) {                if (StringUtils.isNotBlank(hyperlink.getExternalUrl())) {                    linkAddress = hyperlink.getExternalUrl();                } else if (hyperlink.getTargetSlide() != null) {                    linkAddress = "" + hyperlink.getTargetSlide().getSlideId();                }            }            System.out.println("超链接:"+linkAddress);        }    }