使用 apache poi 在有项目符号点时更正文本对齐
Correct Text Alignment when there is a bullet point using apache poi
我正在使用 apache poi xslf 创建一个文本框,然后在其中添加一个项目符号。问题是当项目符号点是多行文本时,它会像这样添加
-文本分析、nGram、朴素贝叶斯文本分类器,用于识别对话的性质、情绪和提出投诉的风险
在上面的要点对话中,应与要点行中的文字文本对齐,即像这样的文本对齐方式
- 文本分析、nGram、朴素贝叶斯文本分类器识别
的性质
谈话情绪和被投诉的风险。
代码如下
XSLFTextBox textbox = this.slide.createTextBox();
textbox.setAnchor(new Rectangle(this.xAxis,this.yAxis,this.width,this.height)); XSLFTextParagraph contentPara = textbox.addNewTextParagraph();
XSLFTextRun bullet1TR = contentPara.addNewTextRun(); contentPara.setBullet(true);
contentPara.setFontAlign(FontAlign.TOP); contentPara.setTextAlign(TextAlign.LEFT);
感谢任何帮助。
谢谢
首先,整个段落需要缩进到项目符号要缩进的程度 space。然后第一行需要有一个相同宽度的悬挂缩进,所以第一行,其中有项目符号点,总和不缩进。
示例:
import java.io.FileOutputStream;
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.sl.usermodel.*;
import java.awt.Rectangle;
public class CreatePPTXTextBoxBullet {
public static void main(String[] args) throws Exception {
XMLSlideShow slideShow = new XMLSlideShow();
XSLFSlide slide = slideShow.createSlide();
XSLFTextBox textbox = slide.createTextBox();
textbox.setAnchor(new Rectangle(50, 100, 570, 100));
XSLFTextParagraph paragraph = textbox.addNewTextParagraph();
paragraph.setBullet(true);
paragraph.setLeftMargin(25.2); //left margin = indent for the text; 25.2 pt = 25.2/72 = 0.35"
paragraph.setIndent(-25.2); //hanging indent first row for the bullet point; -25.2 pt, so first row indent is 0.00 in sum
paragraph.setFontAlign(TextParagraph.FontAlign.TOP);
paragraph.setTextAlign(TextParagraph.TextAlign.LEFT);
XSLFTextRun run = paragraph.addNewTextRun();
run.setText("Text analysis, nGram, Naïve Bayes Text Classifier to identify the nature of the conversation, sentiment and risk of complaint being made");
FileOutputStream out = new FileOutputStream("CreatePPTXTextBoxBullet.pptx");
slideShow.write(out);
out.close();
}
}
我正在使用 apache poi xslf 创建一个文本框,然后在其中添加一个项目符号。问题是当项目符号点是多行文本时,它会像这样添加
-文本分析、nGram、朴素贝叶斯文本分类器,用于识别对话的性质、情绪和提出投诉的风险
在上面的要点对话中,应与要点行中的文字文本对齐,即像这样的文本对齐方式
- 文本分析、nGram、朴素贝叶斯文本分类器识别
的性质 谈话情绪和被投诉的风险。
代码如下
XSLFTextBox textbox = this.slide.createTextBox();
textbox.setAnchor(new Rectangle(this.xAxis,this.yAxis,this.width,this.height)); XSLFTextParagraph contentPara = textbox.addNewTextParagraph();
XSLFTextRun bullet1TR = contentPara.addNewTextRun(); contentPara.setBullet(true);
contentPara.setFontAlign(FontAlign.TOP); contentPara.setTextAlign(TextAlign.LEFT);
感谢任何帮助。 谢谢
首先,整个段落需要缩进到项目符号要缩进的程度 space。然后第一行需要有一个相同宽度的悬挂缩进,所以第一行,其中有项目符号点,总和不缩进。
示例:
import java.io.FileOutputStream;
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.sl.usermodel.*;
import java.awt.Rectangle;
public class CreatePPTXTextBoxBullet {
public static void main(String[] args) throws Exception {
XMLSlideShow slideShow = new XMLSlideShow();
XSLFSlide slide = slideShow.createSlide();
XSLFTextBox textbox = slide.createTextBox();
textbox.setAnchor(new Rectangle(50, 100, 570, 100));
XSLFTextParagraph paragraph = textbox.addNewTextParagraph();
paragraph.setBullet(true);
paragraph.setLeftMargin(25.2); //left margin = indent for the text; 25.2 pt = 25.2/72 = 0.35"
paragraph.setIndent(-25.2); //hanging indent first row for the bullet point; -25.2 pt, so first row indent is 0.00 in sum
paragraph.setFontAlign(TextParagraph.FontAlign.TOP);
paragraph.setTextAlign(TextParagraph.TextAlign.LEFT);
XSLFTextRun run = paragraph.addNewTextRun();
run.setText("Text analysis, nGram, Naïve Bayes Text Classifier to identify the nature of the conversation, sentiment and risk of complaint being made");
FileOutputStream out = new FileOutputStream("CreatePPTXTextBoxBullet.pptx");
slideShow.write(out);
out.close();
}
}