这两种PowerPoint形状的不同之处(通过API访问)

时间:2016-10-02 17:49:26

标签: python powerpoint

作为开源辅助技术项目(here)的一部分,我通过python API(python-pptx)访问PowerPoint文件。

当我看到颜色时,某些形状会导致异常。但很难看出哪一个。

我创建了这个最小的例子:https://www.dropbox.com/s/o5z22lqwb66jemq/forUpload.pptx?dl=0

事实上,这是一个截图:

enter image description here

它由一张幻灯片组成,左边有形状,右边有失败的形状。使用格式画家将使形状工作(或不,取决于格式的来源),但我已经通过各种方式检查我能想到的格式,并且两组形状看起来相同。

最小例子中的两组形状有何不同?

(对于那些可能从API观点感兴趣的人。导致问题的一行是:

self.colours[co][ro] = shape.fill.fore_colour.rgb

位于https://github.com/joereddington/TheOpenVoiceFactory/blob/master/grab_text.py

,例外是:

Traceback (most recent call last):   File "grab_text.py", line 374, in <module>
    grids = extract_grid(prs)   File "grab_text.py", line 353, in extract_grid
    grids.append(Grid(prs, slide, gridSize))   File "grab_text.py", line 119, in __init__
    self.process_shape(shape)   File "grab_text.py", line 164, in process_shape
    ro] = shape.fill.fore_color.rgb   File "/Library/Python/2.7/site-packages/pptx/dml/fill.py", line 43, in fore_color
    return self._fill.fore_color   File "/Library/Python/2.7/site-packages/pptx/dml/fill.py", line 161, in fore_color
    raise TypeError(tmpl) TypeError: a transparent (background) fill has no foreground color

1 个答案:

答案 0 :(得分:0)

您需要致电:

import { Component, EventEmitter, 
  OnInit, AfterViewInit, OnChanges, SimpleChanges,
  Input, Output
} from '@angular/core';

@Component({
  templateUrl: 'myTemplate.html'
    , providers: [ NamesService ]
})

export class MyPage  {
  @Input() names: any[];

  constructor( public namesSvc: NamesService) {}

  ngOnInit() {
    this.getNames$()
  }


  getNames$() : void {
    this.nameService.get().subscribe( 
      (result)=>{
       this.names = result;
       console.log(`getNames$, names=${this.names}`);

       // I could doSomething() here, but it doesn't seem like the correct place
       // doSomething()  

      }
      , error =>  this.errorMessage = <any>error
    )
  }

  ngOnChanges(changes: SimpleChanges) : void {
    // changes.prop contains the old and the new value...
    console.warn(`>>> ngOnChanges triggered`)
    if (changes["names"]) {
      console.warn(`>>> ngOnChanges, names=${changes["names"]}`)
      this.doSomething()
    }
  }

  doSomething(){
    console.log("doing something");
  }
}
在尝试访问shape.fill.solid() 属性之前

填充可以有多种类型,每种类型都有不同的属性集。 fore_color属性特定于实心填充。默认情况下,填充是透明的(即无)。

在这里的文档中有更多关于它的内容: http://python-pptx.readthedocs.io/en/latest/user/autoshapes.html#fill