[英]Export to OneNote using C#
I'd like to export text from my application to MS OneNote and support Office versions: 2007, 2010, 2013 and 2016. I'm using the Microsoft.Office.Interop.OneNote.dll Version:12.0.
我想将文本从应用程序导出到MS OneNote,并支持Office版本:2007、2010、2013和2016。我正在使用Microsoft.Office.Interop.OneNote.dll Version:12.0.
0 as it's supplied with all Office versions. 所有Office版本都提供0。
The problem is when I try to create a new OneNote page on Office 2013 using "CreateNewPage" I'm getting the exception: 问题是当我尝试使用“ CreateNewPage”在Office 2013上创建新的OneNote页面时,出现异常:
hrSectionReadOnly 0x8004200b hrSectionReadOnly 0x8004200b
The section is read-only. 该部分是只读的。
I can see an attribute readOnly="true"
I've tried to change it and it's not helping. 我可以看到一个属性readOnly="true"
我试图更改它,但没有帮助。 Still getting the same exception. 仍然出现相同的异常。
If I reference Microsoft.Office.Interop.OneNote.dll Version:15.0.0
then everything works fine. 如果我引用Microsoft.Office.Interop.OneNote.dll Version:15.0.0
则一切正常。
Any ideas why it's read only and how can I overcome the problem? 有什么想法为什么它是只读的以及如何解决该问题?
Here is code example: 这是代码示例:
string strPath;
string sectionId;
string xml;
// points directly on OneNote's Unfiled section
_app.GetSpecialLocation(SpecialLocation.slUnfiledNotesSection, out strPath);
_app.OpenHierarchy(strPath, "", out sectionId, CreateFileType.cftSection);
_app.CreateNewPage(sectionId, out _sectionId, NewPageStyle.npsDefault);
var strImportXml = @"<?xml version='1.0' ?>
<one:Page xmlns:one='" + _oneNoteNamespace + "' ID='" + _sectionId + @"'>
<one:Title>
<one:OE>
<one:T>
<![CDATA[
]]>
</one:T>
</one:OE>
</one:Title>
<one:Outline>
<one:Meta name='Rumba' content='" + new Random().Next() + @"' />
<one:OEChildren>
<one:HTMLBlock>
<one:Data>
<![CDATA[My sample page]]>
</one:Data>
</one:HTMLBlock>
</one:OEChildren>
</one:Outline>
</one:Page>";
_app.UpdatePageContent(strImportXml, DateTime.MinValue);
_app.NavigateTo(_sectionId, String.Empty, true);
private void ExportDataSetToOther(System.Data.DataTable dataTable, bool isActive)
{
string path = string.Empty;
var lines = new List<string>();
if (isActive )
{
path = savingFileName.Remove(savingFileName.LastIndexOf('\\') + 1);
savingFileName = path + transactionName + DetailsOrSummary + (page + 1) +"."+ extention;// extention means .txt,.xlx,.one,.xlxs etc
isActive = false;
string[] columnNames = dataTable.Columns.Cast<DataColumn>().
Select(column => column.ColumnName).
ToArray();
var header = string.Join(",", columnNames);
lines.Add(header);
var valueLines = dataTable.AsEnumerable()
.Select(row => string.Join(",", row.ItemArray));
lines.AddRange(valueLines);
File.WriteAllLines(savingFileName, lines);
}
else
{
var valueLines1 = dataTable.AsEnumerable()
.Select(row => string.Join(",", row.ItemArray));
lines.AddRange(valueLines1);
File.AppendAllLines(savingFileName, lines);
}
}
check the file is active or not if not active you can do with else part so the current data will append with exiting values 检查文件是否处于活动状态(如果未处于活动状态),则可以处理else部分,以便当前数据将附加退出值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.