Change Text Style in OneNote using C# | Change Font Style

OneNote is a powerful tool for taking notes, organizing information, and collaborating with others. One common use case for changing text style in OneNote is to highlight key points or headings in our notes. By changing the font size, color, or style of certain text, we can make it stand out and draw attention to important information. In this article, we will learn how to programmatically change text style in OneNote using C#.

This article covers the following topics:

  1. C# OneNote API to Change Text Styles
  2. Create a Page Title with Text Style
  3. Change the Text Style of a Page Title
  4. Change the Text Style of Paragraphs
  5. Set Default Paragraph Style
  6. Free Learning Resources

C# OneNote API to Change Text Styles

To change the text style in OneNote using C#, we will use the Aspose.Note for .NET API. It allows to create, modify, and convert OneNote documents programmatically in .NET applications.

Please download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.Note

Create OneNote Page Title with Text Style in C#

We can create a page title in a OneNote document by following the steps below:

  1. Create a new OneNote document using the Document class.
  2. Add a new page using the Page class.
  3. Create a title using the Title class.
  4. Specify the title text, date, and time using the RichText class.
  5. Set the ParagraphStyle property of the RichText class object to define its font name, size, color, etc.
  6. Finally, save the document using the Save method.

The following code sample shows how to create a page title with styles in a OneNote document using C#.

Create OneNote Page Title with Text Style in C#

Create OneNote Page Title with Text Style in C#.

Change Text Style of a Page Title in C#

We can change the text style of page titles in OneNote documents by following the steps below:

  1. Load an existing OneNote document using the Document class.
  2. Loop through all the page titles in a document.
  3. Modify the ParagraphStyle properties for each title.
  4. Alternatively, modify the Style properties of TextRuns for each title.
  5. Finally, save the document using the Save method.

The following code sample shows how to change the text style of a page title in a OneNote document using C#.

Change Text Style of a Page Title in C#

Change Text Style of a Page Title in C#.

Change Text Style of OneNote Paragraphs in C#

We can change the text style of paragraphs in OneNote documents by following the steps below:

  1. Load the OneNote document using the Document class.
  2. Get a particular or all RichText nodes using the GetChildNodes() method.
  3. Modify the Style properties e.g. FontColor, Highlight, FontSize, etc. of TextRuns for the RichText node(s).
  4. Finally, save the document using the Save method.

The following code sample shows how to change the text style of a paragraph in a OneNote document using C#.

Change Text Style of OneNote Paragraphs in C#

Change Text Style of OneNote Paragraphs in C#.

Set Default Paragraph Style in OneNote using C#

We can also set a default paragraph style in a OneNote document by following the steps below:

  1. Create a new document using the Document class.
  2. Create a new page using the Page class.
  3. Initialize Outline and OutlineElement class objects.
  4. Create a RichText class object and specify ParagraphStyle.
  5. After that, append child elements.
  6. Finally, save the document using the Save method.

The following code sample shows how to set the default paragraph style of a paragraph in a OneNote document using C#.

Get a Free License

You can get a free temporary license to try the library without evaluation limitations.

Change Font Style – Learning Resources

Besides changing text and font styles in a OneNote document, explore various other features of the library using the resources below:

Conclusion

In this article, we have learned how to change the text styles of page titles or paragraphs in OneNote documents. We have also seen how to add a page title with a text style programmatically in C#. By leveraging Aspose.Note for .NET, you can easily integrate such functionality into your applications. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also