原創(chuàng)|其它|編輯:郝浩|2012-11-01 14:46:47.000|閱讀 809 次
概述:我們知道PowerPoint演示文件(PPT)沒有任何方法來識別幻燈片內(nèi)的特定形狀。本文將描述一個簡單的技術(shù)就能更容易的在幻燈片中找到一個特定的形狀,而不使用它的內(nèi)部Id。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
我們知道PowerPoint演示文件(PPT)沒有任何方法來識別幻燈片內(nèi)的特定形狀,除非使用一個內(nèi)部獨(dú)特的Id。但是這種方法對于開發(fā)者來說優(yōu)勢相當(dāng)復(fù)雜的。本文將描述一個簡單的技術(shù)就能更容易的在幻燈片中找到一個特定的形狀,而不使用它的內(nèi)部Id。
在這里我們需要借助Aspose.Slides這個控件的幫助。
所有添加到幻燈片的形狀都有一些Alternative Text替代文本。我們建議開發(fā)人員使用Alternative Text替代文本尋找一個特定的形狀。您可以使用MS PowerPoint來定義替代文本的對象,如下所示:
具體實(shí)現(xiàn)代碼如下:
[C#]
//Method implementation to find a shape in a slide using its alternative text Shape FindShape(Slide slide, string alttext) { //Iterating through all shapes inside the slide for (int i = 0; i < slide.Shapes.Count; i++) { //If the alternative text of the slide matches with the required one then //return the shape if (slide.Shapes[i].AlternativeText.CompareTo(alttext) == 0) return slide.Shapes[i]; } return null; }
[Visual Basic]
'Method implementation to find a shape in a slide using its alternative text Private Function FindShape(ByVal slide As Slide, ByVal alttext As String) As Shape Dim i As Integer 'Iterating through all shapes inside the slide For i = 0 To slide.Shapes.Count - 1 'If the alternative text of the slide matches with the required one 'then return the shape If slide.Shapes(i).AlternativeText.CompareTo(alttext) = 0 Then Return slide.Shapes(i) End If Next Return Nothing End Function
[C#]
//Calling FindShape method and passing the slide reference with the //alternative text of the shape to be found Shape shape = FindShape(slide, "Shape1");
[Visual Basic]
'Calling FindShape method and passing the slide reference with the 'alternative text of the shape to be found Dim shape As Shape = FindShape(Slide, "Shape1")
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:翻譯