修改或编辑.net中的ppt模板

时间:2013-12-10 04:10:21

标签: asp.net openxml

我有一个网站发送带有附件的邮件,这是一个ppt演示文稿。 我将ppt模板存储在我的应用程序中。 基于用户做出的选择,我需要修改模板内容,即即将文本添加到该ppt模板并将其作为附件发送。 有人请告诉我如何编辑或修改ppt模板。

感谢。

2 个答案:

答案 0 :(得分:0)

如果你想在.net代码后面写下ppt模板,我已经使用了shotdev的解决方案,它在vb.net中:

Imports Microsoft.Office.Interop.PowerPoint
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Const wdColorLightGreen = &HCCFFCC
Const wdColorBlue = &HCCFFCC

Dim ppApp As New Microsoft.Office.Interop.PowerPoint.Application
Dim ppPres As Presentation
Dim ppSlide1, ppSlide2, ppSlide3, ppSlide4 As Slide
Dim ppName As String = "MyPP/MyPPt.ppt"
Dim ppDoc As String = "shotdev.ppt"

ppApp.Visible = True

ppPres = ppApp.Presentations.Open(Server.MapPath(ppDoc))

ppSlide1 = ppPres.Slides(1)
'*** AddTextbox, objControl.Left,objControl.Top,objControl.Width,objControl.Height ***'
ppSlide1.Shapes.AddTextbox(1, 50, 100, 700, 100) '***4
ppSlide1.Shapes(1).TextFrame.TextRange.Text = "I Love ShotDev.Com 1"
ppSlide1.Shapes(1).TextFrame.TextRange.Font.Name = "Arial"
ppSlide1.Shapes(1).TextFrame.TextRange.Font.Size = 10
ppSlide1.Shapes(1).TextFrame.TextRange.Font.Color.RGB = wdColorLightGreen

ppSlide1.Shapes.AddTextbox(1, 50, 150, 700, 100)
ppSlide1.Shapes(2).TextFrame.TextRange.Text = "I Love ShotDev.Com 2"
ppSlide1.Shapes(2).TextFrame.TextRange.Font.Name = "Arial"
ppSlide1.Shapes(2).TextFrame.TextRange.Font.Size = 20

ppSlide1.Shapes.AddTextbox(1, 50, 200, 700, 100)
ppSlide1.Shapes(3).TextFrame.TextRange.Text = "I Love ShotDev.Com 3"
ppSlide1.Shapes(3).TextFrame.TextRange.Font.Name = "Arial"
ppSlide1.Shapes(3).TextFrame.TextRange.Font.Size = 30

ppSlide1.Shapes.AddTextbox(1, 50, 250, 700, 100)
ppSlide1.Shapes(4).TextFrame.TextRange.Text = "I Love ShotDev.Com 4"
ppSlide1.Shapes(4).TextFrame.TextRange.Font.Name = "Arial"
ppSlide1.Shapes(4).TextFrame.TextRange.Font.Size = 40

ppSlide1.Shapes.AddTextbox(1, 50, 300, 700, 100)
ppSlide1.Shapes(5).TextFrame.TextRange.Text = "I Love ShotDev.Com 5"
ppSlide1.Shapes(5).TextFrame.TextRange.Font.Name = "Arial"
ppSlide1.Shapes(5).TextFrame.TextRange.Font.Size = 50
ppSlide1.Shapes(5).TextFrame.TextRange.Font.Color.RGB = wdColorBlue
ppSlide1.Shapes.AddPicture(Server.MapPath("logo.gif"), 0, 1, 310, 380, 100, 100) '*** Picture,Left,Top,Width,Height ***'

ppSlide2 = ppPres.Slides.Add(2, 3)
ppSlide2.Shapes(1).TextFrame.TextRange.Text = "www.ShotDev.Com Version"
ppSlide2.Shapes(1).TextFrame.TextRange.Font.Color.RGB = wdColorBlue
ppSlide2.Shapes(2).TextFrame.TextRange.Text = "Version 2009" & vbCr & _
"Version 2009" & vbCr & "Version 2009" & vbCr & "Version 2009"
ppSlide2.Shapes(3).TextFrame.TextRange.Text = "Version 2010" & vbCr & _
"Version 2010" & vbCr & "Version 2010" & vbCr & "Version 2010"

ppSlide3 = ppPres.Slides.Add(3, 4)
ppSlide3.Shapes(1).TextFrame.TextRange.Text = "We Love ShotDev.Com"
ppSlide3.Shapes(1).TextFrame.TextRange.Font.Color.RGB = wdColorBlue

ppSlide4 = ppPres.Slides.Add(4, 5)
ppSlide4.Shapes(1).TextFrame.TextRange.Text = "We Love ShotDev.Com"
ppSlide4.Shapes(1).TextFrame.TextRange.Font.Color.RGB = wdColorBlue
ppSlide4.Shapes(2).TextFrame.TextRange.Text = "2006" & vbCr & "2007" & vbCr & "2008" & vbCr & "2009" & vbCr & "2010"

ppApp.Presentations(1).SaveAs(Server.MapPath(ppName))
ppApp.Quit()
ppApp = Nothing

Me.lblText.Text = "PowerPoint Created <a href=" & ppName & ">Click here</a> to Download."

End Sub
End Class

你可以参考:http://www.shotdev.com/aspnet/aspnet-vbnet-powerpoint/aspnet-vbnet-powerpoint-open-template-modify-edit-slides/

答案 1 :(得分:0)

试试MS interop assemblis。 如果您使用*.pptx格式,也可以使用openXML