In order to collect output from a logging script, I would like to use onepy to add information to a OneNote 2013 notebook. Unfortunately, the method update_page_content()
provided by onepy doesn't work for me. To get a deeper understanding of the problem, I switched over to C#, where many online examples for the OneNote API exist and after some trouble I managed to get the following minimalistic C# example to work:
using System;
using OneNote = Microsoft.Office.Interop.OneNote;
class Program
{
static void Main(string[] args)
{
OneNote.Application onenoteApp = new OneNote.Application();
string xml = "<one:Page xmlns:one=\"http://schemas.microsoft.com/office/onenote/2013/onenote\" ...> ... </one:Page>";
onenoteApp.UpdatePageContent(xml, DateTime.MinValue);
}
}
The string xml
was obtained by modification of an XML document, which was retrieved from OneNote using the GetPageContent
method, as detailed in my linked previous question. The precise content of xml
doesn't matter for the sake of this question, the only important thing is that above program runs without problems time after time and changes to an existing OneNote page are always performed successfully.
Going over to Python now, I tried to translate my minimalistic program without making substantial changes. My result looks as follows:
import win32com
import pytz
import datetime
onenote_app = win32com.client.Dispatch('OneNote.Application.15')
xml = "<one:Page xmlns:one=\"http://schemas.microsoft.com/office/onenote/2013/onenote\" ...> ... </one:Page>"
date = pytz.utc.localize(datetime.datetime.fromordinal(1))
onenote_app.UpdatePageContent(xml, date)
I tried to put much care into using the same values for the two variables. Of course the content of the two strings xml
is identical (copy&paste). Also, according to the VS2015 debugger, both DateTime.MinValue
and date
refer to the same date. When I execute the python program, however, I recieve this very unhelpful error.
135 def UpdatePageContent(self, bstrPageChangesXmlIn=defaultNamedNotOptArg, dateExpectedLastModified=(1899, 12, 30, 0, 0, 0, 5, 364, 0), xsSchema=2, force=False):
136 return self._oleobj_.InvokeTypes(1610743816, LCID, 1, (24, 0), ((8, 1), (7, 49), (3, 49), (11, 49)),bstrPageChangesXmlIn
--> 137 , dateExpectedLastModified, xsSchema, force)
138
139 _prop_map_get_ = {
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147213296), None)
To my understanding, both C# and Python actually use the same library to execute their calls (both called Microsoft OneNote 15.0 Object Library
). So in principle both programs should work fine. If I am not mistaken in this point, I would thus assume that Python does something different in its call to the library. How can I trace further what the actual problem here is? Is there maybe a way to use the built-in Python support of Visual Studio 2015 to understand the difference between the C# and the Python code better?