Skip to content

Commit

Permalink
init push
Browse files Browse the repository at this point in the history
  • Loading branch information
rickywu committed Apr 16, 2020
1 parent 73fae6b commit 2ae6f78
Show file tree
Hide file tree
Showing 104 changed files with 8,534 additions and 0 deletions.
Binary file added UpgradeLog.htm
Binary file not shown.
117 changes: 117 additions & 0 deletions VSTOWordProject/CangjieRibbon.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions VSTOWordProject/CangjieRibbon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using Microsoft.Office.Tools.Ribbon;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;
using Microsoft.Office.Interop.Word;

namespace VisualPaste
{
public partial class CangjieRibbon
{
private void CangjieImportRibbon_Load(object sender, RibbonUIEventArgs e)
{
// 为按钮注册点击事件
btnTableTitle.Click += new RibbonControlEventHandler(CheckDocument);
btnCopyImp.Click += new RibbonControlEventHandler(CheckDocument);
}

// 导出文件方法
private void CheckDocument(object sender, RibbonControlEventArgs e)
{
Document Doc = Globals.ThisAddIn.Application.ActiveDocument;
switch (e.Control.Id)
{
// 判断点击的按钮ID
case "btnTableTitle":
foreach (Table tbl in Doc.Tables)
{
tbl.ApplyStyleHeadingRows = true;
}
break;
case "btnCopyImp":
string docName = Doc.FullName;
//select all and copy
//Doc.Application.ActiveDocument.Content.Select();
//Doc.Application.Selection.Copy();
string fileName = Path.Combine(Path.GetTempPath(), "CangJieSaveAs.html");
object missing = System.Reflection.Missing.Value;
object FileName = fileName;
object FileFormat = WdSaveFormat.wdFormatHTML;
Doc.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
Doc.Application.ActiveDocument.SaveAs2(ref FileName, ref FileFormat);
Doc.Application.ActiveDocument.Close();
Globals.ThisAddIn.Application.Documents.Open(docName);

//load to process
var saveDoc = new HtmlAgilityPack.HtmlDocument();
saveDoc.OptionDefaultStreamEncoding = Encoding.UTF8;
saveDoc.DetectEncodingAndLoad(fileName, true);
//remove comment node
var commentNodes = saveDoc.DocumentNode.SelectNodes("//comment()");
if (commentNodes != null)
{
foreach (var comment in commentNodes)
{
if (!comment.InnerText.StartsWith("<!DOCTYPE"))
{
comment.Remove();
}
}
}
//parse img source
var imgNodes = saveDoc.DocumentNode.SelectNodes("//img/@src");
if (imgNodes != null)
{
foreach (var img in imgNodes)
{
string imageName = img.GetAttributeValue("src", "");
string localPath = Path.Combine(Path.GetTempPath(), imageName);
string imgBase64String = GetBase64StringForImage(localPath);
string imageType = imageName.Substring(imageName.Length - 3);
//use correct MIME type for jpeg image
imageType = (imageType == "jpg") ? imageType.Replace("jpg","jpeg") : imageType;
img.SetAttributeValue("src", "data:image/" + imageType + ";base64," + imgBase64String);
}
}
//clear html
String bodyHtml = saveDoc.DocumentNode.SelectSingleNode("//body").InnerHtml;
bodyHtml = Regex.Replace(bodyHtml, @"( |\t|\r?\n)\1+", "$1");
bodyHtml = bodyHtml.Trim(Environment.NewLine.ToCharArray());

//copy to clipboard and delete temp files
Utilities.CopyHtmlToClipBoard(bodyHtml);
File.Delete(fileName);
Directory.Delete(fileName.Replace("html","files"), true);
break;
default:
return;
}
}
protected static string GetBase64StringForImage(string imgPath)
{
byte[] imageBytes = System.IO.File.ReadAllBytes(imgPath);
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
}
120 changes: 120 additions & 0 deletions VSTOWordProject/CangjieRibbon.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
37 changes: 37 additions & 0 deletions VSTOWordProject/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;

// 有关程序集的常规信息通过下列特性集
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("VisualPaste")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VisualPaste")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("5be6078d-d3b4-4513-b838-5fcbff4d4f32")]

// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 内部版本号
// 修订号
//
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 2ae6f78

Please sign in to comment.