Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Excel Apache POI-包含文本的形状_Java_Apache Poi - Fatal编程技术网

Java Excel Apache POI-包含文本的形状

Java Excel Apache POI-包含文本的形状,java,apache-poi,Java,Apache Poi,我已经创建了一个包含文本字符串的形状。我已经能够将文本框居中,但是我似乎无法将文本框居中对齐 使用ApachePOIV。3.9 例: 我尝试了以下方法: XSSFDrawing drawing = sheet.createDrawingPatriarch(); XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 25, 3, 32); XSSFSimpleShape shape = drawing.createSimple

我已经创建了一个包含文本字符串的形状。我已经能够将文本框居中,但是我似乎无法将文本框居中对齐

使用ApachePOIV。3.9

例:

我尝试了以下方法:

XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 25, 3, 32);
XSSFSimpleShape shape = drawing.createSimpleShape(anchor);
XSSFRichTextString textString = new XSSFRichTextString();
XSSFFont font = workbook.createFont();

font.setColor(HSSFColor.WHITE.index);
shape.setShapeType(ShapeTypes.ELLIPSE);

textString.setString(LeadSheetCoverPage.ADD_YOUR_LOGO.getText(dataStore.getLanguage()));
textString.applyFont(font);

shape.getCTShape().getTxBody().getBodyPr().setAnchor(STTextAnchoringType.CTR);
// This line below doesn't seem to align the Paragraph text to center 
shape.getCTShape().getTxBody().getPList().get(0).getPPr().setAlgn(STTextAlignType.CTR);

shape.setFillColor(211, 211, 211);
shape.setLineStyleColor(0, 0, 0);
shape.setText(textString);

使用当前的
ApachePOI4.1.0
XSSFSimpleShape提供。文本位于
xssftextpragement
s中,其中提供了

例如:

import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;

class CreateExcelShape {

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

  try (XSSFWorkbook workbook = new XSSFWorkbook(); 
       FileOutputStream fileout = new FileOutputStream("Excel.xlsx") ) {

   XSSFSheet sheet = workbook.createSheet();
   XSSFDrawing drawing = sheet.createDrawingPatriarch();
   XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 25, 3, 32);
   XSSFSimpleShape shape = drawing.createSimpleShape(anchor);

   shape.setShapeType(ShapeTypes.ELLIPSE);
   shape.setFillColor(211, 211, 211);
   shape.setLineStyleColor(0, 0, 0);
   shape.setText("The text inside the shape.");

   shape.setVerticalAlignment(VerticalAlignment.CENTER);
   shape.getTextParagraphs().get(0).setTextAlign(TextAlign.CENTER);

   workbook.write(fileout);
  }

 }
}

使用当前的
ApachePOI4.1.0
XSSFSimpleShape提供。文本位于
xssftextpragement
s中,其中提供了

例如:

import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;

class CreateExcelShape {

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

  try (XSSFWorkbook workbook = new XSSFWorkbook(); 
       FileOutputStream fileout = new FileOutputStream("Excel.xlsx") ) {

   XSSFSheet sheet = workbook.createSheet();
   XSSFDrawing drawing = sheet.createDrawingPatriarch();
   XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 25, 3, 32);
   XSSFSimpleShape shape = drawing.createSimpleShape(anchor);

   shape.setShapeType(ShapeTypes.ELLIPSE);
   shape.setFillColor(211, 211, 211);
   shape.setLineStyleColor(0, 0, 0);
   shape.setText("The text inside the shape.");

   shape.setVerticalAlignment(VerticalAlignment.CENTER);
   shape.getTextParagraphs().get(0).setTextAlign(TextAlign.CENTER);

   workbook.write(fileout);
  }

 }
}

对我来说,上述两项都不管用,我也不想升级

CTTextParagraphProperties lv1PPr = 
        shape.getCTShape().getTxBody().getLstStyle().addNewLvl1PPr();
lv1PPr.setAlgn(STTextAlignType.CTR);

出于某种原因,上述方法不起作用,但它在STTextAnchoringType上起作用。

对我起作用的不是上述两种方法,我不想升级

CTTextParagraphProperties lv1PPr = 
        shape.getCTShape().getTxBody().getLstStyle().addNewLvl1PPr();
lv1PPr.setAlgn(STTextAlignType.CTR);

出于某种原因,上述方法不起作用,但它在STTextAnchoringType上起作用。

不是Apache3.9,我也尝试过,它不会将文本居中对齐。shape.getTextPages().get(0.setTextAlign(TextAlign.CENTER);不是Apache3.9,我也尝试过这个,它不会将文本居中对齐。shape.getTextPages().get(0.setTextAlign(TextAlign.CENTER);