delphi 呼叫office word,製作浮水印文件 |
|
aftcast
站務副站長 發表:81 回覆:1485 積分:1763 註冊:2002-11-21 發送簡訊給我 |
hello,大家好,因前些日子在 g+ 社團Delphi Developers,上有人問到,花了一點時間去實作,就把程式也放上來給國人參考。
先把提問者的問題貼一下,就不翻譯了: I can Open it and save it to pdf with the below code but couldn't manage to add a watermark. I saved a macro while adding the watermark but I'm having difficulty changing the macro to delphi code. var begin Doc := WordApp.Documents.Open('D:\document.doc'); Doc.ExportAsFixedFormat('D:\document.pdf', 17); Doc := Unassigned; The macro: ActiveDocument.Sections(1).Range.Select Selection.HeaderFooter.Shapes.AddTextEffect(PowerPlusWaterMarkObject, "URGENT", "Calibri", 1, False, False, 0, 0).Select Selection.ShapeRange.Name Selection.ShapeRange.TextEffect.NormalizedHeight = False Selection.ShapeRange.Fill.Visible = True Selection.ShapeRange.Fill.ForeColor.RGB = KYM(192, 192, 192) Selection.ShapeRange.Rotation = 315 Selection.ShapeRange.Height = CentimetersToPoints(3.76) Selection.ShapeRange.WrapFormat.AllowOverlap = True Selection.ShapeRange.WrapFormat.Type = 3 Selection.ShapeRange.RelativeVerticalPosition = wdRelativeVerticalPositionMargin Selection.ShapeRange.Top = wdShapeCenter End Sub 以下是我的回覆: you should use Type Library to import then sample as below: var doc : WordDocument; begin wordAp := Word_TLB.CoWordApplication.Create; wordAp.Visible := true; wordAp.ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageHeader; msoTextEffect1, msoFalse, 0.0, 0.0, EmptyParam).Select(EmptyParam); wordAp.Selection.ShapeRange.Line.Visible := msoFalse; wordAp.Selection.ShapeRange.Fill.Solid; wordAp.Selection.ShapeRange.Fill.Transparency := 0.5; wordAp.Selection.ShapeRange.LockAspectRatio := msoTrue; wordAp.Selection.ShapeRange.Width := 16.52*28.35; wordAp.Selection.ShapeRange.WrapFormat.Side := wdWrapNone; wordAp.Selection.ShapeRange.RelativeHorizontalPosition := wdRelativeVerticalPositionMargin; wordAp.Selection.ShapeRange.Left := Integer(wdShapeCenter); // tricky here cast to Integer wordAp.ActiveWindow.ActivePane.View.SeekView := wdSeekMainDocument; wordAp := nil; ActiveDocument.Sections(1).Range.Select Selection.HeaderFooter.Shapes.AddTextEffect(PowerPlusWaterMarkObject1, _ = "PowerPlusWaterMarkObject1" Selection.ShapeRange.Line.Visible = False Selection.ShapeRange.Fill.Solid Selection.ShapeRange.Fill.Transparency = 0.5 Selection.ShapeRange.LockAspectRatio = True Selection.ShapeRange.Width = CentimetersToPoints(10.33) Selection.ShapeRange.WrapFormat.Side = wdWrapNone Selection.ShapeRange.RelativeHorizontalPosition = _ Selection.ShapeRange.RelativeVerticalPosition = _ Selection.ShapeRange.Left = wdShapeCenter ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument end; Enjoy! BTW, im using XE with word 2003 完整專案在附加檔上:
------
蕭沖 --All ideas are worthless unless implemented-- C++ Builder Delphi Taiwan G+ 社群 http://bit.ly/cbtaiwan |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
|
sryang
尊榮會員 發表:39 回覆:762 積分:920 註冊:2002-06-27 發送簡訊給我 |
|
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
|
aftcast
站務副站長 發表:81 回覆:1485 積分:1763 註冊:2002-11-21 發送簡訊給我 |
是的。但問題是… 就像提問的人,他錄好後,完全不知怎麼寫下去。
我個人覺得大致上是因為多數在google上可以看到的delphi 寫office類都是用 variant 叫物件,而不是用 type library的方式。 這樣會導致,有一些「常數」是定義在type lib裡,你不知他到底是什麼,數值為何… 若是用variant 來create object,寫程式的過程就像是在 盲打 你完全沒有 code complete的功能,也不知到底對否。 對貓你當然一切不是問題啦! >< ===================引 用 sryang 文 章=================== 我的作法很簡單,就是錄製巨集,然後抄巨集裡面的寫法
------
蕭沖 --All ideas are worthless unless implemented-- C++ Builder Delphi Taiwan G+ 社群 http://bit.ly/cbtaiwan |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
使用 Delphi 包好的元件組會好一點
但真的只有一點點 【對貓你當然一切不是問題啦! 】 1 ===================引 用 aftcast 文 章=================== 是的。但問題是… 就像提問的人,他錄好後,完全不知怎麼寫下去。 我個人覺得大致上是因為多數在google上可以看到的delphi 寫office類都是用 variant 叫物件,而不是用 type library的方式。 這樣會導致,有一些「常數」是定義在type lib裡,你不知他到底是什麼,數值為何… 若是用variant 來create object,寫程式的過程就像是在 盲打 你完全沒有 code complete的功能,也不知到底對否。 對貓你當然一切不是問題啦! >< ===================引 用 sryang 文 章=================== 我的作法很簡單,就是錄製巨集,然後抄巨集裡面的寫法
編輯記錄
GrandRURU 重新編輯於 2014-07-21 16:26:51, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |