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

如何使用open xml sdk从c#更改页面方向

发布时间:2020-12-16 23:17:14 所属栏目:百科 来源:网络整理
导读:我正在创建一个word文档 using (WordprocessingDocument myDoc = WordprocessingDocument.Create(@"c:generateexport.docx",WordprocessingDocumentType.Document)) { MainDocumentPart mainPart = myDoc.AddMainDocumentPart(); mainPart.Document = new
我正在创建一个word文档

using (WordprocessingDocument myDoc = WordprocessingDocument.Create
(@"c:generateexport.docx",WordprocessingDocumentType.Document))          
  { MainDocumentPart mainPart = myDoc.AddMainDocumentPart(); 
    mainPart.Document = new Document();               
 var body = new Body();               
 var p = new Paragraph(new ParagraphProperties(new Justification()
 { Val = JustificationValues.Center }),new Run(new Text("test"))); 
  body.Append(p);                
mainPart.Document.Append(body);                
// Save changes to the main document part.                 
mainPart.Document.Save();            }

如何将页面方向设置为横向

解决方法

您必须创建一个新的部分属性.

WordprocessingDocument wd = someDoc;

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

左边==左边距和右边==右边距(双打).

(编辑:李大同)

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

    推荐文章
      热点阅读