You can find more details at: Create a To-Do List in a OneNote Document (.ONE) in Java
Last active
March 16, 2022 08:17
-
-
Save aspose-com-gists/0f9c500de0130dc928f2978b7cc13cb2 to your computer and use it in GitHub Desktop.
Create To Do list on OneNote using Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set styles for paragraph and header text | |
ParagraphStyle headerStyle = new ParagraphStyle(); | |
headerStyle.setFontName("Calibri"); | |
headerStyle.setFontSize(16); | |
ParagraphStyle bodyStyle = new ParagraphStyle(); | |
bodyStyle.setFontName("Calibri"); | |
bodyStyle.setFontSize(12); | |
// Get date to create onenote to do list with dates | |
java.text.DateFormat dateFormat = java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT, Locale.US); | |
// Create an object of the Document class | |
Document document = new Document(); | |
RichText titleText = new RichText(); | |
titleText.setText(String.format("Plan %s", dateFormat.format(java.util.Date.from(Instant.now())))); | |
titleText.setParagraphStyle(ParagraphStyle.getDefault()); | |
// Set the title | |
Title title = new Title(); | |
title.setTitleText(titleText); | |
Page page = new Page(); | |
page.setTitle(title); | |
document.appendChildLast(page); | |
// Set offset values | |
Outline outline = page.appendChildLast(new Outline()); | |
outline.setVerticalOffset(30); | |
outline.setHorizontalOffset(30); | |
// Set styles and add text | |
RichText richText = outline.appendChildLast(new OutlineElement()).appendChildLast(new RichText()); | |
richText.setText("TO DO"); | |
richText.setParagraphStyle(headerStyle); | |
richText.setSpaceBefore(15); | |
// Add checkbox and TO DO tasks | |
for (String e: new String[] { "First Task", "Second Task", "Third Task" }) | |
{ | |
OutlineElement outlineElement = outline.appendChildLast(new OutlineElement()); | |
richText = outlineElement.appendChildLast(new RichText()); | |
richText.setText(e); | |
richText.setParagraphStyle(bodyStyle); | |
richText.getTags().add(NoteCheckBox.createBlueCheckBox()); | |
} | |
// Save output OneNote document with TO DO tasks | |
document.save(dataDir + "TODOonenote.one"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment