Independentsoft
Any library, any programming language
Home
Purchase
Support
Company
Contact
JODF
>
Tutorial
> Set field value
The following example shows you how to set SimpleVariableSetField field value.
import java.util.List; import com.independentsoft.office.odf.Paragraph; import com.independentsoft.office.odf.TextDocument; import com.independentsoft.office.odf.fields.SimpleVariableSetField; public class Example { public static void main(String[] args) { try { TextDocument doc = new TextDocument("c:\\test\\input.odt"); List
paragraphs = doc.getParagraphs(); for (int i = 0; i < paragraphs.size(); i++) { for (int j = paragraphs.get(i).getContent().size()- 1; j >= 0; j--) { if (paragraphs.get(i).getContent().get(j) instanceof SimpleVariableSetField) { SimpleVariableSetField field = (SimpleVariableSetField)paragraphs.get(i).getContent().get(j); if (field.getName().equals("CustomerID")) { field.setValue("12345"); } } } } doc.save("c:\\test\\output.odt", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*