https://issues.apache.org/bugzilla/show_bug.cgi?id=45088
Summary: POI-HSLF changeTextInRichTextRun corrupts presentation
Product: POI
Version: 3.0-dev
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: major
Priority: P2
Component: HSLF
AssignedTo: [email protected]
ReportedBy: [EMAIL PROTECTED]
Created an attachment (id=22024)
--> (https://issues.apache.org/bugzilla/attachment.cgi?id=22024)
test.ppt
Am using a pre-release version of scratchpad (although I think it also happens
with previous versions)
Using version poi-scratchpad-3.1-beta2-20080526
Calling changeTextInRichTextRun renders the output presentation corrupt. Have
tried to open with Microsoft Office Powerpoint 2003 and 2007. The reason I'm
trying to use rich text runs, is to prevent the formating of the text being
erased, which is happening when I call setText on the TextRun. Here's the
code...
public static void main(String[] args) {
doPowerpoint();
}
private static void doPowerpoint() {
try {
SlideShow ppt = new SlideShow(new
HSLFSlideShow("./src/main/resources/test.ppt"));
Slide[] slides = ppt.getSlides();
for (int i = 0; i < slides.length; i++) {
System.out.println("checking slide " + i);
TextRun[] text = slides[i].getTextRuns();
outer: for (int j = 0; j < text.length; j++) {
System.out.println(" checking text " + j);
RichTextRun[] richText = text[j].getRichTextRuns();
for (int k = 0; k < richText.length; k++) {
System.out.println(" checking rich text " + k);
String sText = richText[k].getText();
if (sText != null && sText.contains("[SYSDATE]")) {
String replacedText = sText.replace("[SYSDATE]",
"REPLACED_DATE_WITH_A_LONG_ONE");
text[j].changeTextInRichTextRun(richText[k],
replacedText);
text[j].ensureStyleAtomPresent();
System.out.println("replaced date!" +
richText[k].getRawText());
continue outer;
}
}
}
}
writeFile(ppt);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Problem with slide show " + e.getMessage());
}
}
private static void writeFile(SlideShow slideshow) throws
FileNotFoundException, IOException {
FileOutputStream fos = null;
try {
File outputFile = new File("output.ppt");
fos = new FileOutputStream(outputFile);
slideshow.write(fos);
} finally {
if (fos != null) {
fos.close();
fos = null;
}
}
}
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]