WPS的JS宏实现图片正文在同一段落的分离方法

当图片处于正文的行尾时,有时候人眼很难判断出来。但是在编辑格式时又很容易出错,图片需要居中处理,正文需要左对齐。

如下JS代码实现了:图文分离

let rangShapes = Documents.Item(filepath).Range(startP,endP).InlineShapes;
    while(i<=count)
    {
        rangShapes.Item(i).Select();
        if(rangShapes.Item(i).Height >= Selection.Font.Size*2)
        {//图片高度大于正文字体高度的两倍,进行居中处理。否则判定为正文描述内容。            
            rangShapes.Item(i).Select();            
            ActiveW.Selection.MoveLeft(wdCharacter, 2, wdExtend);
            if(ActiveW.Selection.Paragraphs.Count == 1)
            {//图文在同一段落中,在图片前增加回车换行。
                rangShapes.Item(i).Select();
                ActiveW.Selection.MoveLeft(wdCharacter, 1, wdMove);
                ActiveW.Selection.TypeParagraph();
                ActiveW.Selection.Style =  "正文";
            }
            rangShapes.Item(i).Select();
            ActiveW.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = 0;
            ActiveW.Selection.ParagraphFormat.FirstLineIndent = 0;
            ActiveW.Selection.ParagraphFormat.CharacterUnitLeftIndent = 0;
            ActiveW.Selection.ParagraphFormat.LeftIndent = 0;
            ActiveW.Selection.ParagraphFormat.CharacterUnitRightIndent = 0;
            ActiveW.Selection.ParagraphFormat.RightIndent = 0;
            ActiveW.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter;//图片居中      
        }                        
        i++;
    }

猜你喜欢

转载自blog.csdn.net/qq_27866305/article/details/125417646