addDateAndHour
- addBackgroundImage
- addFooter
- addHeader
- addLineNumbering
- addPageBorders
- addProperties
- addSection
- createDocx
- createCharacterStyle
- createListStyle
- createParagraphStyle
- createTableStyle
- docxSettings
- embedFont
- importHeadersAndFooters
- importStyles
- modifyPageLayout
- removeFooters
- removeHeaders
- setBackgroundColor
- setDefaultFont
- setDocumentDefaultStyles
- setEncodeUTF8
- setLanguage
- setMarkAsFinal
- setRTL
- addBibliography
- addBookmark
- addBreak
- addChart
- addCitation
- addComment
- addCrossReference
- addDateAndHour
- addEndnote
- addExternalFile
- addFootnote
- addFormElement
- addHeading
- addImage
- addLink
- addList
- addMathEquation
- addMergeField
- addOLE
- addPageNumber
- addShape
- addSimpleField
- addSource
- addStructuredDocumentTag
- addTable
- addTableContents
- addText
- addTextBox
- addWordML
- embedHTML
- clearBlocks
- deleteTemplateBlock
- getTemplateVariables
- getTemplateVariablesType
- modifyInputFields
- modifyMergeFields
- processTemplate
- removeTemplateVariable
- replaceListVariable
- replacePlaceholderImage
- replaceTableVariable
- replaceVariableByExternalFile
- replaceVariableByHtml
- replaceVariableByText
- replaceVariableByWordFragment
- replaceVariableByWordML
- setTemplateSymbol
- tickCheckbox
addDateAndHour
BASIC / ADVANCED / PREMIUM
Inserts the current date and/or hour into the Word document.
Description
public void addDateAndHour(OptionsDateAndHour options) throws Exception
This method allows the insertion of the current date and/or hour in different formats.
The default format is dd/MM/yyyy H:mm:ss that will render something like 30/01/2014 7:35:48, where:
- dd stands for the day in two digit format
- MM stands for the month in two digit format
- yyyy stands for the year in 4 digit format
- H, mm and ss correspond to hours, minutes and seconds respectively
This default format can be changed at will through the format option. For example, if you use as format: dd' of 'MMMM' of 'yyyy' at 'HH:mm', it will result in something like this: 30 of January of 2014 at 07:35.
The DOCX standard offers us multiple possibilities that may be explored via this link.
The most usual options are summarized in the following table:
Format Specifier | Description |
---|---|
d | The day of the month: 1 to 31 |
dd | The day of the month: 01 to 31 |
ddd | The day of the month: short name |
dddd | The day of the month: full name |
M | The month of the year: 1 to 12 |
MM | The month of the year: 01 to 12 |
MMM | The month of the year: short name |
MMMM | The month of the year: full name |
y | The year (max. two digits): 0 to 99 |
yy | The year (two digits): 00 to 99 |
yyyy | The year (four digits) |
h | The hour of the day (12 hours clock): 1 to 12 |
hh | The hour of the day (12 hours clock): 01 to 12 |
H | The hour of the day: 1 to 23 |
HH | The hour of the day: 01 to 23 |
m | The minutes: 1 to 59 |
mm | The minutes: 01 to 59 |
s | The seconds: 1 to 59 |
ss | The seconds: 01 to 59 |
tt | AM or PM |
You may also include the date and hour within other element (paragraph, table, header, footer...) creating a WordFragment.
Parameters
options
Option | Type | Description |
---|---|---|
dateFormat | String | A string with the required date format. The default value is: dd/MM/yyyy H:mm:ss. |
Option | Type | Description |
---|---|---|
pStyle | String | Word style to be used. |
backgroundColor | String | Hexadecimal color value: FF0000, 000000... |
bidi | Boolean | Sets to true for right to left languages like Hebrew or Arabic. |
bold | Boolean | If true the text will be shown in bold characters. |
border | String | Available values are:
|
borderBottom | String | Overwrites the general border type for the bottom border of the paragraph. |
borderLeft | String | Overwrites the general border type for the left border of the paragraph. |
borderTop | String | Overwrites the general border type for the top border of the paragraph. |
borderRight | String | Overwrites the general border type for the right border of the paragraph. |
borderColor | String | Hexadecimal color value: FF0000, 000000... |
borderBottomColor | String | Overwrites the general border color for the bottom border of the paragraph. |
borderLeftColor | String | Overwrites the general border color for the left border of the paragraph. |
borderTopColor | String | Overwrites the general border color for the top border of the paragraph. |
borderRightColor | String | Overwrites the general border color for the right border of the paragraph. |
borderSpacing | Integer | Separation between border and text in points. |
borderBottomSpacing | Integer | Overwrites the general border spacing for the bottom border of the paragraph. |
borderLeftSpacing | Integer | Overwrites the general border spacing for the left border of the paragraph. |
borderTopSpacing | Integer | Overwrites the general border spacing for the top border of the paragraph. |
borderRightSpacing | Integer | Overwrites the general border spacing for the right border of the paragraph. |
borderWidth | Integer | Border width in eigths of a point. |
borderBottomWidth | Integer | Overwrites the general border width for the bottom border of the paragraph. |
borderLeftWidth | Integer | Overwrites the general border width for the left border of the paragraph. |
borderTopWidth | Integer | Overwrites the general border width for the top border of the paragraph. |
borderRightWidth | Integer | Overwrites the general border width for the right border of the paragraph. |
caps | Boolean | If true displays text in capital letters. |
color | String | Hexadecimal color value: "FF0000", "000000"... |
contextualSpacing | String | Ignores spacing above and below the paragraph whenever the neighbouring paragraphs use the same Word style. |
doubleStrikeThrough | Boolean | If true displays text in doubleStrikeThrough. |
em | String | Emphasis mark type: "none", "dot", "circle", "comma", "underDot". |
firstLineIndent | Integer | First line indentation in twentieths of a point (twips). |
font | String | Font family: "Arial", "Calibri"... |
fontSize | Integer | Font size in points. |
hanging | Integer | Paragraph hanging in twentieths of a point (twips). |
headingLevel | Integer | The heading level if you want this paragraph to be a heading. |
italic | Boolean | If true displays the text in italics. |
indentLeft | Integer | Left margin in points. |
indentRight | Integer | Right margin in points. |
keepLines | Boolean | Keeps (whenever possible) all the current paragraph lines on the same page (default value is false). |
keepNext | Boolean | Keeps (whenever possible) in the same page the current paragraph with next paragraph (default value is false). |
lineSpacing | Integer | 120, 240 (standard), 360, 480... (in twentieths of a point). |
pageBreakBefore | Boolean | If true forces a page break before the paragraph. |
primaryStyle | Boolean | If true sets as primary style. | position | Integer | Position value. Positive value for raised and negative value for lowered. |
rtl | Boolean | Sets to true for right to left languages like Hebrew or Arabic. |
scaling | Integer | Scaling value, 100 is the default value. |
semiHidden | Boolean | If true sets as semihidden style. |
smallCaps | Boolean | If true displays text in small capital letters. |
spacingBottom | Integer | Bottom padding in twentieths of a point. |
spacingTop | Integer | Top padding in twentieths of a point. |
strikeThrough | Boolean | If true displays text in strikethrough. |
tabPositions | ArrayList<HashMap<String, String>> | Each entry is a HashMap array with the following keys and values:
|
textAlign | String | Text alignment within paragraph. Possible values are: center, right, both and distribute. |
textDirection | String | Text flow direction within a table cell. Possible values are: lrTb, tbRl, btLr, lrTbV, tbRlV and tbLrV. |
underline | String | Underlines text. Possible values are: single, words, double, dotted, dash and wave. |
underlineColor | String | Underlines text with a color: "FF0000", "000000"... |
vanish | Boolean | Uses a vanish style. |
widowControl | Boolean | Prevents Word from printing the last line of a paragraph by itself at the top of the page (widow) or the first line of a paragraph at the bottom of a page (orphan). |
wordWrap | Boolean | Allows line breaking at character level (default value is false). |