Sorry for the very late delay, hope you are still looking for this. Note that this does NOT use the SDK - it just uses System.IO.Packaging and Linq (and XML literals). Anyway, here's what to do:
- Create a presentation. On slide 3, add 4 text fields.
- Place the text in the three of them and enter them "Sample1", "Sample2" and "Sample3".
- In the last text box, place two lines of text and then makes these lines bullet holes. Name it "ListSample1".
That is all you need. Then save the file and pay attention to the path and change the filePath variable below to reflect the presentation path.
Run below in the console application:
Imports System.IO Imports System.IO.Packaging ''# Add reference to WindowsBase for this Imports <xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"> Imports <xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> Imports <xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> Module Module1 Public Const documentRelationshipType As String = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Sub Main() Dim slide, document As XElement Dim pptPackage As Package = Nothing Dim slidePart, documentPart As PackagePart Dim filePath As String = "C:\Users\Me\Documents\visual studio 2010\Projects\FillPowerPoint\FillPowerPoint\sample.pptx" pptPackage = Package.Open(filePath, FileMode.Open, FileAccess.ReadWrite) Using pptPackage Dim documentRelationship As PackageRelationship = pptPackage.GetRelationshipsByType(documentRelationshipType).FirstOrDefault Dim documentUri As Uri = PackUriHelper.ResolvePartUri(New Uri("/", UriKind.Relative), documentRelationship.TargetUri) documentPart = pptPackage.GetPart(documentUri) document = XElement.Load(New StreamReader(documentPart.GetStream)) Dim slideList = From e In document.<p:sldIdLst>.<p:sldId> Dim slideIndex As Integer = 3 ''# this is the slide number we want, 1-based Dim slideReference As String = slideList(slideIndex - 1).@r:id.ToString slidePart = pptPackage.GetPart(PackUriHelper.ResolvePartUri(documentPart.Uri, documentPart.GetRelationship(slideReference).TargetUri)) slide = XElement.Load(New StreamReader(slidePart.GetStream)) ''# Replace just text value in Sample1 textbox Dim Sample1 = From e In slide.<p:cSld>.<p:spTree>.<p:sp> Where e.<p:nvSpPr>.<p:cNvPr>.@name = "Sample1" Select e.<p:txBody>.<a:p>.<a:r>.<a:t>.SingleOrDefault Sample1.Value = "new text in sample 1" ''# Replace text and make bold inn Sample2 textbox Dim Sample2 = From e In slide.<p:cSld>.<p:spTree>.<p:sp> Where e.<p:nvSpPr>.<p:cNvPr>.@name = "Sample2" Select e.<p:txBody>.<a:p>.<a:r>.SingleOrDefault Sample2.<a:rPr>.SingleOrDefault.Add(New XAttribute("b", 1)) Sample2.<a:t>.SingleOrDefault.Value = "new bold text in sample 2" ''# Replace text and make bold inn Sample2 textbox Dim Sample3 = From e In slide.<p:cSld>.<p:spTree>.<p:sp> Where e.<p:nvSpPr>.<p:cNvPr>.@name = "Sample3" Select e.<p:txBody>.SingleOrDefault Sample3.<a:p>.Remove() Dim newParagraphs As XElement = <placeholder> <a:p> <a:r> <a:rPr lang="en-US" dirty="0" smtClean="0"/> <a:t>Sample3</a:t> </a:r> </a:p> <a:p> <a:r> <a:rPr lang="en-US" smtClean="0"/> <a:t>With a new paragraph</a:t> </a:r> <a:endParaRPr lang="en-US" dirty="0"/> </a:p> </placeholder> Sample3.SingleOrDefault.Add(newParagraphs.Elements) ''# Create a new list of bullets Dim s() As String = {"Bullet 1", "Bullet 2", "Bullet 3"} Dim ListSample1 = From e In slide.<p:cSld>.<p:spTree>.<p:sp> Where e.<p:nvSpPr>.<p:cNvPr>.@name = "ListSample1" Select e.<p:txBody>.SingleOrDefault ListSample1.<a:p>.Remove() ListSample1.SingleOrDefault.Add(From e In s Select <a:p> <a:pPr marL="285750" indent="-285750"> <a:buFont typeface="Arial" pitchFamily="34" charset="0"/> <a:buChar char="β’"/> </a:pPr> <a:r> <a:rPr lang="en-US" dirty="0" smtClean="0"/> <a:t><%= e %></a:t> </a:r> </a:p>) slide.Save(slidePart.GetStream) End Using End Sub End Module
Sorry, I know this is heavily weighted with respect to VB and XML Literals, but C # should be able to do the same with some conversions.
Todd main
source share