Exemplo n.º 1
0
    //public DxDoc(DxChartFactory factory, string projtitle, string datafile, string netid)
    //{
    //	_creator_netid = netid;
    //	//Document doc = new DevExpress.XtraRichEdit.API.Native.Document();
    //}



    //public DxDoc(List<DxChartOrder> ordersC, string path, string projtitle, string datafile, string netid)
    //{
    //	_creator_netid = netid;
    //	_temppath = path;
    //	_projtitle = projtitle;
    //	_datafile = datafile;
    //	_filename = "test.docx"; // filename;

    //	MakeDocx(ordersC);

    //	//Document doc = new DevExpress.XtraRichEdit.API.Native.Document();
    //}



    //public DxDoc(DataTable dt_plots, List<string> htmltables, string path, string filename, string projtitle, string datafile, string netid)
    //{
    //	_creator_netid = netid;
    //	_temppath = path;
    //	_projtitle = projtitle;
    //	_datafile = datafile;
    //	_filename = filename;

    //	MakeDocx(dt_plots, htmltables);

    //	//Document doc = new DevExpress.XtraRichEdit.API.Native.Document();
    //}

    //public DxDoc(DataTable dt_plots, DataTable dt_tables, string path, string filename, string projtitle, string datafile, string netid)
    //{
    //	_creator_netid = netid;
    //	_temppath = path;
    //	_projtitle = projtitle;
    //	_datafile = datafile;
    //	_filename = filename;

    //	MakeDocx(dt_plots, dt_tables);

    //	//Document doc = new DevExpress.XtraRichEdit.API.Native.Document();
    //}
    #endregion


    protected void DocxHeader(DevExpress.XtraRichEdit.API.Native.Document doc, string s1, string s2)
    {
        DevExpress.XtraRichEdit.API.Native.Section firstSection = doc.Sections[0];
        // Create an empty header.
        SubDocument newHeader = firstSection.BeginUpdateHeader();

        firstSection.EndUpdateHeader(newHeader);
        // Check whether the document already has a header (the same header for all pages).
        if (firstSection.HasHeader(DevExpress.XtraRichEdit.API.Native.HeaderFooterType.Primary))
        {
            SubDocument myHeader = firstSection.BeginUpdateHeader();
            doc.ChangeActiveDocument(myHeader);
            doc.CaretPosition = myHeader.CreatePosition(0);

            string        txt   = String.Format("{0}     p.", s1);
            DocumentRange range = myHeader.InsertText(myHeader.CreatePosition(0), txt);
            Field         fld   = myHeader.Fields.Create(range.End, "PAGE");   //  "PAGE \\* ARABICDASH");
            myHeader.Fields.Update();

            myHeader.Paragraphs.Append();
            string user_time = String.Format("{0}     {1:MM/dd/yy H:mm}", _creator_netid, System.DateTime.Now);
            myHeader.AppendText(String.Format("{0}                             {1}", s2, user_time));


            firstSection.EndUpdateHeader(myHeader);
        }
    }
Exemplo n.º 2
0
        /// <versions>20-02-2018(GesAMFC-v1.0.0.3)</versions>
        private void Config_Document(RichEditControl objRichEditControl)
        {
            try
            {
                objRichEditControl.Text = String.Empty;

                DevExpress.XtraRichEdit.API.Native.Document document = objRichEditControl.Document;
                document.BeginUpdate();
                document.Unit = DevExpress.Office.DocumentUnit.Centimeter;
                foreach (DevExpress.XtraRichEdit.API.Native.Section objSection in document.Sections)
                {
                    objSection.Page.PaperKind = System.Drawing.Printing.PaperKind.A4;
                    objSection.Page.Landscape = false;
                    objSection.Margins.Left   = 2.5f;
                    objSection.Margins.Top    = 2.0f;
                    objSection.Margins.Right  = 1.5f;
                    objSection.Margins.Bottom = 2.0f;
                }
                document.EndUpdate();
            }
            catch (Exception ex)
            {
                Program.HandleError(ex.TargetSite.Name, ex.Message, Program.ErroType.EXCEPTION, true, false);
            }
        }
Exemplo n.º 3
0
        void AddFooterToDocument(DevExpress.XtraRichEdit.API.Native.Document document, string htmlText)
        {
            SubDocument doc = document.Sections[0].BeginUpdateFooter();

            doc.AppendHtmlText(htmlText);
            document.Sections[0].EndUpdateFooter(doc);
        }
 static void ExportRangeToPlainText(RichEditDocumentServer server)
 {
     #region #ExportRangeToPlainText
     DevExpress.XtraRichEdit.API.Native.Document document = server.Document;
     document.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
     string plainText = document.GetText(document.Paragraphs[2].Range);
     System.Windows.Forms.MessageBox.Show(plainText);
     #endregion #ExportRangeToPlainText
 }
Exemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            DevExpress.XtraRichEdit.API.Native.Document doc = richEditControl1.Document;
            doc.BeginUpdate();
            //doc.Text = "我是中国人,我爱自己的pylg";
            CharacterProperties cp = doc.BeginUpdateCharacters(0, doc.Text.Length);

            cp.FontName = "宋体";
            cp.FontSize = 14;
            doc.EndUpdateCharacters(cp);
            doc.EndUpdate();
        }
Exemplo n.º 6
0
 private void InitializeDocument(RichEditControl control)
 {
     DevExpress.XtraRichEdit.API.Native.Document document = control.Document;
     document.BeginUpdate();
     try
     {
         document.DefaultCharacterProperties.FontName        = "新宋体";
         document.DefaultParagraphProperties.LineSpacingType = ParagraphLineSpacing.Sesquialteral;    //行距
     }
     finally
     {
         document.EndUpdate();
     }
 }
 static void ExportRangeToHtml(RichEditDocumentServer server)
 {
     #region #ExportRangeToHtml
     DevExpress.XtraRichEdit.API.Native.Document document = server.Document;
     document.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
     // Get the range for three paragraphs.
     DocumentRange r = document.CreateRange(document.Paragraphs[0].Range.Start, document.Paragraphs[0].Range.Length + document.Paragraphs[1].Range.Length + document.Paragraphs[2].Range.Length);
     // Export to HTML.
     string htmlText = document.GetHtmlText(r, null);
     System.IO.File.WriteAllText("test.html", htmlText);
     // Show the result in a browser window.
     System.Diagnostics.Process.Start("test.html");
     #endregion #ExportRangeToHtml
 }
Exemplo n.º 8
0
        //加载编辑窗体
        private void richEditControl1_InitializeDocument(object sender, EventArgs e)
        {
            RichEditControl obj = (RichEditControl)sender;

            DevExpress.XtraRichEdit.API.Native.Document document = obj.Document;
            document.BeginUpdate();
            try
            {
                document.DefaultCharacterProperties.FontName        = "新宋体";
                document.DefaultParagraphProperties.LineSpacingType = ParagraphLineSpacing.Sesquialteral;
            }
            finally
            {
                document.EndUpdate();
            }
        }
 static void SaveImageFromRange(RichEditDocumentServer server)
 {
     #region #SaveImageFromRange
     DevExpress.XtraRichEdit.API.Native.Document document = server.Document;
     document.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
     DocumentRange docRange = document.Paragraphs[2].Range;
     ReadOnlyDocumentImageCollection docImageColl = document.Images.Get(docRange);
     if (docImageColl.Count > 0)
     {
         DevExpress.Office.Utils.OfficeImage myImage = docImageColl[0].Image;
         System.Drawing.Image image = myImage.NativeImage;
         string imageName           = String.Format("Image_at_pos_{0}.png", docRange.Start.ToInt());
         image.Save(imageName);
         System.Diagnostics.Process.Start("explorer.exe", "/select," + imageName);
     }
     #endregion #SaveImageFromRange
 }
Exemplo n.º 10
0
        /// <versions>28-04-2017(v0.0.2.46)</versions>
        private void Config_Member_Letter_Address_Editor(RichEditControl objRichEditControl)
        {
            try
            {
                objRichEditControl.Text = String.Empty;

                DevExpress.XtraRichEdit.API.Native.Document document = objRichEditControl.Document;
                document.BeginUpdate();
                document.Text = String.Empty;
                document.Unit = DevExpress.Office.DocumentUnit.Centimeter;
                document.Sections[0].Page.PaperKind = System.Drawing.Printing.PaperKind.DLEnvelope;
                document.Sections[0].Page.Landscape = true;
                float fMargin = 0.5f;
                document.Sections[0].Margins.Left   = fMargin;
                document.Sections[0].Margins.Top    = fMargin;
                document.Sections[0].Margins.Right  = fMargin;
                document.Sections[0].Margins.Bottom = fMargin;
                document.EndUpdate();
            }
            catch (Exception ex)
            {
                Program.HandleError(ex.TargetSite.Name, ex.Message, Program.ErroType.EXCEPTION, true, false);
            }
        }
Exemplo n.º 11
0
    protected void MakeDocx(DxReport rpt)     //, string path, string projtitle, string datafile)
    {
        log(" ====== MakeDocx (DxChartFactory factory) ======");
        //const float imageLocationX = 40;
        //const float imageLocationY = 40;
        //int counter = 0;
        //string path = @"C:\_temp\factory\";


        //string fileName_with_savepath = String.Format(@"{0}{1}", _savepath, _filename);


        using (DevExpress.XtraRichEdit.RichEditDocumentServer srv = new DevExpress.XtraRichEdit.RichEditDocumentServer())
        {
            DevExpress.XtraRichEdit.API.Native.Document doc = srv.Document;
            doc.Unit = DevExpress.Office.DocumentUnit.Inch;
            doc.Sections[0].Page.PaperKind = System.Drawing.Printing.PaperKind.Letter;
            doc.Sections[0].Margins.Left   = 0.5f;
            doc.Sections[0].Margins.Right  = 0.5f;
            doc.Sections[0].Margins.Top    = 0.5f;
            doc.Sections[0].Margins.Bottom = 0.5f;

            string subtitle = String.Format("Data Proj: {0}{1}Data file: {2}", _projtitle, Environment.NewLine, _datafile);

            DocxHeader(doc, rpt.rpttitle, subtitle);

            DocumentPosition pos = doc.Range.Start;
            //New Section

            if (rpt.rptdesc.Length > 2)
            {
                doc.AppendText("Report Description:");
                doc.Paragraphs.Append();
                doc.AppendText(rpt.rptdesc);
                doc.Paragraphs.Append();
            }



            //foreach (DxChartOrder order in rpt.orders.chartorders)
            for (int c = 0; c < rpt.orders.chartorders.Count; c++)
            {
                DxChartOrder order = rpt.orders.chartorders[c];
                doc.Paragraphs.Append();

                bool hassameasPrev = rpt.orders.HasSameWkshtFilterVars(c, "chart", -1);
                bool hassameasNext = rpt.orders.HasSameWkshtFilterVars(c, "chart", 1);

                if (order.dt_selectedvars != null & hassameasPrev == false)
                {
                    AppendDataTable(doc, order.dt_selectedvars);
                    doc.Paragraphs.Append();
                }

                Debug.WriteLine(order.InvoiceToString());
                doc.AppendSingleLineText(order.InvoiceToString());
                doc.Paragraphs.Append();

                for (int b = 0; b < order.batches.Count; b++)
                {
                    DxChartBatch batch = order.batches[b];

                    if (batch.charts.Count > 0)
                    {
                        doc.AppendSingleLineText(batch.batchtitle);
                        doc.Paragraphs.Append();

                        AppendCharts(pos, batch, doc);
                        doc.Paragraphs.Append();
                    }
                }

                if (hassameasNext == false)
                {
                    doc.InsertSection(doc.Range.End);
                }
            }


            srv.SaveDocument(String.Format(@"{0}{1}", _savepath, rpt.RptFilename()), DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
        }
    }
Exemplo n.º 12
0
        private void simpleAction1_Execute_1(object sender, SimpleActionExecuteEventArgs e)
        {
            MauIn     mauIn     = (MauIn)View.CurrentObject;
            NguoiDung nguoiDung = mauIn.Session.GetObjectByKey <NguoiDung>(SecuritySystem.CurrentUserId);

            //Name of files
            FileData chungNhan    = mauIn.fileMau;
            string   fileName     = chungNhan.FileName;
            string   fileNameTemp = @"TempFile\" + fileName;
            string   fileNameSave = @"SaveFile\" + fileName;

            //Names of fields in files
            //if (nguoiDung.thanhVien.TenNguoiDung != null) ;
            string   tenNguoiDung = nguoiDung.thanhVien.TenNguoiDung != null? nguoiDung.thanhVien.TenNguoiDung:"";
            DateTime _ngaySinh    = (DateTime)nguoiDung.thanhVien.ngaySinh;
            string   ngaySinh     = _ngaySinh.ToString("dd-MM-yyyy") != null?_ngaySinh.ToString("dd-MM-yyyy") : "";//Edit format of DateTime

            string gioiTinh = nguoiDung.thanhVien.ToString() != null?nguoiDung.thanhVien.ToString() : "";

            string MSSV   = nguoiDung.thanhVien.MSSV != null ? nguoiDung.thanhVien.MSSV : "";
            string khoa   = nguoiDung.thanhVien.khoaString != null ? nguoiDung.thanhVien.khoaString : "";
            string SDT    = nguoiDung.thanhVien.SDT != null ? nguoiDung.thanhVien.SDT : "";
            string email  = nguoiDung.thanhVien.email != null ? nguoiDung.thanhVien.email : "";
            string diaChi = nguoiDung.thanhVien.diaChi != null ? nguoiDung.thanhVien.diaChi : "";

            //int soLanIn = nguoiDung.soLanIn;


            using (RichEditDocumentServer srv = new RichEditDocumentServer())
            {
                if (srv.LoadDocument(fileNameTemp, DocumentFormat.OpenXml))
                {
                    Document doc = srv.Document;
                    //tenNguoiDung
                    DocumentRange[] ranges = doc.FindAll("<tenNguoiDung>", SearchOptions.None);
                    for (int i = 0; i < ranges.Length; i++)
                    {
                        doc.Replace(ranges[i], tenNguoiDung);
                    }
                    //ngaySinh
                    DocumentRange[] range1s = doc.FindAll("<ngaySinh>", SearchOptions.None);
                    for (int i = 0; i < range1s.Length; i++)
                    {
                        doc.Replace(range1s[i], ngaySinh);
                    }
                    //gioiTinh
                    DocumentRange[] range2s = doc.FindAll("<gioiTinh>", SearchOptions.None);
                    for (int i = 0; i < range2s.Length; i++)
                    {
                        doc.Replace(range2s[i], gioiTinh);
                    }
                    //MSSV
                    DocumentRange[] range3s = doc.FindAll("<MSSV>", SearchOptions.None);
                    for (int i = 0; i < range3s.Length; i++)
                    {
                        doc.Replace(range3s[i], MSSV);
                    }
                    //khoa
                    DocumentRange[] range4s = doc.FindAll("<khoa>", SearchOptions.None);
                    for (int i = 0; i < range4s.Length; i++)
                    {
                        doc.Replace(range4s[i], khoa);
                    }
                    //SDT
                    DocumentRange[] range5s = doc.FindAll("<SDT>", SearchOptions.None);
                    for (int i = 0; i < range5s.Length; i++)
                    {
                        doc.Replace(range5s[i], SDT);
                    }
                    //email
                    DocumentRange[] range6s = doc.FindAll("<email>", SearchOptions.None);
                    for (int i = 0; i < range6s.Length; i++)
                    {
                        doc.Replace(range6s[i], email);
                    }
                    //diaChi
                    DocumentRange[] range7s = doc.FindAll("<diaChi>", SearchOptions.None);
                    for (int i = 0; i < range7s.Length; i++)
                    {
                        doc.Replace(range7s[i], diaChi);
                    }
                }
                srv.SaveDocument(fileNameSave, DocumentFormat.OpenXml);
                //srv.Document.Sections[0].Page.Landscape = true;

                //DevExpress.XtraPrinting.PrintableComponentLink link = new DevExpress.XtraPrinting.PrintableComponentLink(new DevExpress.XtraPrinting.PrintingSystem());

                if (nguoiDung.soLanIn > 0)
                {
                    srv.Print();
                    nguoiDung.soLanIn--;
                    MessageBox.Show("You have " + nguoiDung.soLanIn.ToString() + " more time(s) to PRINT");
                    nguoiDung.Save();// lưu lại giá trị
                }
                else
                {
                    MessageBox.Show("Your print time has run out!");
                }


                //FileStream fsOut = File.Open("FileOut.pdf", FileMode.Create);
                //srv.ExportToPdf(fsOut);
                //fsOut.Close();
            }
            //RichEditDocumentServer srv1 = new RichEditDocumentServer();
            //srv1.LoadDocument(fileNameTemp, DocumentFormat.OpenXml);
            //DevExpress.XtraPrinting.PdfExportOptions options = new DevExpress.XtraPrinting.PdfExportOptions();
            //options.Compressed = false;
            //options.ImageQuality = DevExpress.XtraPrinting.PdfJpegImageQuality.Highest;
            //FileStream pdfFileStream = new FileStream("Document_PDF.pdf", FileMode.Create);
            //srv1.ExportToPdf(pdfFileStream, options);

            //System.Diagnostics.Process.Start("Document_PDF.pdf");

            //System.Diagnostics.Process.Start(fileNameSave);
            //FileAttachmentsWindowsFormsModule.GetFileDataManager(Application).Open(chungNhan);//Open FileData
            //PreviewPrint previewPrintWindow = new PreviewPrint();
            //previewPrintWindow.ShowDialog();
        }