aspose 解决插入html后字体问题

 /// 
        /// 添加html
        /// 
        /// 
        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
            }
        }

 

转载于:https://www.cnblogs.com/daxiongblog/p/5057431.html

你可能感兴趣的:(aspose 解决插入html后字体问题)