poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pierce Krouse" <pkro...@boundlessnetwork.com>
Subject new user has problems editing a RichTextRun
Date Wed, 05 Mar 2008 17:12:30 GMT
Greetings.
I downloaded the latest POI jars (poi-3.0.2-FINAL-20080204.jar,
poi-scratchpad-3.0.2-FINAL-20080204.jar) with the intent of editing
powerpoint presentations.
Right now I am opening a powerpoint slideshow that is one sheet long,
and I am having problems editing the richtext runs in this existing
sheet.  My intent is to add more sheets to this slideshow and cloning
other sheets into these new sheets by copying all the shapes as
described elsewhere.

Right now I am just getting a toehold by editing this first page and
writing the results back out.  When I simply open the slideshow and
write it back out, I get a faithful copy of the original slideshow, as
expected.  As soon as I edit the RichTextRun objects in the sheet,
powerpoint can no longer read the output.  Here is a snippet of the code
I am using, along with the processSlideText where the problem is:

String headerTemplateLocation = "c:/etc/templates/HeaderTemplate.ppt";
// our main output file to populate
String target = "c:/etc/templates/output.ppt";
// text to find and replace in all slides (both must be the same size)
String[] find = {"${customername}"};
String[] replace = {"YoyoDyne"};
SlideShow ss = new SlideShow(new HSLFSlideShow(headerTemplateLocation));
Slide[] slides  = ss.getSlides();
Slide page1 = slides[0];
// process header slide
processSlideText(page1, find, replace);
		
//save the slideshow
FileOutputStream out = new FileOutputStream(target);
ss.write(out);
out.close();

private void processSlideText(Slide slide, String[] find, String[]
replace){
		TextRun[] textRuns = slide.getTextRuns();
	for (int i=0; i<textRuns.length; i++ ){
		TextRun textRun = textRuns[i];
		RichTextRun richTextRun = textRun.getRichTextRuns()[0];
		String interim = richTextRun.getText();
		System.out.println(" start:"+interim);
		for (int j=0;j<find.length;j++){
			interim = StringUtils.replace(interim, find[j],
replace[j]);
		}
		System.out.println("finish:"+interim);
		// page is corrupted by this call
		richTextRun.setText(interim);
			
		String check = richTextRun.getText();
		System.out.println("checking stored text:"+check);
	}
}

So basically I just look for all the find strings and replace them with
all the replace strings in all the richtextruns in the sheet.

My sheet has exactly one textRun, and the printed output shows that it
is finding the ${customername} text and replacing it with YoyoDyne as
expected.  If I comment out the richTextRun.setText(interim); call the
output is unedited, but readable.  With this line, that isn't the case
-- powerpoint cannot read the file.

This is soooo simple.  Can someone point out what I am missing here?
--Pierce Krouse
Boundless Network
(512)879-4417


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message