I want create a text box in a document .docx but I didn´t find a method that help me do it and any example. Someone know how can i do it?
标签:
apache-poi
相关问题
- android apache poi-ooxml causes build error 'a
- Error: How to read empty cell in Excel
- Why we need to create a Workbook before reading th
- Does anyone have an example of Apache POI converti
- How to store time spent or total duration in Java?
相关文章
- How to loop through all the rows and cells in an e
- Java Apache POI newline characters are ignored whe
- How to know number of sheets in a workbook?
- How to Highlight a text for a Pargraph in MS word
- How to use Tika's XWPFWordExtractorDecorator c
- How to move position of chart in excel by Java POI
- Apache POI - Invalid part to process data
- Updating Excel sheet values based on a csv sheet w
Inserting a real
Word
Text-box is not fully possible withapache-poi
until now. A realWord
Text-box is contained in aCTShape
fromschemasMicrosoftComVml
orcom.microsoft.schemas.vml
. The XML looks like:As you see the namespaces in
v:shape
andv:textbox
are different from the rest.So if we know and respect this, we can currently insert such
CTShape
. But only inline with the text. Creating aCTWrap
for this is currently not possible, as far as I know, because theCTWrap
from theschemasMicrosoftComOfficeWord
is not shipped within the poi-ooxml-schemas-3.13-*.jar and thecom.microsoft.schemas.vml
andcom.microsoft.schemas.office
classes from ooxml-schemas-1.3.jar need aorg.apache.poi.POIXMLTypeLoader
which is not shipped with version 3.13.Example for an inline Textbox:
But a positioned text-frame is possible:
This needs the fully ooxml-schemas-1.3.jar as mentioned in https://poi.apache.org/faq.html#faq-N10025.
Edit
If we downgrade to ooxml-schemas-1.1.jar - available from http://search.maven.org/#artifactdetails|org.apache.poi|ooxml-schemas|1.1|jar - then a free positionable Text-box is also possible with
apache-poi
version 3.13.For HWPF (i.e. the old binary doc format) there is a very rudimentary interface via
HWPFDocument.getMainTextBoxRange()
. I believe it is only suitable for reading, though.For XWPF (the newer docx format that you asked for) it appears that Text Boxes are always embedded in a Drawing (using DrawingML; please correct me if I am wrong). At least this is how I interpret clauses 17.3.1.40, 20.4.2.37 and 20.4.2.38 of ECMA-376, Part 1. Thus, your method of choice should be
XSSFDrawing.createTextbox()
. However, I haven't yet come across an easy to use link between this drawing class (which stems from POI's Excel component) and XWPF.