Skip to content

Commit

Permalink
2023年2月7日更新:
Browse files Browse the repository at this point in the history
完善在页面上新增复制为纯文本功能,选择内容,右键,点击复制为纯文本,将文本复制到剪切板。
  • Loading branch information
lun9090 committed Feb 7, 2023
1 parent 0174fe8 commit e646cfe
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 8 deletions.
159 changes: 154 additions & 5 deletions Class1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
using System.Xml;
using System.Xml.Linq;
using OneNote = Microsoft.Office.Interop.OneNote;
using TextCopy;
using System.Text;
using System.Text.RegularExpressions;
using HtmlAgilityPack;


namespace litingaddin
{
Expand Down Expand Up @@ -1644,7 +1648,8 @@ public string GetItemID(IRibbonControl control, int index)
return "heading" + index.ToString();
}

public void copy_chun(IRibbonControl control)

public static void get_chun(out String page_copy)
{
OneNote.Application onenoteApp = new OneNote.Application();
string xml;
Expand All @@ -1653,15 +1658,159 @@ public void copy_chun(IRibbonControl control)
XDocument doc = XDocument.Parse(xml);
XNamespace ns = doc.Root.Name.Namespace;
StringBuilder sb = new StringBuilder();
foreach (XElement Outlines in from node in doc.Descendants(ns + "Outline").ToList() select node)
foreach (XElement Outlines in doc.Descendants(ns + "Outline").ToList())
{
foreach (XElement outline in from node1 in Outlines.Descendants(ns + "T").Where(o => o.Attribute("selected").Value == "all") select node1)
String Outlines_selected = null;
Outlines_selected = Outlines.Attribute("selected").Value;
if (Outlines_selected != null)
{
sb.AppendLine(outline.Value);
foreach (XElement Outlines_OEChilds in Outlines.Descendants(ns + "OEChildren").ToList())
{
String OEChilds_selected = null;
try
{
OEChilds_selected = Outlines_OEChilds.Attribute("selected").Value;
}
catch (Exception)
{

}

if (OEChilds_selected != null)
{
//MessageBox.Show(Outlines_OEChilds.ToString());
foreach (XElement Outlines_OE in Outlines_OEChilds.Descendants(ns + "OE").ToList())
{


String OE_selected = null;
try
{
OE_selected = Outlines_OE.Attribute("selected").Value;
}
catch (Exception)
{

}

if (OE_selected != null)
{
//MessageBox.Show(Outlines_OE.ToString());
foreach (XElement Outlines_T in Outlines_OE.Descendants(ns + "T").ToList())
{
String T_selected = null;
try
{
T_selected = Outlines_T.Attribute("selected").Value;
}
catch (Exception)
{

}

if (T_selected != null)
{
MessageBox.Show(Outlines_T.ToString());
sb.AppendLine(Outlines_T.Value);
}
else
{
continue;
}
}
}
else
{

continue;
}
}
}
else
{
continue;
}
}
}
else
{
continue;
}


}
Clipboard.SetDataObject(sb.ToString());
page_copy= sb.ToString();
/*MessageBox.Show(sb.ToString());
TextCopy.ClipboardService.SetText(sb.ToString());*/
}

public static void Replace_cpan(String cpan_in,out String cpan_out)
{



HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(cpan_in);
StringBuilder sb_1 = new StringBuilder();
var spanNodes = doc.DocumentNode.SelectNodes("//span");
if (spanNodes != null)
{
foreach (var spanNode in spanNodes)
{
string content = spanNode.InnerHtml;
sb_1.Append(content);
}
}
cpan_out= sb_1.ToString();

}

public void copy_chun(IRibbonControl control)
{
OneNote.Application onenoteApp = new OneNote.Application();
string xml;
var pageid = onenoteApp.Windows.CurrentWindow.CurrentPageId;
onenoteApp.GetPageContent(pageid, out xml, OneNote.PageInfo.piAll);
XDocument doc = XDocument.Parse(xml);
XNamespace ns = doc.Root.Name.Namespace;
StringBuilder sb = new StringBuilder();
String page_copy;

foreach (XElement Outlines_T in doc.Descendants(ns + "T").ToList())
{
String T_selected = null;
try
{
T_selected = Outlines_T.Attribute("selected").Value;
}
catch (Exception)
{

}

if (T_selected == "all")
{
//MessageBox.Show(Outlines_T.ToString());
//sb.AppendLine(Outlines_T.Value);
if(Outlines_T.Value.Contains("span") ==true)
{
Replace_cpan(Outlines_T.Value, out page_copy);
sb.AppendLine(page_copy);
}
else
{
sb.AppendLine(Outlines_T.Value);
}

}
else
{
continue;
}
}
//MessageBox.Show(sb.ToString());
TextCopy.ClipboardService.SetText(sb.ToString());
MessageBox.Show("复制成功!");
}


Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ onenote项目管理插件
- 项目管理日记
> 点击后,在默认笔记本位置,生成My Project Journal笔记本。
> 如果的笔记本是联网的,也就是说,你的默认笔记本路径是在onedrve上的,按照这样的步骤操作,第一次生成My Project Journal笔记本后,关闭OneNote,等待onedirve将你的笔记本自动转化为在线笔记本,这个时间可能有点慢,你也可以继续使用,等待下次打开找不到笔记本的时候,你需要做的一件事就是,点击打开笔记本,点击onedirve,找到转化后的在线My Project Journal笔记本,完成同步后,插件可继续使用,目前技术还未解决该问题,后续再说。
- 右键功能
- 复制为纯文本
> 选择内容,右键,点击复制为纯文本,将文本复制到剪切板。
## 特别说明

本工具根据个人工作需要开发,有其他需求的,可以留言。
Expand Down
12 changes: 10 additions & 2 deletions app.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="litingaddin.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
Expand All @@ -21,4 +21,12 @@
</setting>
</litingaddin.Properties.Settings>
</applicationSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
49 changes: 49 additions & 0 deletions litingaddin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,69 @@
<Reference Include="extensibility, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="HtmlAgilityPack.NetCore, Version=1.5.0.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\HtmlAgilityPack.NetCore.1.5.0.1\lib\net45\HtmlAgilityPack.NetCore.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Extensions.DependencyInjection.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.JsonWebTokens, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.JsonWebTokens.5.6.0\lib\net461\Microsoft.IdentityModel.JsonWebTokens.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Logging, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Logging.5.6.0\lib\net461\Microsoft.IdentityModel.Logging.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Tokens, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Tokens.5.6.0\lib\net461\Microsoft.IdentityModel.Tokens.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.Services.Common, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.VisualStudio.Services.Client.16.170.0\lib\net462\Microsoft.VisualStudio.Services.Common.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.Services.WebApi, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.VisualStudio.Services.Client.16.170.0\lib\net462\Microsoft.VisualStudio.Services.WebApi.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\System.IdentityModel.Tokens.Jwt.5.6.0\lib\net461\System.IdentityModel.Tokens.Jwt.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="TextCopy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1ca091877d12ca03, processorArchitecture=MSIL">
<HintPath>packages\TextCopy.6.2.1\lib\net462\TextCopy.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Class1 - 20211014.cs.bak" />
<Compile Include="Class1.cs" />
<Compile Include="allinxml.cs">
Expand All @@ -73,6 +121,7 @@
</ItemGroup>
<ItemGroup>
<None Include="onenote_bat\restartonenote.bat" />
<None Include="packages.config" />
<None Include="Properties\DataSources\Class1.datasource" />
<None Include="README.md" />
<None Include="Resources\title%404x.png" />
Expand Down
17 changes: 17 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="HtmlAgilityPack.NetCore" version="1.5.0.1" targetFramework="net48" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net48" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="7.0.0" targetFramework="net48" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="7.0.0" targetFramework="net48" />
<package id="Microsoft.IdentityModel.JsonWebTokens" version="5.6.0" targetFramework="net48" />
<package id="Microsoft.IdentityModel.Logging" version="5.6.0" targetFramework="net48" />
<package id="Microsoft.IdentityModel.Tokens" version="5.6.0" targetFramework="net48" />
<package id="Microsoft.VisualStudio.Services.Client" version="16.170.0" targetFramework="net48" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net48" />
<package id="System.IdentityModel.Tokens.Jwt" version="5.6.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net48" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net48" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
<package id="TextCopy" version="6.2.1" targetFramework="net48" />
</packages>

0 comments on commit e646cfe

Please sign in to comment.