首页 > 解决方案 > 如何使用 NPOI 删除行之间的额外间距

问题描述

我是新开发人员,需要您的帮助

我正在使用 NPOI 创建基于 txt 文件的 word 文档。已经有一个单词示例,格式还可以。

正如您在这张图片中看到的,线条之间的空间很窄:

没有间距的图像

在我使用 NPOI 创建 Word 文档后,新文件的段落间距更大:

带间距的图像

每次我在 word 文档中添加新文本时,我都会设置:

     private static void SetParagraphRunSettings(XWPFRun paragraphRun)
        {
            paragraphRun.FontSize = 7;
            paragraphRun.FontFamily = "Courier New";
            paragraphRun.IsBold = true;
        }
        
        private static void SetParagraphSettings(XWPFParagraph paragraph, string stepComment)
        {
            if (stepComment.Contains("Landscate -"))
            {
                paragraph.IndentationFirstLine = 0;
                paragraph.FirstLineIndent = 0;
                paragraph.IndentationLeft = 1; //(int)(0.002 * 20); // 0.64 Cm = 0.002 inches
                paragraph.IndentationHanging = 1;  //(int)(0.002 * 20); // 0.64 Cm = 0.002 inches
            }
            paragraph.Alignment = ParagraphAlignment.LEFT;
            paragraph.IndentationRight = 0;
            paragraph.SpacingBefore = 0;
            paragraph.SpacingAfter = 0;
            // Line Spcing = Sigle 
            paragraph.setSpacingBetween(1, LineSpacingRule.AUTO);
        }

标签: c#ms-wordnpoixwpf

解决方案


您可以在https://github.com/nissl-lab/npoi-examples/issues中创建问题吗?我想检查这是否是最新 NPOI 的错误。


推荐阅读