meichthys / onenote-html-export

Exports local onenote notebooks in html directory format.
MIT License
5 stars 0 forks source link

Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope]. #1

Closed maphew closed 2 months ago

maphew commented 3 months ago

Out of the box:

.\pwsh --version
PowerShell 7.4.4

.\onenote-powershell-html-export.ps1
InvalidOperation: A:\code\mhw\onenote-html-export\onenote-powershell-html-export.ps1:110
Line |
 110 |  … erarchy("", [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPage …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope].

I tried downloading and installing Microsoft Office 2010: Primary Interop Assemblies Redistributable but that didn't change anything. (Rebooted also).

maphew commented 3 months ago

Additional research uncovered that Powershell core newer than v7.0 cannot load the Office win32 interop libraries :-/

on the other hand, that project has taken a much deeper dive into converting Onenote pages. However I remain to be convinced going to markdown is a good idea. (As handy as md is, it leaves a lot out.) The project is a great resource at any rate.

Running onenote-html-export under Windows Powershell instead of powershell core works somewhat. All of my pages are converted to html, but the images are broken. Attachments such as pdf are left out also, but maybe that was always out of scope for this script.

meichthys commented 3 months ago

I also agree that the markdown export looses alot of formatting that can only really be captured in HTML. TBH, I don't really remember how my images were converted using this script. I don't remember there being too much of a headache, so I assume that they were converted in some way. I'm also not sure about attachments - it's possible i migrated those manually since i did not use attachments heavily in OneNote.

maphew commented 2 months ago

The fastest, easiest, and most solid means I've found is to use the Onemore Addin and it's Archive or Export commands: https://onemoreaddin.com/commands/File%20Commands.htm.

meichthys commented 2 months ago

@maphew This looks like a great tool. Does it preserve the note heierarchy? Were there any changes you needed to make after exporting and then importing into Trilium? If this is a smooth migration path we should definitely document it in our TriliumNext/Docs repo

maphew commented 2 months ago

I've only imported a couple of test sections so far, but no significant problems noticed. Trilium appends .htm to the note title, which is annoying as it doesn't do that for .html. I haven't decided if I'll write a small script to rename the pages in the zips before import or try and patch Trilium to recognize the short form. I haven't looked yet at what happens with cross page/section/notebook links after importing.

In Onemore,

meichthys commented 2 months ago

@maphew No need to worry about the .htm in the note title. You can simply fix that in Trilium. Just open search, select Action > rename note and paste in ${note.title.replace(".htm","")} to the rename note title to: field and click search and execute actions (be careful (take a backup first).