加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何使用Open XML和C#更改单个段落或页面的方向?

发布时间:2020-12-15 23:56:22 所属栏目:百科 来源:网络整理
导读:我正在使用C#和Open XML SDK生成word文档.我想将一些段落及其包含页面的方向更改为横向,同时保持其他段落的纵向方向. 我尝试了一些解决方案,但他们没有实现我想要的东西,而是所有页面的方向都被改为横向除了第一个.这些解决方案包括 – 将SectionProperties
我正在使用C#和Open XML SDK生成word文档.我想将一些段落及其包含页面的方向更改为横向,同时保持其他段落的纵向方向.
我尝试了一些解决方案,但他们没有实现我想要的东西,而是所有页面的方向都被改为横向除了第一个.这些解决方案包括
– 将SectionProperties添加到我想要更改的段落中
它对景观的定位:
WordprocessingDocument WordDocument = WordprocessingDocument.Open(ReportFile,true)
Paragraph paragraph =  new Paragraph(new ParagraphProperties(
               new SectionProperties( new PageSize() 
               { Width = (UInt32Value)15840U,Height = (UInt32Value)12240U,Orient = PageOrientationValues.Landscape })));
WordDocument.MainDocumentPart.Document.Body.Append(paragraph);

– 将新主体添加到主文档并将段落附加到主文档:

WordprocessingDocument WordDocument = WordprocessingDocument.Open(ReportFile,true)    
Body body = new Body();          
Paragraph paragraph =  new Paragraph(new ParagraphProperties(
               new SectionProperties( new PageSize() 
               { Width = (UInt32Value)15840U,Orient = PageOrientationValues.Landscape })));
body.Append(paragraph);
WordDocument.MainDocumentPart.Document.Append(body);

– 在主文档中添加一个新Body并直接向其添加SectionProprties:

WordprocessingDocument WordDocument = WordprocessingDocument.Open(ReportFile,true)  
Body body = new Body();
Paragraph paragraph = new Paragraph();
SectionProperties sectionProp = new SectionProperties(new PageSize() { Width = (UInt32Value)15840U,Orient = PageOrientationValues.Landscape });
body.Append(paragraph);
body.Append(sectionProp);
WordDocument.MainDocumentPart.Document.Append(body);

那么,有没有办法改变单个段落/页面的方向?

您必须放置下一页分节符以开始新节,并设置该节的方向.完成后,使用默认页面方向开始新部分.

下一页分节开始横向:

doc.MainDocumentPart.Document.Body.Append(
    new Paragraph(
        new ParagraphProperties(
            new SectionProperties(
                new PageSize() { Width = (UInt32Value)12240U,Height = (UInt32Value)15840U,Orient = PageOrientationValues.Landscape },new PageMargin() { Top = 720,Right = Convert.ToUInt32(rightmargin * 1440.0),Bottom = 360,Left = Convert.ToUInt32(leftmargin * 1440.0),Header = (UInt32Value)450U,Footer = (UInt32Value)720U,Gutter = (UInt32Value)0U }))));

下一页分节开始纵向方向:

doc.MainDocumentPart.Document.Body.Append(
    new Paragraph(
        new ParagraphProperties(
            new SectionProperties(
                new PageSize() { Width = (UInt32Value)12240U,Height = (UInt32Value)15840U },Gutter = (UInt32Value)0U }))));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读