Exemplo n.º 1
0
        private void SaveErrorFile(string strFile, Bitmap img)
        {
            XWPFDocument m_Docx   = new XWPFDocument();
            CT_SectPr    m_SectPr = new CT_SectPr();

            //页面设置A4
            m_SectPr.pgSz.w = (ulong)16838;
            m_SectPr.pgSz.h = (ulong)11906;

            m_Docx.Document.body.sectPr = m_SectPr;

            // 创建段落
            CT_P m_p = m_Docx.Document.body.AddNewP();

            m_p.AddNewPPr().AddNewJc().val = ST_Jc.left;                //段落水平居左
            XWPFParagraph gp = new XWPFParagraph(m_p, m_Docx);          //创建XWPFParagraph

            CT_R m_r = m_p.AddNewR();

            m_r.AddNewT().Value = "记录时间:" + DateTime.Now.ToString("yyyy-MM-dd mm:dd:ss");
            m_r.AddNewCr();
            m_r.AddNewT().Value = "账套公司名称:" + mstrCompanyName;
            m_r.AddNewCr();
            m_r.AddNewT().Value = "按钮名称:" + mstrButtonAction;
            WriteText(m_r, txtMainInfo.Text);
            WriteText(m_r, mstrMoreInfo);

            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                using (Bitmap bmp = GetScreenImage())
                {
                    bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Gif);
                }

                stream.Position = 0;

                m_p = m_Docx.Document.body.AddNewP();
                m_p.AddNewPPr().AddNewJc().val = ST_Jc.center;                //段落水平居中
                gp = new XWPFParagraph(m_p, m_Docx);
                XWPFRun gr = gp.CreateRun();
                gr.AddPicture(stream, (int)NPOI.XWPF.UserModel.PictureType.GIF, "1.gif", 360000 * 23, 360000 * 16);
            }

            using (FileStream writer = new FileStream(strFile, FileMode.CreateNew))
            {
                m_Docx.Write(writer);
                writer.Close();
            }
        }
Exemplo n.º 2
0
        public void TestAddCarriageReturn()
        {
            ctRun.AddNewT().Value = ("TEST STRING");
            ctRun.AddNewCr();
            ctRun.AddNewT().Value = ("TEST2 STRING");
            ctRun.AddNewCr();
            ctRun.AddNewT().Value = ("TEST3 STRING");
            Assert.AreEqual(2, ctRun.SizeOfCrArray());

            XWPFRun run = new XWPFRun(new CT_R(), p);

            run.SetText("T1");
            run.AddCarriageReturn();
            run.AddCarriageReturn();
            run.SetText("T2");
            run.AddCarriageReturn();
            Assert.AreEqual(3, run.GetCTR().GetCrList().Count);
        }
Exemplo n.º 3
0
 private void WriteText(CT_R m_r, string text)
 {
     using (StringReader reader = new StringReader(text))
     {
         string strLine = reader.ReadLine();
         while (strLine != null)
         {
             m_r.AddNewT().Value = strLine;
             m_r.AddNewCr();
             strLine = reader.ReadLine();
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Specifies that a carriage return shall be placed at the
  * current location in the run.content.
  * A carriage return is used to end the current line of text in
  * WordProcess.
  * The behavior of a carriage return in run.content shall be
  * identical to a break character with null type and clear attributes, which
  * shall end the current line and find the next available line on which to
  * continue.
  * The carriage return character forced the following text to be
  * restarted on the next available line in the document.
  */
 public void AddCarriageReturn()
 {
     run.AddNewCr();
 }