Git Product home page Git Product logo

richpaste's Introduction

RichPaste

OneNote 2016 Addin - Paste Rich Text Into Your Notebook!

To install addin - click on 'RichPasteInstall.msi' above and download

If you have any further questions or would like to contact me then send me an email at [email protected]


#Tutorial

Contents

Creating The Ribbon Button

How OneNote Pages Are Structured/Stored

How To Use The OneNote API


Creating The Ribbon Button

To start off the addin simply follow this guide: http://www.malteahrens.com/#/blog/howto-onenote-dev/

Most of the guide is still relevant to OneNote 2016 but there are some notable changes:

  1. Use .Net version 4.5 instead of the newer 4.5.2 etc (in Project Properties >> Application >> Target Framework). Your compiler will probably warn you to do this anyway.

  2. When you add the assemblies you'll need the following COM assemblies (for Office 2016)

    1. Microsoft OneNote 15.0 Object Library
    2. Microsoft Office 16.0 Object Library
  3. It is mentioned in the guide but you have to turn off the 'Embed Interop Types' from the OneNote Assembly (hit F4 on the reference)

  4. Installer Templates aren't in the standard install of Visual Studio 2015, but you can download the templates here: https://visualstudiogallery.msdn.microsoft.com/f1cc3f3e-c300-40a7-8797-c509fb8933b9

  5. [On 64bit machine] When adding the registry keys you will also have to add the keys to your WOW6432Node Folders (see RegKeysImport.reg for examples)

  6. [On 64bit machine] You'll also have to change the output type on the Setup project to x64 (hit F4 on the project)

  7. To build the Setup project along with the Class Libraries you'll need to go into 'Build' >> 'Configuration Manager' and tick 'Build' next to the Setup project

  8. This might not be a problem for everyone but in my solution the addin would always fail on load up if I had any "Microsoft.Office.Interop.OneNote.Application" references/objects in my start up Class (the one with your ProgID and GUID). I recommend leaving them out of the startup class and just using them in classes that the startup one uses.



How OneNote Pages Are Structured/Stored

OneNote pages are stored in XML. We can view and edit this XML to update our pages.

The basic structure is:

<Page>
    <Title>
        <OE>
            <T>
                <![CDATA[ PAGE TITLE ]]>
            </T>
        </OE>
    </Title>
    
    <Outline >
        <Position x="35.0" y="60.0"/>"                                  
        <Size width="750.75" height="13.50" />        
    
            <OEChildren>
                <OE>
                    <T>
                        <![CDATA[ PAGE CONTENT ]]>
                    </T>
                </OE>
            </OEChildren>
    
    </Outline>
</Page>

So obviously the CDATA[] between the "Title" tags is the page's name.

The Outline tags specify a new box of content on the page that you can move around.

The OEChildren belong to the Outline tags that it is between, there are usually only one OEChildren tag per Outline, but OEChildren can contain as many OE tags as you'd like.

And the OE, T and CDATA represent lines within the content box. For each line you'll have a seperate CDATA[].

Each OE contains Attributes regarding who created it, when it was created, and a unique object reference id.

This reference it contains

1) A GUID   (You can create GUIDs using NewGUID() method)
2) A object number  (This increments from the number of the previous object)
3) A notebook hex number (I think, not 100% sure but I know that this doesn't change for me on all my pages)

Special formats add in additional tags (like bullet points adds a "Bullet" tag)... but these are the basics and all you need to understand to start editing your pages.

OneNote contains your Page's text within the CDATA[] tag in HTML. This is why some Paste functions work (like copy/pasteing from MS Word) and why Rich Text doesn't (there is no standard RTF to HTML convertion done)


How To Use The OneNote API

Once you've got the ribbon created and understand OneNotes data structure you'll want to start querying your own OneNote.

In your solution first create an instance of the OneNote application:

var oneNote = new Microsoft.Office.Interop.OneNote.Application();

Notice the fully qualified name, that is because you will most likely have another type of Application in one of your assemblies and you'll have to specify that you want OneNotes API.

One tip is that you can state that you specifically want oneNotes API in a using statement:

using Application = Microsoft.Office.Interop.OneNote.Application;

That way the first row (and any other OneNote app declarations) can be simplified down to just:

var oneNote = new Application();

Now that you have an instance of the onenote API you can start using their methods.

There is a great big list of them all here: https://msdn.microsoft.com/en-us/library/office/gg649853(v=office.14).aspx

Most of them are pretty straight forward, but the few that I believe to be the most useful are actually not on the list.

I'm talking about getting the current NoteBook/Section/Page

These methods are a little more hidden. Here they are listed below:

string currentOpenNoteBook = oneNote.Windows.CurrentWindow.CurrentNotebookId;
string currentOpenSection  = oneNote.Windows.CurrentWindow.CurrentSectionId;    
string currentOpenPage = oneNote.Windows.CurrentWindow.CurrentPageId;

With the above ID's you can then use the GetHierarchy()/ GetPageContent()/ UpdatePageContent() methods to edit your onenote programmatically.

richpaste's People

Contributors

samueloconnor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

jaywick

richpaste's Issues

Add-in does not appear on the ribbon

Add-in does not appear on the ribbon

Description.
I downloaded the add-on https://github.com/SamuelOConnor/RichPaste
I ran "RichPasteInstall.msi".
Result: The installation was successful.
I ran "RegKeysImport.reg"
Result: The installation was successful.

Question.
How do I display an add-in on the ribbon?

Used.
Win - 7x64
OneNote 2016 x64 for Office 365 MSO (16.0.12527.20986) (Version 2002 (Build 12527.20988))

Picture-1
2020-08-15_13-27-51

Picture-2
2020-08-15_13-28-14

Failed to Install

The RichPasteInstall.msi installer completed sucessfully but the addin did not appear in OneNote in
File > Options > AddIns.
I'm running OneNote 2016 32 bit on Windows 7 Enterprise 64 bit.

Thanks

How do I connect an add-in for OneNote?

Question.
How do I connect an add-in for OneNote?
When I add an add-in to OneNote I get an error: "This is not a valid Office Add-in"

Description.
I am using the project: "Class Library (.NET Framework)".
I have created an add-on.
I added libraries:

  • "Extensibility";
  • "Microsoft.Office.Interop.Excel" (version 16);
  • "System.Windows.Forms";
  • COM: Microsoft Office 16.0 Object Library.

I added a class: MyConnect.cs.
I added a file: Ribbon.xml.
I added the add-on to the registry.
I am adding an add-in to OneNote
Result:
Error:
C:\test\AddinOneNoteClassLibrary01\p01\AddinOneNoteClassLibrary01.dll "is not a valid Office add-in.

Used.

  • .NET Framework 4.7.2
  • win 7x64
  • MS Office 2016
  • OneNote 2016 x64 for Office 365 MSO (16.0.12527.20986) (Version 2002 (Build 12527.20988))

RegKeysImport.reg
`Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\AppID{C33CAD6D-E14D-45D5-94E5-6A9861061129}]
"DllSurrogate"=""

[HKEY_CLASSES_ROOT\AddinOneNoteClassLibrary01.MyConnect\CLSID]
"(Default)"="{C33CAD6D-E14D-45D5-94E5-6A9861061129}"

[HKEY_CLASSES_ROOT\CLSID{C33CAD6D-E14D-45D5-94E5-6A9861061129}]
"AppID"="{C33CAD6D-E14D-45D5-94E5-6A9861061129}"

[HKEY_CLASSES_ROOT\WOW6432Node\AppID{C33CAD6D-E14D-45D5-94E5-6A9861061129}]
"DllSurrogate"=""

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID{C33CAD6D-E14D-45D5-94E5-6A9861061129}]
"(Default)"="AddinOneNoteClassLibrary01.MyConnect"
"AppID"="{C33CAD6D-E14D-45D5-94E5-6A9861061129}"

[HKEY_CURRENT_USER\Software\Classes\AppID{C33CAD6D-E14D-45D5-94E5-6A9861061129}]
"DllSurrogate"=""

[HKEY_CURRENT_USER\Software\Classes\AddinOneNoteClassLibrary01.MyConnect\CLSID]
"(Default)"="{C33CAD6D-E14D-45D5-94E5-6A9861061129}"

[HKEY_CURRENT_USER\Software\Classes\WOW6432Node\CLSID{C33CAD6D-E14D-45D5-94E5-6A9861061129}]
"(Default)"="AddinOneNoteClassLibrary01.MyConnect"
"AppID"="{C33CAD6D-E14D-45D5-94E5-6A9861061129}"

[HKEY_CURRENT_USER\Software\Classes\CLSID{C33CAD6D-E14D-45D5-94E5-6A9861061129}]
"AppID"="{C33CAD6D-E14D-45D5-94E5-6A9861061129}"

[HKEY_LOCAL_MACHINE\Software\Classes\AppID{C33CAD6D-E14D-45D5-94E5-6A9861061129}]
"DllSurrogate"=""

[HKEY_LOCAL_MACHINE\Software\Classes\CLSID{C33CAD6D-E14D-45D5-94E5-6A9861061129}]
"AppID"="{C33CAD6D-E14D-45D5-94E5-6A9861061129}"

[HKEY_LOCAL_MACHINE\Software\Microsoft\Office\OneNote\AddIns\AddinOneNoteClassLibrary01.MyConnect]
"Description"="Description - AddinOneNoteClassLibrary01 MyConnect"
"FriendlyName"="AddinOneNoteClassLibrary01"
"LoadBehavior"=dword:00000003`

MyConnect.cs
`namespace AddinOneNoteClassLibrary01
{

[System.Runtime.InteropServices.ProgId("ExcelCOMAddin.MyConnect")]
[System.Runtime.InteropServices.ComDefaultInterface(typeof(IMyConnect))]
// [System.Runtime.InteropServices.Guid("DE3911A1-C82F-42F1-BEFB-F3802E1B6D34")]
[System.Runtime.InteropServices.Guid("C33CAD6D-E14D-45D5-94E5-6A9861061129")]
[System.Runtime.InteropServices.ClassInterface(
    System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
public class MyConnect : IMyConnect
{
    Microsoft.Office.Interop.OneNote.Application _ApplicationObject;
    Microsoft.Office.Core.COMAddIn _AddinInstance;

    public void OnConnection(
        object Application,
        Extensibility.ext_ConnectMode ConnectMode,
        object AddInInst,
        ref Array custom)
    {
        this._ApplicationObject = (Microsoft.Office.Interop.OneNote.Application)Application;

        if (this._AddinInstance == null)
        {
            this._AddinInstance = (Microsoft.Office.Core.COMAddIn)AddInInst;
            this._AddinInstance.Object = this;
        }

        System.Windows.Forms.MessageBox.Show("onConnection");
    }
    public void OnDisconnection(
        Extensibility.ext_DisconnectMode RemoveMode,
        ref Array custom)
    {
        this._ApplicationObject = null;
        this._AddinInstance = null;
    }
    public void OnAddInsUpdate(ref Array custom)
    { }
    public void OnStartupComplete(ref Array custom)
    { }
    public void OnBeginShutdown(ref Array custom)
    { }

    //public string GetCustomUI(string RibbonID)
    //{
    //    return "";
    //}


    public string GetCustomUI(string RibbonID)
    {
        return GetResourceText("COMExcelModelCover.Ribbon.xml");
    }

    private static string GetResourceText(string resourceName)
    {
        System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
        string[] resourceNames = asm.GetManifestResourceNames();

        for (int i = 0; i < resourceNames.Length; ++i)
        {
            if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
            {
                using (System.IO.StreamReader resourceReader = new System.IO.StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
                {
                    if (resourceReader != null)
                    {
                        return resourceReader.ReadToEnd();
                    }
                }
            }
        }
        return null;
    }

    public void Button_One_Click(Microsoft.Office.Core.IRibbonControl control)
    {
        System.Windows.Forms.MessageBox.Show("Button_One_Clicked");
    }

    public void Button_Two_Click(Microsoft.Office.Core.IRibbonControl control)
    {
        System.Windows.Forms.MessageBox.Show("Button_Two_Clicked");
    }


}`

Ribbon.xml

<?xml version="1.0" encoding="utf-8" ?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
	<ribbon>
		<tabs>
			<tab id="MyNewRibbonTab"
					  insertBeforeMso="TabInsert"
					  label="BETTER">
				<group id="Group_ID_One" label="MyGroup">
					<button id="Button_ID_One"
								  imageMso="Help"
								  onAction="Button_One_Click"
								  label="Button 1"
								  size="large"/>
					<separator id="Separator_ID_One"/>
					<button id="Button_ID_One"
								  imageMso="Help"
								  onAction="Button_One_Click"
								  label="Button 1"
								  size="large"/>
				</group>
			</tab>
		</tabs>
	</ribbon>
</customUI>

Picture-1
2020-08-15_16-06-59

Picture-2
2020-08-15_18-22-05

Picture-3
2020-08-15_18-24-16

Picture-4
HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\Addins\AddinOneNoteClassLibrary01.MyConnect
2020-08-15_18-27-14

Picture-5
2020-08-15_18-28-34

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.