乐于分享
好东西不私藏

国产系统下WPS公文排版插件(三)--标题设置

国产系统下WPS公文排版插件(三)--标题设置
    哈哈,到这里速度就比较快了,不用在意一些标准之争、具体数值。当然没有经过各种场景测试可能会遗漏一些不适应也是正常。标题的设置主要还是以考虑设置字体为主,其他的类似复制粘贴网文字的颜色不是黑色,如果一并设置进去会导致原有的一些标记被抹除,尽量还是拆开另外设置。
    公文的标题,常用的我认为可以分为文档标题、一级标题“一、”、二级标题“(一)”、三级标题“1.”、四级标题“(1)”、五级标题“一是”和其他标题。其他标题比如制度的“章条”、法律条文的“编章节条款项目”等等。
    除了文档标题以外,其他的标题都有一些比较显著的特征,如果我们也只是类似格式刷选中文字后,再来一个个设置感觉没什么意义,虽然市面上的公文助手基本也是这个模式。毕竟,我们既然自己动手了,当然得想怎么方便来怎么来了。
一、文档标题
    公文的文档标题有个特殊性,他要根据标题的内容进行调整,每个文档都不一样,多两个字少两个字也可能也不一样了,他可能1行,可能2行,也可能3行、4行。因此需要选中才能设置,主要以居中、字体、大小为主,大纲级别就不设置了,但是保留,后续大纲1级不使用。本来想说去除下头部空格,但是效果不好,默认已经前文的“全文设置”处理过了,这样子就会是用的首行缩进,这里缩进设为0就够用了。有需要后期处理可以另外统一处理去除头部多余空格。
function 文档标题(){    let 标题字体="方正小标宋简体";    let selection = Application.Selection;    let wendangbiaoti=obj=>{        obj.CharacterUnitFirstLineIndent = 0;        obj.FirstLineIndent = 0;        obj.OutlineLevel = 1;        obj.DisableLineHeightGrid = 0;        obj.ReadingOrder = 1;//wdReadingOrderLtr;        obj.AutoAdjustRightIndent = -1;        obj.WidowControl = -1;        obj.KeepWithNext = 0;        obj.KeepTogether = 0;        obj.PageBreakBefore = 0;        obj.FarEastLineBreakControl = -1;        obj.WordWrap = -1;        obj.HangingPunctuation = -1;        obj.HalfWidthPunctuationOnTopOfLine = 0;        obj.AddSpaceBetweenFarEastAndAlpha = -1;        obj.BaseLineAlignment =4;// wdBaselineAlignAuto;    }    wendangbiaoti(selection.ParagraphFormat);    selection.Font.Name = 标题字体;    selection.ParagraphFormat.Alignment = 1;    selection.Font.Size = 22;}
二、一级标题
    一级标题是“一、”、“二、”、“三、”开头的,通常是一整个段,这个就特好识别处理了,直接正则锁定,替换格式即可,这里设为大纲2级。现在就无需选定文字了在设置了。
function 一级标题(){    let 一级字体="黑体"    let doc=Application.ActiveDocument    let selection = Application.Selection;    const matches = doc.Content.Text.match(/^[零一二三四五六七八九十百千万亿]+、.*$/gm);    if(matches == null){        alert("无标题需要处理!")        return    }else{          for(let match of matches){            selection.HomeKey(6)//wdStory            selection.Find.Text=match;            selection.Find.Execute(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined,0, undefined, undefined, undefined, undefined);// wdReplaceNone            selection.Font.Name = 一级字体            Aselection.Paragraphs.OutlineLevel=2        }    }    selection.HomeKey(6);//wdStory,6,部分。wdMove,0,将所选内容折叠到插入点中并移到指定单位的末尾。默认值。}
二、二级标题
    二级标题是“(一)”、“(二)”、“(三)”开头的,但是他通常是在某段的开头一句,甚至半句,并不是一整个段落,并不好设置大纲级别,这里也保留设为大纲3级。
function 二级标题(){    let 二级字体="楷体"    let doc=Application.ActiveDocument    let selection = Application.Selection;    const matches = doc.Content.Text.match(/^([零一二三四五六七八九十百千万亿]+)[\s\S]*?[。!?]/gm);    if(matches == null){        alert("无标题需要处理!")        return    }else{          for(let match of matches){            selection.HomeKey(6)//wdStory            selection.Find.Text=match;            selection.Find.Execute(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined,0, undefined, undefined, undefined, undefined);// wdReplaceNone            selection.Font.Name = 二级字体            selection.Paragraphs.OutlineLevel=3        }    }    selection.HomeKey(6);}
三、三级标题
    跟二级标题类似,并不好设置大纲级别。因为字体一般和正文一样,所以好像也没有什么设置必须要单拎出来。保留设置为以后界面调整预留位置。插空保留。
function 三级标题(){    let 三级字体="方正仿宋简体"    let doc=Application.ActiveDocument    let selection = Application.Selection;    const matches = doc.Content.Text.match(/[0-9]\.+[\s\S]*?[。!?]/gm);    if(matches == null){        alert("无标题需要处理!")        return    }else{          for(let match of matches){            selection.HomeKey(6)//wdStory            selection.Find.Text=match;            selection.Find.Execute(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined,0, undefined, undefined, undefined, undefined);// wdReplaceNone            selection.Font.Name = 三级字体            selection.Paragraphs.OutlineLevel=4        }    }    selection.HomeKey(6); }
四、四级标题
    跟三级标题一样。
function 四级标题(){    let 四级字体="方正仿宋简体"    let doc=Application.ActiveDocument    let selection = Application.Selection;    const matches = doc.Content.Text.match(/([0-9]+)[\s\S]*?[。!?]/gm);    if(matches == null){        alert("无标题需要处理!")        return    }else{          for(let match of matches){            selection.HomeKey(6)//wdStory            selection.Find.Text=match;            selection.Find.Execute(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined,0, undefined, undefined, undefined, undefined);// wdReplaceNone            selection.Font.Name = 四级字体            selection.Paragraphs.OutlineLevel=5        }    }    selection.HomeKey(6); }
五、五级标题
    这个我自己加的,因为他比三、四级标题实用多了。我把段落中的“一是”、“二是”、“三是”定义为五级标题,只设置加粗,其他不动。他穿插在各个段落中,格式刷起来比前面的标题累多了,到这里才是真正能体现效率的设置
function 五级加粗(){    let doc=Application.ActiveDocument    let selection = Application.Selection;    const matches = doc.Content.Text.match(/[一二三四五六七八九十]{1,3}是/gm);    if(matches == null){        alert("无标题需要处理!")        return    }else{          for(let match of matches){            selection.HomeKey(6)//wdStory            sSelection.Find.Text=match;            selection.Find.Execute(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined,0, undefined, undefined, undefined, undefined);// wdReplaceNone            selection.Font.Bold = true        }    }    selection.HomeKey(6); }
六、其他标题
    一些制度类型的文件,通常含有条目,“第一条”、“第二条”之类的,可以参照五级标题进行设置。格式太多种多样了,众口难调,就说法律吧:
    “条”一定存在‌
  • ‌“编、章、节”不一定都有‌,仅在内容复杂、需系统分类时使用;
  • 民法典之类的还有分编;
  • 各个法律的“附则”放的地方还不一样,也不好区分。
  • 还是以“章条”为例,只做加粗。考虑到法典有1千多条,不能设的太少,起码千起步。以下用民法典测试过,要转好一伙儿,但是可行。有需要可以章居中、加粗,条加粗。
function 章条加粗(){    let doc=Application.ActiveDocument    let selection = Application.Selection;    const matches = doc.Content.Text.match(/第[零一二三四五六七八九十百千万亿]{1,7}条/gm);    if(matches == null){        alert("无标题需要处理!")        return    }else{          for(let match of matches){            selection.HomeKey(6)//wdStory            selection.Find.Text=match;            selection.Find.Execute(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined,0, undefined, undefined, undefined, undefined);// wdReplaceNone            selection.Font.Bold = true        }    }    selection.HomeKey(6); }
七、综上
   把每一条分开是为了灵活,如果要一键设置,就还是搞一个函数:
function 一键设置字体(){  一级标题()  二级标题()  三级标题()  四级标题()  五级加粗()}
    有空搞一搞,并不能涉及方方面面,遇到不顺手的我也随手就改了。因为使用不同电脑进行测试,有时候未完全同步,有些错误就会没改,有看到会及时修改或者提醒。
  想到什么做什么,没有完整的规划,随时修改会有各种毛病,归类也不知道要如何分类分组,今天这样顺手今天这样排,明天加个功能那样排。有些功能可能还没有想法或者思路。没有图标,随便玩玩。

相关学习资料