[C#][原创]aspose.word删除文档空行

下面代码测试通过,但是aspose.word有个缺点,加载文档后行距会自动由单倍行距变成1.15多倍行距,段后本来是0结果会变成10。目前找不到好的解决方法,有知道解决方法下面一起交流        

public void RemoveEmpyLines(string docFile, string saveFile)
        {

            Document doc = new Document(docFile);
  
            //遍历文档,判定段落中是否包含空白行,删除空白行
            foreach (Section section in doc.Sections)
            {
    
                for (int i = 0; i < section.Body.ChildNodes.Count; i++)
                {
               
                    if (section.Body.ChildNodes[i].NodeType == NodeType.Paragraph)
                    {
                       

                        if (String.IsNullOrEmpty((section.Body.ChildNodes[i] as Paragraph).GetText().Trim()))
                        {
                            section.Body.ChildNodes.Remove(section.Body.ChildNodes[i]);
            
                            i--;
                        }
                    }
                }
            }        
            doc.Save(saveFile);
        }

猜你喜欢

转载自blog.csdn.net/FL1623863129/article/details/112967780