Aspose.Wrods For Net 按标签 替换HTML内容时 样式设置

    /// 
    /// Aspose HTML字体设置
    /// 
    public class HandleNodeChangingFontChanger : INodeChangingCallback
    {
        private double conSize;
        private bool conBold;
        private string name;
        public HandleNodeChangingFontChanger(double gconSize, bool gconBold,string fontName)
        {
            conSize = gconSize;
            conBold = gconBold;
            name = fontName;
        }
        
        // Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document
        /// 
        /// 插入HTML 字体设置
        /// 
        /// 
        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;
                if(string.IsNullOrEmpty(name)) name= "等线 (正文)";
                font.Name = name;
            }
        }

        void INodeChangingCallback.NodeInserting(NodeChangingArgs args)
        {
            // Do Nothing
        }

        void INodeChangingCallback.NodeRemoved(NodeChangingArgs args)
        {
            // Do Nothing
        }

        void INodeChangingCallback.NodeRemoving(NodeChangingArgs args)
        {
            // Do Nothing
        }
    }

使用:

 doc.NodeChangingCallback = new HandleNodeChangingFontChanger(10.5, false,"仿宋"); 

这样就可以设置

builder.InsertHtml("替换内容", true);

你可能感兴趣的:(NET,c#)