您好,妖哥,還是這個問題,http://bbs.csdn.net/topics/390850793?page=1#post-397919561
就是如何獲得第2個幻燈片里邊有多少個資料(占位符?物件?)呢。
如果我批量修改PPT的話,他每個幻燈片里邊的資料個數不一樣
有的是2個圖片1段文字,有的是3段文字2個圖片。等等
如果定義死了,就出錯了。
期待回復*(delphi的),謝謝。
uj5u.com熱心網友回復:
PowerPointSlide1.Shapes.Count
uj5u.com熱心網友回復:
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
// 啟動PowerPoint
PowerPointApplication1.Connect;
// 為除錯方便,設定其界面可視
PowerPointApplication1.Visible := msoTrue;
// 打開一個已存在的PPT檔案
PowerPointPresentation1.ConnectTo(PowerPointApplication1.Presentations.Open
('D:\Desktop\ppt\3.ppt', msoFalse, msoFalse, msoTrue));
if PowerPointPresentation1.Slides.Count > 1 then
begin
// 定位到第二張幻燈片
PowerPointSlide1.ConnectTo(PowerPointPresentation1.Slides.Item(2));
// 填寫第二張幻燈片的兩個文本框
if PowerPointSlide1.Shapes.Count > 1 then
begin
with PowerPointSlide1 do
begin
Layout := 3;//型別3是文本
FollowMasterBackground := 0;//設定背景
i := Shapes.Count + 1;
//獲取第二張幻燈片的資料有3個,然后我+1,創建第四個,并在其上添加資料,但是卻提示越界了。
Shapes.Item(i).TextFrame.TextRange.Text := Edit1.Text;
Shapes.Item(i).TextFrame.TextRange.Font.Name := 'Arial';
Shapes.Item(i).TextFrame.TextRange.Font.size := 1.5;
Shapes.Item(i).TextFrame.TextRange.Font.Color.RGB := RGB(255, 255, 255);
Shapes.Item(i).Left := 10;
Shapes.Item(i).Top := 10;
Shapes.Item(i).Width := 50;
Shapes.Item(i).Height := 10;
end;
end;
end;
end;
提示越界,妖哥。只能添加到已有的物件?不能創建一個新的物件,并寫入資料嗎?
uj5u.com熱心網友回復:
提示越界這個問題,你的PowerPointPresentation1和PowerPointSlide1可曾有關系?如果兩個物件是陌路人,不越界才怪。uj5u.com熱心網友回復:

我感覺PowerPointPresentation1和PowerPointSlide1在這里關系不大。
with PowerPointSlide1 do
begin
Layout := 3;//型別3是文本
FollowMasterBackground := 0;//設定背景
i := Shapes.Count + 1;
//這個地方出錯的,比如幻燈2里邊有3個文本框
// 如果不+1,就會在第三個文本框中追加資料。
//如果+1,就是創建第四個文本框并寫入資料,但是他說,只有3個,不能搞第四個。
Shapes.Item(i).TextFrame.TextRange.Text := Edit1.Text;
Shapes.Item(i).TextFrame.TextRange.Font.Name := 'Arial';
Shapes.Item(i).TextFrame.TextRange.Font.size := 1.5;
Shapes.Item(i).TextFrame.TextRange.Font.Color.RGB := RGB(255, 255, 255);
Shapes.Item(i).Left := 10;
Shapes.Item(i).Top := 10;
Shapes.Item(i).Width := 50;
Shapes.Item(i).Height := 10;
end;
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
貌似搞定了,應該先創建一個TXT文本框,再寫入。Shapes.AddTextbox(msoTextOrientationHorizontal ,10,10,100,15);
uj5u.com熱心網友回復:
首先,PowerPointPresentation1肯定得和PowerPointSlide1有關系(不管是設計時還是運行時設定屬性)其次,Office中的下標是從1開始的。
uj5u.com熱心網友回復:
謝謝妖哥,我還以為也是從0開始的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/117264.html
上一篇:cbc執行SQL陳述句INSERT INTO時用什么函式對欄位轉換?
下一篇:跪求解答。。。
