mirror of https://github.com/apache/poi.git
github-7 - Form check box extraction with XWPFWordExtractor
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1636990 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9bb00e4228
commit
ac57e34264
|
@ -34,42 +34,13 @@ import org.apache.xmlbeans.XmlObject;
|
||||||
import org.apache.xmlbeans.XmlString;
|
import org.apache.xmlbeans.XmlString;
|
||||||
import org.apache.xmlbeans.XmlToken;
|
import org.apache.xmlbeans.XmlToken;
|
||||||
import org.apache.xmlbeans.impl.values.XmlAnyTypeImpl;
|
import org.apache.xmlbeans.impl.values.XmlAnyTypeImpl;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
|
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualPictureProperties;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
|
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPictureNonVisual;
|
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPictureNonVisual;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
|
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
|
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColor;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColor;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEmpty;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdnRef;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHpsMeasure;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPTab;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSignedHpsMeasure;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTUnderline;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalAlignRun;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrType;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
|
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
import org.w3c.dom.Text;
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
|
@ -894,6 +865,22 @@ public class XWPFRun implements ISDTContents, IRunElement{
|
||||||
text.append(((CTText) o).getStringValue());
|
text.append(((CTText) o).getStringValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Complex type evaluation (currently only for extraction of check boxes)
|
||||||
|
if(o instanceof CTFldChar) {
|
||||||
|
CTFldChar ctfldChar = ((CTFldChar)o);
|
||||||
|
if(ctfldChar.getFldCharType() == STFldCharType.BEGIN) {
|
||||||
|
if(ctfldChar.getFfData() != null) {
|
||||||
|
for(CTFFCheckBox checkBox : ctfldChar.getFfData().getCheckBoxList()) {
|
||||||
|
if(checkBox.getDefault().getVal() == STOnOff.X_1) {
|
||||||
|
text.append("|X|");
|
||||||
|
} else {
|
||||||
|
text.append("|_|");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (o instanceof CTPTab) {
|
if (o instanceof CTPTab) {
|
||||||
text.append("\t");
|
text.append("\t");
|
||||||
|
|
|
@ -397,4 +397,17 @@ public class TestXWPFWordExtractor extends TestCase {
|
||||||
extractor.getText();
|
extractor.getText();
|
||||||
extractor.close();
|
extractor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCheckboxes() throws IOException {
|
||||||
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("checkboxes.docx");
|
||||||
|
System.out.println(doc);
|
||||||
|
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
|
||||||
|
|
||||||
|
assertEquals("This is a small test for checkboxes \nunchecked: |_| \n" +
|
||||||
|
"Or checked: |X|\n\n\n\n\n" +
|
||||||
|
"Test a checkbox within a textbox: |_| -> |X|\n\n\n" +
|
||||||
|
"In Table:\n|_|\t|X|\n\n\n" +
|
||||||
|
"In Sequence:\n|X||_||X|\n", extractor.getText());
|
||||||
|
extractor.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue