I have a function that looks through a slide and reads all available text. It has been working well except for this slide. It can’t find the text…
Ok, just found it but it seems strange to me.
slide.placeholders.count returns 1
slide.placeholders[0] returns null
slide.placeholders[1] returns the textholder
I thought the array should be zero based?
I’ve attached the slide I used.
Thanks for any info
JP
Dear plunk,
I think, proper checks are missing on Slide.Placeholders collection and index is also not starting with 0. I will report it.
However, I am able to read all the text inside the placeholder, you should typecast the placeholder into a textframe and then read its text e,.g the following code gives this output
[Placeholder Text]=Standard medical procedures have been developed for the treat
ment of patients in the traditional pre-hospital and hospital environments where
evacuations are usually achieved in less than 1 hour. These procedures are not
UNDERSTAND THE ENVIRONMENT YOU ARE WORKING IN!!
Here is the code
void ReadText()
{
//read existing presentation
Presentation pres = new Presentation("tcc1.ppt");
//Presentation pres = new Presentation("srcReadText.ppt");
//get the reference of first slide
Slide fstSlide = pres.GetSlideByPosition(1);
//iterate through all shapes and print their containing text
foreach (Shape shp in fstSlide.Shapes)
{
if (shp.GetType().Name == "Rectangle")
if (shp.Placeholder != null)
{
TextHolder th = shp.Placeholder as TextHolder;
Console.WriteLine("[Placeholder Text]=" + th.Text);
}
else
{
TextFrame tf = shp.TextFrame;
Console.WriteLine("[Textbox Text]=" + tf.Text);
}
}
}
In the debugger you can see all the text
"Standard medical procedures have been developed for the treatment of patients in the traditional pre-hospital and hospital environments where evacuations are usually achieved in less than 1 hour. These procedures are not always applicable to your work environment.\r\rUNDERSTAND THE ENVIRONMENT YOU ARE WORKING IN!! "
Thanks for verifying this.
JP
Dear Plunk,
Actually, Placeholders collection is zero-based. First element, i.e at position 0 is always a header placeholder.
Since your slide does not have header placeholder, so it returns null.
Please read this note from out team lead
“Placeholders collection is not zero based. There can be up to 8 placeholders and their indexes are hard-coded. For example Header always has index 0. If slide doesn’t have header placeholder then Placeholders[0] will be null.
So to iterate all placeholder it’s necessary to check Placeholders[0…7] and also check if they are not null. For better simple iterating it’s possible to use public DictionaryEnumerator Placeholders.GetEnumerator() method”
This is a sample code to iterate all of your placeholders and read text using IDictionaryEnumerator, using it set you free from caring, which placeholder is null or which is not.
void IteratingPlaceholdersArray()
{
Presentation srcPres = new Presentation("tcc1.ppt");
Slide fstSlide = srcPres.GetSlideByPosition(1);
IDictionaryEnumerator IDICEnum = fstSlide.Placeholders.GetEnumerator();
while (IDICEnum.MoveNext())
{
TextHolder th = (TextHolder)IDICEnum.Value;
Console.WriteLine(th.Text);
}
}