// Fourth stage. For each Order ID create a detailed document that will be inserted in place of the DOCVARIABLE field. // This is the final stage and the Product.Orders template does not contain DOCVARIABLE fields. So, further processing is not required. void richServerDetailProcessor_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e) { int currentProductID = GetID(e.Arguments[0].Value); if (currentProductID == -1) { return; } if (productID != currentProductID) { // Get data source that contains orders for the specified product and supplier. dataDetailedForOrders = (List <OrderDetail>)GetOrderDataFilteredbyProductAndSupplier(supplierID, currentProductID); productID = currentProductID; } if (e.VariableName == "OrderDetails") { IRichEditDocumentServer richServerOrdersTemplate = mainRichEdit.CreateDocumentServer(); RtfLoadHelper.Load("detaildetail.rtf", richServerOrdersTemplate); richServerOrdersTemplate.Options.MailMerge.DataSource = dataDetailedForOrders; IRichEditDocumentServer richServerDetailDetailProcessor = mainRichEdit.CreateDocumentServer(); MailMergeOptions options = richServerOrdersTemplate.CreateMailMergeOptions(); options.MergeMode = MergeMode.JoinTables; richServerOrdersTemplate.MailMerge(options, richServerDetailDetailProcessor); e.Value = richServerDetailDetailProcessor; e.Handled = true; } }
private static void exportFileToPath(IRichEditDocumentServer documentServer, string filePath) { using (var fs = new FileStream(filePath, FileMode.Create)) { documentServer.SaveDocument(fs, DocumentFormat.OpenXml); } }
private void ResultRichEdit_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e) { //Check whether the event is raised to the required field: if (e.VariableName == "Categories") { //Provide the data source for the next document part: masterRichEdit.Options.MailMerge.DataSource = categories; //Create a new RichEditDocumentServer for further processing: IRichEditDocumentServer result = masterRichEdit.CreateDocumentServer(); //Subscribe the new instance to the CalculateDocumentVariable event to handle the detail part: result.CalculateDocumentVariable += result_CalculateDocumentVariable; //Set additional mail merge options if necessary: MailMergeOptions options = masterRichEdit.CreateMailMergeOptions(); options.LastRecordIndex = 4; //Merge the document and pass it to the RichEditDocumentServer: masterRichEdit.MailMerge(options, result.Document); result.CalculateDocumentVariable -= result_CalculateDocumentVariable; e.Value = result; e.Handled = true; } }
private void addPageToDocument(JournalPage page, IRichEditDocumentServer documentServer) { var document = getDocumentFor(page); addTitle(page, document); insertPageInNewSection(documentServer, document, page); }
private void addPagesToDocument(IReadOnlyList <JournalPage> orderedPages, IRichEditDocumentServer documentServer) { var firstPage = orderedPages.FirstOrDefault(); insertFirstPage(firstPage, documentServer); orderedPages.Except(new[] { firstPage }).Each(page => { addPageToDocument(page, documentServer); }); }
private void resetLandscape(IRichEditDocumentServer documentServer) { documentServer.Document.Sections.Each(section => { section.Page.Landscape = false; section.Page.Width = _pageWidth; }); }
private void insertPageInNewSection(IRichEditDocumentServer documentServer, Document document, JournalPage page) { var section = documentServer.Document.AppendSection(); createHeader(section, page); createFooter(section, page); documentServer.Document.AppendDocumentContent(document.Range); }
static void buttonCustomAction_ItemClick_DocumentServer(object sender, ItemClickEventArgs e) { RichEditControl richEdit = e.Item.Tag as RichEditControl; IRichEditDocumentServer server = richEdit.CreateDocumentServer(); using (System.IO.FileStream fs = new System.IO.FileStream("Documents\\DocumentServerTest.docx", System.IO.FileMode.Open)) { server.LoadDocument(fs, DevExpress.XtraRichEdit.DocumentFormat.OpenXml); richEdit.Document.InsertDocumentContent(richEdit.Document.CaretPosition, server.Document.Range); } }
private void Form1_Load(object sender, EventArgs e) { richEditControl1.ReplaceService <ISyntaxHighlightService>(new HTMLSyntaxHighlightService(richEditControl1)); using (IRichEditDocumentServer server = richEditControl1.CreateDocumentServer()) { server.Text = "some HTML text"; richEditControl1.Text = server.HtmlText; } richEditControl1.Document.DefaultCharacterProperties.FontName = "Consolas"; richEditControl1.Document.DefaultCharacterProperties.FontSize = 9; }
private void exportAndOpenDocument(IRichEditDocumentServer documentServer) { var savedDocument = exportDocumentAsWordFile(documentServer); if (string.IsNullOrEmpty(savedDocument)) { return; } FileHelper.TryOpenFile(savedDocument); }
private string exportDocumentAsWordFile(IRichEditDocumentServer documentServer) { var filePath = getFileNameForExport(); if (string.IsNullOrEmpty(filePath)) { return(string.Empty); } FileHelper.TrySaveFile(filePath, () => exportFileToPath(documentServer, filePath)); return(filePath); }
void result_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e) { ArgumentCollection arguments = e.Arguments; int currentCategoryID = GetID(arguments[0].Value); if (currentCategoryID == -1) { return; } if (categoryID != currentCategoryID) { currentDataSetProducts = GetData(currentCategoryID).ToList(); categoryID = currentCategoryID; } if (e.VariableName == "Products") { detailRichEditControl.Options.MailMerge.DataSource = currentDataSetProducts; IRichEditDocumentServer result = detailRichEditControl.CreateDocumentServer(); MailMergeOptions options = detailRichEditControl.CreateMailMergeOptions(); options.MergeMode = MergeMode.JoinTables; result.CalculateDocumentVariable += detail_CalculateDocumentVariable; detailRichEditControl.MailMerge(options, result.Document); result.CalculateDocumentVariable -= detail_CalculateDocumentVariable; e.Value = result; e.Handled = true; } if (e.VariableName == "LowestPrice") { e.Value = currentDataSetProducts.Min(p => p.UnitPrice); e.Handled = true; } if (e.VariableName == "HighestPrice") { e.Value = currentDataSetProducts.Max(p => p.UnitPrice); e.Handled = true; } if (e.VariableName == "ItemsCount") { e.Value = currentDataSetProducts.Count(); e.Handled = true; } if (e.VariableName == "TotalSales") { e.Value = GetTotalSales(arguments); e.Handled = true; } }
private static void SetPrintOptions(IRichEditDocumentServer richedit) { foreach (Section _section in richedit.Document.Sections) { _section.Page.PaperKind = System.Drawing.Printing.PaperKind.A4; _section.Page.Landscape = false; _section.Margins.Left = 150f; _section.Margins.Right = 150f; _section.Margins.Top = 50f; _section.Margins.Bottom = 50f; _section.PageNumbering.NumberingFormat = NumberingFormat.CardinalText; _section.PageNumbering.FirstPageNumber = 0; } }
private void insertFirstPage(JournalPage firstPage, IRichEditDocumentServer documentServer) { var document = documentServer.Document; loadContentFor(firstPage); loadDocumentServer(firstPage, documentServer); addTitle(firstPage, document); var section = document.GetSection(document.CaretPosition); createFooter(section, firstPage); createHeader(section, firstPage); }
void resultingRichEditControl_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e) { if (e.VariableName == "Categories") { masterRichEditControl.Options.MailMerge.DataSource = dataSetCategories.ToList(); IRichEditDocumentServer result = masterRichEditControl.CreateDocumentServer(); result.CalculateDocumentVariable += result_CalculateDocumentVariable; masterRichEditControl.MailMerge(result.Document); result.CalculateDocumentVariable -= result_CalculateDocumentVariable; e.Value = result; e.Handled = true; } }
void Document_CalculateDocumentVariable(object sender, DevExpress.XtraRichEdit.CalculateDocumentVariableEventArgs e) { if (filesCollection.ContainsKey(e.VariableName)) { IRichEditDocumentServer server = richEditControl1.CreateDocumentServer(); FileFieldInfo info = filesCollection[e.VariableName]; server.Document.Images.Insert(server.Document.Range.End, new Bitmap(Icon.ExtractAssociatedIcon(info.FullFileName).ToBitmap(), new Size(16, 16))); DocumentRange range = server.Document.AppendText(info.FileName + "; "); Hyperlink hyperlink = server.Document.Hyperlinks.Create(range.Start, range.Length - 1); hyperlink.Target = info.FullFileName; hyperlink.ToolTip = info.FileName; hyperlink.NavigateUri = info.FullFileName; e.Value = server.Document; e.Handled = true; } }
private void result_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e) { //Check whether the event is raised for the required field: if (e.VariableName == "Products") { //Provide the detail part with the data source: detailRichEdit.Options.MailMerge.DataSource = products; //Create an intermediate document server instance: IRichEditDocumentServer result = detailRichEdit.CreateDocumentServer(); //Set the merged ranges delimitation and a number of records to be merged: MailMergeOptions options = detailRichEdit.CreateMailMergeOptions(); options.MergeMode = MergeMode.JoinTables; options.LastRecordIndex = 10; //Provide a procedure for further processing: result.CalculateDocumentVariable += detail_CalculateDocumentVariable; // Create a merged document with a detail template: detailRichEdit.MailMerge(options, result.Document); result.CalculateDocumentVariable -= detail_CalculateDocumentVariable; e.Value = result; e.Handled = true; } //Format other merged fields: if (e.VariableName == "LowestPrice") { e.Value = String.Format(cultureInfo, "{0:C2}", products.Compute("Min(UnitPrice)", String.Empty)); e.Handled = true; } if (e.VariableName == "HighestPrice") { e.Value = String.Format(cultureInfo, "{0:C2}", products.Compute("Max(UnitPrice)", String.Empty)); e.Handled = true; } if (e.VariableName == "ItemsCount") { e.Value = products.Rows.Count; e.Handled = true; } }
protected override void Context() { _projectRetriever = A.Fake <IProjectRetriever>(); _dialogCreator = A.Fake <IDialogCreator>(); _contentLoader = A.Fake <IContentLoader>(); FileHelper.TryOpenFile = s => _triedFileName = s; _richEditDocumentServerFactory = A.Fake <IRichEditDocumentServerFactory>(); _documentServer = A.Fake <IRichEditDocumentServer>(); _document = A.Fake <Document>(); A.CallTo(() => _document.AppendSection()).Invokes(() => _sectionCount++).ReturnsLazily <Section>(A.Fake <Section>); A.CallTo(() => _document.Sections.Count).ReturnsLazily(() => _sectionCount); A.CallTo(() => _richEditDocumentServerFactory.Create()).Returns(_documentServer); A.CallTo(() => _documentServer.Document).Returns(_document); // document starts with one section always _sectionCount = 1; sut = new JournalExportTask(_contentLoader, _dialogCreator, _projectRetriever, _richEditDocumentServerFactory); }
// Third stage. For each Product ID create a detailed document that will be inserted in place of the DOCVARIABLE field. void richServerMasterProcessor_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e) { int currentSupplierID = GetID(e.Arguments[0].Value); if (currentSupplierID == -1) { return; } if (supplierID != currentSupplierID) { // Get data source that contains products for the specified supplier. dataDetailedForProducts = (List <Product>)GetProductsDataFilteredbySupplier(currentSupplierID); supplierID = currentSupplierID; } if (e.VariableName == "Product") { // Create a document container and load a document containing the Product header section (detail section) IRichEditDocumentServer richServerProductsTemplate = mainRichEdit.CreateDocumentServer(); RtfLoadHelper.Load("detail.rtf", richServerProductsTemplate); // Create a text engine to process a document after the mail merge. IRichEditDocumentServer richServerDetailProcessor = mainRichEdit.CreateDocumentServer(); // Specify data source for mail merge. richServerProductsTemplate.Options.MailMerge.DataSource = dataDetailedForProducts; // Specify that the resulting table should be joined with the header table. // Do not specify this option if calculated fields are not within table cells. MailMergeOptions options = richServerProductsTemplate.CreateMailMergeOptions(); options.MergeMode = MergeMode.JoinTables; // Provide a procedure for further processing. richServerDetailProcessor.CalculateDocumentVariable += new CalculateDocumentVariableEventHandler(richServerDetailProcessor_CalculateDocumentVariable); // Create a merged document using the Product template. The document will contain DOCVARIABLE fields with OrderID arguments. // The CalculateDocumentVariable event for the richServerDetail fires. richServerProductsTemplate.MailMerge(options, richServerDetailProcessor); richServerDetailProcessor.CalculateDocumentVariable -= richServerDetailProcessor_CalculateDocumentVariable; // Return the document to insert. e.Value = richServerDetailProcessor; // This setting is required for inserting e.Value into the source document. Otherwise it will be ignored. e.Handled = true; } }
static void buttonCustomAction_ItemClick_LoadDocument(object sender, ItemClickEventArgs e) { RichEditControl richEdit = e.Item.Tag as RichEditControl; IRichEditDocumentServer documentServer = richEdit.CreateDocumentServer(); using (FileStream fs = new FileStream("Documents\\testDocumentDOCX.docx", FileMode.Open)) { documentServer.LoadDocument(fs, DevExpress.XtraRichEdit.DocumentFormat.OpenXml); richEdit.Document.AppendDocumentContent(documentServer.Document.Range); } using (FileStream fs = new FileStream("Documents\\testDocumentRTF.rtf", FileMode.Open)) { documentServer.LoadDocument(fs, DevExpress.XtraRichEdit.DocumentFormat.Rtf); richEdit.Document.AppendDocumentContent(documentServer.Document.Range); } using (FileStream fs = new FileStream("Documents\\testDocumentHTML.html", FileMode.Open)) { documentServer.LoadDocument(fs, DevExpress.XtraRichEdit.DocumentFormat.Html); richEdit.Document.AppendDocumentContent(documentServer.Document.Range); } }
// Second stage. For each Supplier ID create a detailed document that will be inserted in place of the DOCVARIABLE field. void resultRichEdit_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e) { if (e.VariableName == "Supplier") { // Create a document container and load a document containing the Supplier header section (master section) IRichEditDocumentServer richServerSupplierTemplate = mainRichEdit.CreateDocumentServer(); RtfLoadHelper.Load("supplier.rtf", richServerSupplierTemplate); // Create a text engine to process a document after the mail merge. IRichEditDocumentServer richServerMasterProcessor = mainRichEdit.CreateDocumentServer(); // Provide a procedure for further processing richServerMasterProcessor.CalculateDocumentVariable += new CalculateDocumentVariableEventHandler(richServerMasterProcessor_CalculateDocumentVariable); // Create a merged document using the Supplier template. The document will contain DOCVARIABLE fields with ProductID arguments. // The CalculateDocumentVariable event for the richServerMasterProcessor fires. // Note that the data source for mail merge should be specified via the RichEditDocumentServer.Options.MailMerge.DataSource property. richServerSupplierTemplate.Options.MailMerge.DataSource = dataSuppliers; richServerSupplierTemplate.MailMerge(richServerMasterProcessor.Document); richServerMasterProcessor.CalculateDocumentVariable -= richServerMasterProcessor_CalculateDocumentVariable; // Return the document to insert in place of the DOCVARIABLE field. e.Value = richServerMasterProcessor; // Required. Otherwise e.Value will be ignored. e.Handled = true; } }
public static void Load(String fileName, IRichEditDocumentServer richEditControl) { Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MasterDetailExample" + "." + fileName); richEditControl.LoadDocument(stream, DocumentFormat.Rtf); }
protected virtual void SaveBookToFile(IRichEditDocumentServer bookServer, string fileName, SaveOptions options) { var format = DocumentFormat.OpenXml; switch (Path.GetExtension(fileName)?.ToLower()) { case ".docx": format = DocumentFormat.OpenXml; break; case ".doc": format = DocumentFormat.Doc; break; case ".txt": case ".text": format = DocumentFormat.PlainText; break; case ".rtf": format = DocumentFormat.Rtf; break; case ".html": case ".htm": format = DocumentFormat.Html; break; case ".mht": format = DocumentFormat.Mht; break; case ".odt": format = DocumentFormat.OpenDocument; break; case ".epub": format = DocumentFormat.ePub; break; case ".pdf": format = DocumentFormat.Undefined; break; } if (format == DocumentFormat.Undefined) { var pdfOptions = new PdfExportOptions() { ConvertImagesToJpeg = false, ImageQuality = PdfJpegImageQuality.Highest, PdfACompatibility = PdfACompatibility.None, ShowPrintDialogOnOpen = false }; using var ps = new PrintingSystem(); using var link = new PrintableComponentLink(ps) { Component = bookServer as IPrintable }; link.CreateDocument(); ExecuteLocked(() => ps.ExportToPdf(fileName, pdfOptions), (options?.LockFiles ?? false) ? LockObject : null); } else { ExecuteLocked(() => bookServer.Document.SaveDocument(fileName, format), (options?.LockFiles ?? false) ? LockObject : null); } }
static void ProcessWorkbook(IWorkbook workbook, string tableName, bool rebuild, out IRichEditDocumentServer richEditDocumentServer) { richEditDocumentServer = null; if (rebuild) { workbook.CalculateFullRebuild(); } CellRange range = null; int p = tableName.IndexOf('!'); if (p >= 0) { var worksheetName = tableName.Substring(0, p); var worksheetTableName = tableName[(p + 1)..];
public static void RegisterProvider(IRichEditDocumentServer server) { var uriStreamService = server.GetService <IUriStreamService>(); uriStreamService.RegisterProvider(new ProjectUriStreamProvider()); }
protected IRichEditDocumentServer AddSpreadTable(ArgumentCollection arguments) { if (arguments.Count <= 0) { throw new Exception("'DOCVARIABLE SPREADTABLE' requires filename as first argument."); } if (arguments.Count <= 1) { throw new Exception("'DOCVARIABLE SPREADTABLE' requires table or range as second argument."); } var fileName = arguments[0].Value; if (string.IsNullOrWhiteSpace(fileName)) { throw new Exception("DOCVARIABLE SPREADTABLE does not contain valid filename."); } object snippet = null; if (Snippets?.ContainsKey(fileName) ?? false) { snippet = Snippets[fileName]; if (snippet is SCSpreadsheetContext) { } else { throw new Exception($"Specified snippet '{fileName}' is not supported. Snippet shall be Spreadsheet."); } } else if (string.Compare(fileName, "$SPREAD", true) == 0) { //Do nothing } else { fileName = Project.Current.MapPath(fileName); } if (snippet == null && string.Compare(fileName, "$SPREAD", true) != 0 && !File.Exists(fileName)) { throw new Exception($"File '{fileName}' does not exist."); } var tableName = arguments[1].Value; bool rebuild = false; if (arguments.Count > 2) { var properties = Utils.SplitNameValueString(arguments[2].Value, ';'); foreach (var prop in properties) { if (string.IsNullOrWhiteSpace(prop.Key)) { continue; } switch (prop.Key.ToLower()) { case "rebuild": case "recalculate": case "recalc": var valueRebuild = prop.Value; if (string.IsNullOrWhiteSpace(valueRebuild)) { valueRebuild = bool.TrueString; } rebuild = bool.Parse(valueRebuild); break; } } } bool needDispose = true; IWorkbook workbook = null; try { //using var workbook = SpreadsheetUtils.CreateWorkbook(); if (snippet is SCSpreadsheetContext spreadsheetContext) { workbook = SpreadsheetUtils.CreateWorkbook(); workbook.Append(spreadsheetContext.Workbook); } else if (string.Compare(fileName, "$SPREAD", true) == 0) { needDispose = false; workbook = this.DefaultSpreadsheet; if (workbook == null) { throw new Exception("Current script does not support default (Host) spreadsheet."); } } else { workbook = SpreadsheetUtils.CreateWorkbook(); workbook.LoadDocument(fileName); } IRichEditDocumentServer result = null; if (workbook == this.DefaultSpreadsheet && NeedSynchronizeDefaultSpreadsheet) { SCDispatcherService.UIDispatcherServer.Invoke(() => ProcessWorkbook(workbook, tableName, rebuild, out result)); } else { ProcessWorkbook(workbook, tableName, rebuild, out result); } return(result); } finally { if (needDispose && workbook != null) { workbook.Dispose(); } }
public static void OnSelectionChanged(this IRichEditDocumentServer server) { var documentServer = server.GetPropertyValue("InnerDocumentServer"); documentServer.GetType().Method("OnSelectionChanged").Call(documentServer, null, null); }
public static IObservable <IRichEditDocumentServer> WhenSelectionChanged(this IRichEditDocumentServer server) => Observable.FromEventPattern <EventHandler, EventArgs>(h => server.SelectionChanged += h, h => server.SelectionChanged -= h, EventsScheduler) .TransformPattern <EventArgs, IRichEditDocumentServer>() .Select(_ => _.sender);
private static void SelectActiveStyle(this IRichEditDocumentServer server, (DetailView view, Document defaultPropertiesProvider) detailView)
private static object VScrollBar(this IRichEditDocumentServer server) { return(((IEnumerable)server.GetPropertyValue("Controls")).Cast <object>() .First(o => o?.GetType().FullName == "DevExpress.XtraEditors.VScrollBar")); }