Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Insert text box
The example shows you how to insert text box in a document.
import com.independentsoft.office.vml.Position; import com.independentsoft.office.vml.Shape; import com.independentsoft.office.vml.ShapeStyle; import com.independentsoft.office.vml.TextBox; import com.independentsoft.office.word.Paragraph; import com.independentsoft.office.word.Run; import com.independentsoft.office.word.VmlObject; import com.independentsoft.office.word.WordDocument; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument(); Run textBoxRun = new Run(); textBoxRun.addText("Simple text inside a textbox"); Paragraph textBoxParagraph = new Paragraph(); textBoxParagraph.add(textBoxRun); TextBox textBox = new TextBox(); textBox.getContent().add(textBoxParagraph); ShapeStyle shapeStyle = new ShapeStyle(); shapeStyle.setPosition(Position.ABSOLUTE); shapeStyle.setWidth("100pt"); shapeStyle.setHeight("75pt"); Shape shape = new Shape(shapeStyle); shape.getContent().add(textBox); VmlObject vmlObject = new VmlObject(); vmlObject.getContent().add(shape); Run run1 = new Run(); run1.add(vmlObject); Paragraph paragraph1 = new Paragraph(); paragraph1.add(run1); doc.getBody().add(paragraph1); doc.save("c:\\test\\output.docx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*