Aspose.slides记录(四)

来源:互联网 发布:手机魔术卡软件 编辑:程序博客网 时间:2024/05/17 08:03

图表

这里写图片描述
图表也是PPT中一个特殊的插入样式,该样式外显数据在openxml里存储在/charts/chart([0-9]+).xml中,但是实际数据存放在PPT的内嵌excel里面,本质上等同于一个内嵌excel.
获取方式与前文类似,代码如下:

if(shape instanceof Chart){    //图表    Chart chart = (Chart)shape;    //TODO          }

图表中需读取的信息分为图表标题、坐标轴、单元格数据及单元格标签,其中单元格数据为纯数字,按照用户需求不需要读取,因此本文仅讨论其他种类的信息获取.

标题

ITextFrame titleTextFrame = chart.getChartTitle().getTextFrameForOverriding();if ( titleTextFrame != null) {    IParagraphCollection titleParas  = titleTextFrame.getParagraphs();    for (int paraNum = 0,len = titleParas.getCount(); paraNum < len; paraNum++) {        IPortionCollection titlePortions = titleParas.get_Item(paraNum).getPortions();        readStyle(titlePortions);    }}

坐标轴

坐标轴类型如果为日期坐标轴,读取的数据为时间的毫秒数,与现实的文字不符,需再进行日期格式的转换

// 系列IChartSeriesCollection seriesCol = chart.getChartData().getSeries();    int xSize = seriesCol.size();    for (int x =0; x < xSize ;x++) {    if(seriesCol.get_Item(x) != null && seriesCol.get_Item(x).getName() !=null){        String seriesValue = seriesCol.get_Item(x).getName().toString();    }}       // 类别IChartCategoryCollection categoryCol = chart.getChartData().getCategories();int ySize = categoryCol.size();for(int y=0;y <ySize; y++){    if(categoryCol.get_Item(y) != null && categoryCol.get_Item(y).getValue() != null){        String categoryValue = categoryCol.get_Item(y).getValue().toString();    }}

单元格标签

单元格标签同坐标轴一样,aspose.slides取值只能取到String对象,而不能取到postion对象,因此不包含样式,只包含文本

// 单元格标签int size = chart.getChartData().getSeries().size();for (int m = 0; m < size; m++) {    IChartSeries series = chart.getChartData().getSeries().get_Item(m);    int len = series.getDataPoints().size();    for (int n = 0; n < len; n++) {        String labelValue = series.getDataPoints().get_Item(n).getLabel()                            .getTextFrameForOverriding().getText();         }}
原创粉丝点击