/// <summary> /// 添加html /// </summary> /// <param name="strText"></param> public void InsertHtml(string strText, double conSize, bool conBold, string conAlign="") { oDoc.NodeChangingCallback = new HandleNodeChangingFontChanger(conSize,conBold); oWordApplic.InsertHtml(strText); }
public class HandleNodeChangingFontChanger : INodeChangingCallback { private double conSize; private bool conBold; public HandleNodeChangingFontChanger(double gconSize, bool gconBold) { conSize = gconSize; conBold = gconBold; } // Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document void INodeChangingCallback.NodeInserted(NodeChangingArgs args) { // Change the font of inserted text contained in the Run nodes. if (args.Node.NodeType == NodeType.Run) { Font font = ((Run)args.Node).Font; font.Size = conSize; font.Bold = conBold; font.Name = "宋体"; } } void INodeChangingCallback.NodeInserting(NodeChangingArgs args) { // Do Nothing } void INodeChangingCallback.NodeRemoved(NodeChangingArgs args) { // Do Nothing } void INodeChangingCallback.NodeRemoving(NodeChangingArgs args) { // Do Nothing } }