web 2.0

How to use ASP & Word (Word.Application) - Add/Insert Picture (AddPicture)

How to use ASP & Word (Word.Application) - Add/Insert Picture (AddPicture) This is learn/tutorial asp developers how to using ASP script Create Word document and Add/Insert Picture (AddPicture)

ShotDev Focus:
- ASP & Create Word document and Add/Insert Picture (AddPicture)

Example

asp_word_image.asp

  1. <% Option  Explicit %>  
  2. <html>  
  3. <head>  
  4. <title>ShotDev.Com Tutorial</title>  
  5. </head>  
  6. <body>  
  7. <%  
  8.   
  9. Const wdColorDarkRed = &H80  
  10.   
  11. Const wdAlignParagraphCenter = 1  
  12. Const wdAlignParagraphLeft = 0  
  13. Const wdParagraph = 4  
  14. Const wdHorizontalPositionMargin = 0  
  15. Const wdTableLeft = -999998  
  16. Const wdCollapseEnd = 0  
  17.   
  18. Dim Wrd,WrdDoc,DocName  
  19. Dim MyRange1,MyRange2,MyRange3  
  20. Set Wrd = CreateObject("Word.Application")  
  21. DocName = "MyDoc/MyWord.doc"  
  22. Wrd.Application.Visible = False  
  23.   
  24. Set WrdDoc = Wrd.Documents.Add()  
  25.   
  26. Set MyRange1 = WrdDoc.Paragraphs.Add.Range  
  27. With MyRange1  
  28. .ParagraphFormat.Alignment = wdAlignParagraphCenter  
  29. .Font.Name = "Verdana"  
  30. .Font.Size = "30"  
  31. .Font.Bold = True  
  32. .InsertBefore(vbCrLf&vbCrLf&"www.ShotDev.Com"&vbCrLf&"Version 2010")  
  33. End With  
  34.   
  35. MyRange1.InlineShapes.AddPicture Server.MapPath("logo.gif")  
  36. 'WrdDoc.InlineShapes.AddPicture Server.MapPath("logo.gif")  
  37. 'WrdDoc.Shapes.AddPicture Server.MapPath("logo.gif"),0,0,MyRange1  
  38. 'WrdDoc.Shapes.AddPicture Server.MapPath("logo.gif"),40,6,Wrd.Selection.Range  
  39.   
  40. Set MyRange2 = WrdDoc.Paragraphs.Add.Range  
  41. With MyRange2  
  42. .ParagraphFormat.Alignment = wdAlignParagraphCenter  
  43. .Font.Name = "Verdana"  
  44. .Font.Size = "15"  
  45. .Font.Bold = True  
  46. .InsertBefore(vbCrLf&vbCrLf&"PHP,ASP and ASP.NET Tutorial")  
  47. End With  
  48.   
  49. MyRange2.InlineShapes.AddPicture Server.MapPath("doc.gif")  
  50.   
  51. Set MyRange3 = WrdDoc.Paragraphs.Add.Range  
  52. With MyRange3  
  53. .ParagraphFormat.Alignment = wdAlignParagraphCenter  
  54. .Font.Name = "Verdana"  
  55. .Font.Size = "10"  
  56. .Font.Bold = True  
  57. .Font.Color = wdColorDarkRed  
  58. .Underline = True  
  59. .InsertBefore(vbCrLf&vbCrLf&vbCrLf&vbCrLf&"All Rights Reserved")  
  60. End With  
  61.   
  62. WrdDoc.SaveAs(Server.MapPath(DocName))  
  63. Wrd.Application.Quit  
  64. Set Wrd = Nothing  
  65. %>  
  66. Word Created <a href="<%=DocName%>">Click here</a> to Download.  
  67. </body>  
  68. </html>  

Create a asp file and save to path root-path/myasp/

Run
http://localhost/myasp/asp_word_image.asp

Screenshot

ASP & Create Word document and Add/Insert Picture (AddPicture).
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.