General

Components

Community

Development

TDF

Documents > Cookbook >Fields



Variable Field
You can use the following code to create a variable field, and set the value.

			TextDocument doc = TextDocument.newTextDocument();
Paragraph paragraph = doc.addParagraph("test_con_variable:");
VariableField simpleVariableField = Fields.createSimpleVariableField(doc, "test_con_variable");
simpleVariableField.updateField("true", paragraph.getOdfElement());

Following code can be used to set value to variable field, and append it to an ODF element.

			simpleVariableField.updateField("user variable content", null);
simpleVariableField.displayField(paragraph.getOdfElement());


Condition Field
Following code can be used to create a condition field.

			Paragraph newParagraph = doc.addParagraph("Condition Field Test:");
ConditionField conditionField = Fields.createConditionField(newParagraph.getOdfElement(), "test_con_variable == \"true\"",
"trueText", "falseText");


Hidden Field
Following code can be used to create a hidden field.

			newParagraph = doc.addParagraph("Hide Text Field Test:");
conditionField = Fields.createHiddenTextField(newParagraph.getOdfElement(), "test_con_variable == \"true\"", "hiddenText");


Cross Reference Field
Following code can be used to create a reference field.

			OdfElement newTextSpanElement = ((TextPElement)doc.addParagraph("Reference Content:").getOdfElement()).newTextSpanElement();
newTextSpanElement.setTextContent("This is a test reference content.");
ReferenceField referenceField = Fields.createReferenceField(newTextSpanElement, "test-ref");

Following code can be used to append a reference field.

			referenceField.appendReferenceTo(doc.addParagraph("User Reference Field:").getOdfElement(), ReferenceField.DisplayType.TEXT);


Chapter Field
Following code can be used to create a chapter field.

			ChapterField chapterField = Fields.createChapterField(doc.addParagraph("Chapter:").getOdfElement());


Title and Subject Field
Following code can be used to create a title field.

			TitleField titleField = Fields.createTitleField(doc.addParagraph("The Title:").getOdfElement());

Following code can be used to create a subject field.

			SubjectField subjectField = Fields.createSubjectField(doc.addParagraph("The Subject:").getOdfElement());


Author Field
Following code can be used to create a author initial field and a author name field.

			AuthorField authorField = Fields.createAuthorInitialsField(doc.addParagraph("The initials of the author :").getOdfElement());
authorField = Fields.createAuthorNameField(doc.addParagraph("Author:").getOdfElement());


Page Number Field
Following code can be used to create a current page number field.

			PageNumberField numberField = Fields.createCurrentPageNumberField(doc.addParagraph("Current Page Number:").getOdfElement());
numberField.setNumberFormat(NumberFormat.UPPERCASE_LATIN_ALPHABET);
numberField.setDisplayPage(DisplayType.NEXT_PAGE);

Following code can be used to create a previous page number and a next page number field.

			numberField = Fields.createPreviousPageNumberField(doc.addParagraph("Previous Page Number:").getOdfElement());
numberField = Fields.createNextPageNumberField(doc.addParagraph("Next Page Number:").getOdfElement());


Page Number Field
Following code can be used to create a page count field, and set the number format.

			PageCountField countField = Fields.createPageCountField(doc.addParagraph("Page Count:").getOdfElement());
countField.setNumberFormat(NumberFormat.UPPERCASE_LATIN_ALPHABET);


Date Field
Following code can be used to create a date field, and set the format.

			DateField dateField = Fields.createDateField(doc.addParagraph("Date:").getOdfElement());
dateField.formatDate("yy-MM-dd");


Time Field
Following code can be used to create a time field, and set the format.

			TimeField timeField = Fields.createTimeField(doc.addParagraph("Time:").getOdfElement());
timeField.formatTime("HH:mm:ss a");


Impressum (Legal Info) | Privacy Policy (Datenschutzerklärung) | Statutes (non-binding English translation) - Satzung (binding German version) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Apache License, v2.0. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License v2.0. “LibreOffice” and “The Document Foundation” are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy. LibreOffice was based on OpenOffice.org.