Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active March 16, 2022 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/0f9c500de0130dc928f2978b7cc13cb2 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/0f9c500de0130dc928f2978b7cc13cb2 to your computer and use it in GitHub Desktop.
Create To Do list on OneNote using Java
// 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