回覆列表
  • 1 # 使用者990540253822

    #region 1.建立文件(頁首、頁尾)

    XWPFDocument doc = new XWPFDocument();

    //頁面設定 A4:w=11906 h=16838

    doc.Document.body.sectPr = new CT_SectPr();

    CT_SectPr m_SectPr = doc.Document.body.sectPr;

    m_SectPr.pgSz.h = (ulong)16838;

    m_SectPr.pgSz.w = (ulong)11906;

    m_SectPr.pgMar.left = (ulong)1000;//左邊距

    m_SectPr.pgMar.right = (ulong)1000;//右邊距

    m_SectPr.pgMar.top = "150";//上邊距

    m_SectPr.pgMar.bottom = "150";

    #region =頁首=

    CT_Hdr m_hdr = new CT_Hdr();

    m_hdr.AddNewP().AddNewPPr().AddNewSpacing().lineRule = "-600";

    //建立頁首關係

    XWPFRelation Hrelation = XWPFRelation.HEADER;

    XWPFHeader m_h = (XWPFHeader)doc.CreateRelationship(Hrelation, XWPFFactory.GetInstance(), doc.HeaderList.Count);

    //讀取圖片資料

    FileStream picData_ym = null;

    string filepath_ym = System.Windows.Forms.Application.StartupPath + @"/Images/ym.png";

    picData_ym = new FileStream(filepath_ym, FileMode.Open, FileAccess.Read);

    //設定頁首

    m_h.SetHeaderFooter(m_hdr);

    //頁首插入圖片(inline)單位:EMUS,1CM=360000EMUS

    m_h.AddPicture(picData_ym, (int)PictureType.PNG, "ym.png", 6200000, 200000);

    CT_HdrFtrRef m_HdrFtr = m_SectPr.AddNewHeaderReference();

    m_HdrFtr.type = ST_HdrFtr.@default;

    m_HdrFtr.id = m_h.GetPackageRelationship().Id;

    picData_ym.Close();

    #endregion

  • 中秋節和大豐收的關聯?
  • “流水落花春去也”這道詩的出處、全文?