首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在open xml中去掉"After Spacing“

如何在open xml中去掉"After Spacing“
EN

Stack Overflow用户
提问于 2012-12-11 23:58:12
回答 1查看 10.4K关注 0票数 10

在open XML中,我的word文档默认为"Spacing After: 10pt“,我该如何将其更改为0,所以没有空格。

这是我的代码,它几乎从数据库中获取信息,并将其放到word文档中以便能够打印出来。但是间距使得文档太大了。

代码语言:javascript
复制
using (WordprocessingDocument wordDoc = WordprocessingDocument.Create(filepath,  WordprocessingDocumentType.Document)) {
    MainDocumentPart mainPart = wordDoc.AddMainDocumentPart();
    mainPart.Document = new Document();
    Body body = mainPart.Document.AppendChild(new Body());

    Paragraph para_main = body.AppendChild(new Paragraph());
    Run run_main = para_main.AppendChild(new Run());

    // Goes through all of the forms
    foreach (var form in forms) {
        Table table = new Table();
        // Initialize all of the table properties
        TableProperties tblProp = new TableProperties(
            new TableBorders(
                new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackSquares), Size = 16 },
                new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackSquares), Size = 16 },
                new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackSquares), Size = 16 },
                new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackSquares), Size = 16 },
                new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackSquares), Size = 8 },
                new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackSquares), Size = 8 }
            ),
            new SpacingBetweenLines() { Before = "20", After = "20" }
            //new TableCellProperties(
            //    new 
            //new TableJustification() {Val = TableRowAlignmentValues.Center}
        );

        table.AppendChild<TableProperties>(tblProp);

        Paragraph para_header = body.AppendChild(new Paragraph());
        Run run_header = para_header.AppendChild(new Run());
        RunProperties runProps = run_header.AppendChild(new RunProperties(new Bold()));

        string username = form.Username;
        string proces_header = form.HeaderTitle;

        run_header.AppendChild(new Text(proces_header + " | " + username));

        for (int i = 0; i < form.FieldList.Count; i++) {
            if (!(form.FieldList[i].Token == "USR" || form.FieldList[i].Token == "SNT")) {
                TableRow tr = new TableRow();
                TableCell header_cell = new TableCell();
                header_cell.Append(new Paragraph(new Run(new Text(form.FieldList[i].Label))));
                TableCell value_cell = new TableCell();
                value_cell.Append(new Paragraph(new Run(new Text(form.FieldList[i].Value))));
                tr.Append(header_cell, value_cell);
                table.Append(tr);
            }
        }
        wordDoc.MainDocumentPart.Document.Body.Append(table);
    }
    mainPart.Document.Save();
    wordDoc.Close();
    return "Success";
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-20 21:25:15

行距需要附加到段落属性中,当然也需要附加到段落中。

这里有很长的一段路要走。SpacingBetweenLines还可以设置行高,“规则”控制如何使用之前和之后的值。

代码语言:javascript
复制
SpacingBetweenLines spacing = new SpacingBetweenLines() { Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0" };
ParagraphProperties paragraphProperties = new ParagraphProperties();
Paragraph paragraph = new Paragraph();

paragraphProperties.Append(spacing);
paragraph.Append(paragraphProperties);

看起来您正在尝试设置表格的行距。那是行不通的(相信我,我试过了)。表周围的文本由文本换行和表的位置控制。

此外,当使用多个表时,如果您想将它们分开,则需要在表之后添加一个段落(或其他内容),否则您的表将合并在一起。

如果您需要该空间,请创建一个字体设置为.5或非常小的字体的段落,并将其添加到每个表之后。

票数 15
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13823668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档