This post includes a series of interesting support tickets answered throughout August and September along with a breaking change notice. It also includes a list of enhancements made to our Office-inspired product line. We hope you find the contents of this post interesting and of business value. Should you have any questions about this post, feel free to comment below.
Breaking Change
T1032641 - The PdfChoiceFormFieldFacade<T> class and its descendants were changed
https://supportcenter.devexpress.com/ticket/details/t1032641
With our most recent update (v21.1.6), the MultiSelect and Value properties were moved from the PdfChoiceFormFieldFacade<T> class to its descendants: PdfComboBoxFormFieldFacade and PdfListBoxFormFieldFacade. The latter class now includes a Values property that allows you to specify multiple values for a list box form field.
If you need to specify a single value for a list box form field, use the PdfListBoxFormFieldFacade.Values property in the following manner:
using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
{
pdfDocumentProcessor.LoadDocument("Documents//FormDemo.pdf");
PdfDocumentFacade documentFacade = pdfDocumentProcessor.DocumentFacade;
PdfAcroFormFacade acroForm = documentFacade.AcroForm;
PdfListBoxFormFieldFacade listField = acroForm.GetListBoxFormField("List");
listField.Values = new List<string>() { listField.Items[2].Value };
pdfDocumentProcessor.SaveDocument("Documents//Result.pdf");
}
Tips & Tricks
Word Processing Document API
T1019089 - How to use the Word Processing Document API to insert an image into the MVC Rich Text Editor
https://supportcenter.devexpress.com/ticket/details/t1019089T1026292 - How to obtain custom document properties
https://supportcenter.devexpress.com/ticket/details/t1026292The Document.CustomProperties property returns custom properties. To access an individual property, obtain the property’s name, and pass this name to the indexer. The following code sample retrieves all custom properties:
using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Native; using System.Linq; using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer()) { // Load document wordProcessor.LoadDocument("Document.docx"); // Access custom property collection DocumentCustomProperties customProperties = wordProcessor.Document.CustomProperties; for (int i = 0; i <= customProperties.Count-1; i++) { // Get property name string propertyName = customProperties.Names.ElementAt(i); // Retrieve property by its name var property = customProperties[propertyName]; // Your code here } }
T1025985 - How to display a Data Table below a chart
https://supportcenter.devexpress.com/ticket/details/t1025985
WinForms and WPF Rich Text Editors
T1024436 - How to copy and paste data between two Rich Text Editors
https://supportcenter.devexpress.com/ticket/details/t1024436T1023401 - How to create a check box
https://supportcenter.devexpress.com/ticket/details/t1023401T1030196 - How to highlight text in the Rich Text Editor without affecting the Undo/Redo operations
https://supportcenter.devexpress.com/ticket/details/t1030196T1031306 - How to show a tooltip above DOCVARIABLE fields
https://supportcenter.devexpress.com/ticket/details/t1031306T1023404 - How to change the predefined "Standard Colors" collection in the Font Color ribbon item
https://supportcenter.devexpress.com/ticket/details/t1023404/T1018913 - How to disable Tab navigation in the read-only Rich Text Editor
https://supportcenter.devexpress.com/ticket/details/t1018913T1019920 – How to allow scrolling in the WPF Rich Text Editor located in ScrollViewer
https://supportcenter.devexpress.com/ticket/details/t1019920T1029650 - How to show all field codes in a document
https://supportcenter.devexpress.com/ticket/details/t1029650
Spreadsheet Document API
T1024059 - How to merge data from multiple worksheets into a single worksheet
https://supportcenter.devexpress.com/ticket/details/t1024059Call the CellRange.CopyFrom method to copy data (e.g., text, numbers, and formula calculated values) from one worksheet to another. Use the GetDataRange method to retrieve a data range from a source worksheet.
using DevExpress.Spreadsheet; using (var targetWorkbook = new Workbook()) { // Specify copy options if needed targetWorkbook.Options.Copy.KeepSourceThemeColors = true; targetWorkbook.Options.Copy.KeepSourceThemeFonts = true; var targetWorksheet = targetWorkbook.Worksheets[0]; using (var sourceWorkbook = new Workbook()) { // Load source worksheet sourceWorkbook.LoadDocument("merge.xlsx"); int topRowIndex = 0; foreach (var sourceWorksheet in sourceWorkbook.Worksheets) { if (!sourceWorksheet.HasData) continue; // Retrieve data from source worksheet var sourceRange = sourceWorksheet.GetDataRange(); // Define target worksheet area to paste data int rightColumnIndex = sourceRange.ColumnCount - 1; int bottomRowIndex = topRowIndex + sourceRange.RowCount - 1; var targetRange = targetWorksheet.Range.FromLTRB(0, topRowIndex, rightColumnIndex, bottomRowIndex ); // Copy data from one worksheet to another targetRange.CopyFrom(sourceRange, PasteSpecial.Values | PasteSpecial.Formats); topRowIndex += sourceRange.RowCount; } } targetWorkbook.SaveDocument("result.xlsx"); }
WinForms and WPF Spreadsheet Controls
T1019060 - How to bind the Spreadsheet control to data from a stored procedure
https://supportcenter.devexpress.com/ticket/details/t1019060T1025957 - How to resize columns in the read-only Spreadsheet control
https://supportcenter.devexpress.com/ticket/details/t1025957
PDF Document API
T1025879 - How to add a stamp to a PDF file
https://supportcenter.devexpress.com/ticket/details/t1025879You can use the PDF Graphics API to draw an image (stamp) on a page. The code sample below draws an image in the corner of the page:
using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) { // Load document documentProcessor.LoadDocument("Document.pdf"); // Create PDF graphics using (PdfGraphics graph = documentProcessor.CreateGraphics()) { // Draw image graph.DrawImage(File.ReadAllBytes("Documents//stamp.png"), new System.Drawing.PointF(500, 50)); // Add image to the page foreground graph.AddToPageForeground(documentProcessor.Document.Pages[0]); } // Save the result documentProcessor.SaveDocument("result.pdf"); }
Note: We are going to enhance annotation support in our upcoming major release (v21.2). Our new API will allow you to add interactive rubber stamp annotations.
Enhancements
Spreadsheet Document API and Spreadsheet Controls (for WinForms and WPF)
T1024708 - We implemented new ColumnCollection.Insert method overloads that allow you to format inserted columns
https://supportcenter.devexpress.com/ticket/details/t1024708ColumnCollection.Insert methods now accept the formatMode parameter and allow you to specify how to format inserted columns. The following options are supported:
- ColumnFormatMode.FormatAsNext - New columns have the same formatting as the column to the right of inserted columns.
- ColumnFormatMode.FormatAsPrevious - New columns have the same formatting as the column to the left of inserted columns.
- ColumnFormatMode.None - Inserted columns have no formatting applied.
The following example inserts two columns ("B" and "C") with the same format settings as column "A":
worksheet.Columns.Insert("B", 2, ColumnFormatMode.FormatAsPrevious);
T1017380 – We added a SpreadsheetCompatibilityOptions.TruncateLongStringsInFormulas option to load documents containing formulas with text values longer than 255 characters
https://supportcenter.devexpress.com/ticket/details/t1017380Disable this property to allow users to load documents that contain formulas with string values longer than 255 characters.
spreadsheetControl1.Options.Compatibility.TruncateLongStringsInFormulas = false;
Consider the following restrictions:
The following message appears when a user edits a formula with string values longer than 255 characters:
- Text values in formulas are truncated to 255 characters when you export a document to Excel formats (for example, XLSX, XLSB, XLS, or XML Spreadsheet 2003).
We recommend that you use the CONCATENATE function or the concatenation operator (&) to create formulas with text values longer than 255 characters. The following example iterates through all formulas in a workbook and splits long strings with the CONCATENATE function:
Spreadsheet - How to use the CONCATENATE function to update formulas with text values longer than 255 characters
PDF Document API
T1019054 - We added a PdfSignatureInfo.Contents property to return signature contents
https://supportcenter.devexpress.com/ticket/details/t1019054Call the PdfDocumentSigner.GetSignatureInfo method to retrieve the list of PdfSignatureInfo objects that contain information about document signatures. Use the Contents property to obtain content bytes for each signature.
using (var signer = new PdfDocumentSigner(fileName)) { var signatures = signer.GetSignatureInfo(); if (signatures.Count > 0) { // Return the first signature value. var signatureBytes = signatures[0].Contents; } }
New Example: Word Processing Document API
This new example demonstrates how to use the Layout API to execute the following page actions:
- Get page text
- Get page number and page count
- Search for text on a specific page
Use the RichEditDocumentServer.DocumentLayout property as an entry point to the Layout API.
Layout API - How to perform page-based operations
As always, if you’ve come across an interesting support ticket you’d like to share with the rest of the DevExpress developer community, please comment below and include the appropriate link.