1

Apache poi hslf を使用して、パワーポイントにテキスト ボックスを追加したいと考えています。テキストボックスに、見出しを追加してから、同じテキストボックスに箇条書きを追加したいと考えています。しかし、richtextrun.setbullet(true); を適用すると 見出しは別のリッチテキストランにありますが、見出し付きの箇条書きも配置します。どんな助けでも大歓迎です。サンプルコードを添付しています。

import org.apache.poi.hslf.record.StyleTextPropAtom; 
import org.apache.poi.hslf.record.TextCharsAtom; 
import org.apache.poi.hslf.record.Record; 
import org.apache.poi.hslf.model.*; 
import org.apache.poi.hslf.model.textproperties.TextPropCollection; 
import org.apache.poi.hslf.usermodel.SlideShow; 
import org.apache.poi.hslf.usermodel.RichTextRun; 

import java.awt.*; 
import java.io.*; 

public class test { 

     public static void main(String[] args) throws Exception { 

         SlideShow ppt = new SlideShow(); 
         Slide slide = ppt.createSlide(); 
         TextShape shape = new TextBox(); 
         shape.setSheet(slide); 

         TextRun run = shape.getTextRun(); 
         StyleTextPropAtom styleAtom = null; 
         TextCharsAtom textAtom = null; 
         for(Record r : run.getRecords()){ 
             if(r instanceof StyleTextPropAtom) styleAtom = (StyleTextPropAtom)r; 
             else if(r instanceof TextCharsAtom) textAtom = (TextCharsAtom)r; 
         } 

         styleAtom.getParagraphStyles().clear(); 
         styleAtom.getCharacterStyles().clear(); 

         StringBuffer text = new StringBuffer(); 
         TextPropCollection prProps, chProps; 
         RichTextRun rt; 
         String chunk; 

         //begin building rich text runs 

         //this should be heading and without bullet ppoint
         chunk = " Apache POI"; 

         text.append(chunk); 
         prProps = styleAtom.addParagraphTextPropCollection(chunk.length()); 
         chProps = styleAtom.addCharacterTextPropCollection(chunk.length()); 
         rt = new RichTextRun(shape.getTextRun(), text.length(), chunk.length(), null, chProps, false, false); 
         rt.supplySlideShow(ppt); 
         rt.setFontColor(Color.green); 
         rt.setItalic(true); 
         rt.setFontSize(24); 

        String chunk = " \r is \r cool"; 
        int len = chunk.length();
         text.append(chunk); 
         prProps = styleAtom.addParagraphTextPropCollection(chunk.length()); 
         chProps = styleAtom.addCharacterTextPropCollection(chunk.length()); 
         rt = new RichTextRun(shape.getTextRun(), text.length(), chunk.length(), prProps, chProps, false, false); 
         rt.supplySlideShow(ppt); 
         PPFont font = new PPFont(); 
         font.setFontName("Times New Roman"); 
         int fontIndex = ppt.addFont(font); 
         rt.setFontIndex(fontIndex); 
         rt.setBold(true); 
         rt.setFontSize(24); 
         rt.setBullet(true);

         //sum of chunk lengths must be text.length+1, add a dummy char to the end 
         styleAtom.addParagraphTextPropCollection(1); 
         styleAtom.addCharacterTextPropCollection(1); 

         String txt = text.toString(); 
         textAtom.setText(txt); 
         shape.getTextRun().buildRichTextRuns(styleAtom.getParagraphStyles(), styleAtom.getCharacterStyles(), txt); 
         //end building rich text runs 

         shape.setAnchor(new Rectangle(100, 100, 300, 50)); 
         slide.addShape(shape); 

         FileOutputStream out = new FileOutputStream("test.ppt"); 
         ppt.write(out); 
         out.close(); 

     } 

} 

前もって感謝します

現在の出力は ここに画像の説明を入力

最初の行に箇条書きは必要ありません

4

1 に答える 1