FieldMergeBarcode Class |
Namespace: Aspose.Words.Fields
The FieldMergeBarcode type exposes the following members.
Name | Description | |
---|---|---|
![]() | FieldMergeBarcode | Initializes a new instance of the FieldMergeBarcode class |
Name | Description | |
---|---|---|
![]() ![]() | AddStartStopChar |
Gets or sets whether to add Start/Stop characters for barcode types NW7 and CODE39.
|
![]() ![]() | BackgroundColor |
Gets or sets the background color of the barcode symbol. Valid values are in the range [0, 0xFFFFFF]
|
![]() ![]() | BarcodeType |
Gets or sets the barcode type (QR, etc.)
|
![]() ![]() | BarcodeValue |
Gets or sets the barcode value.
|
![]() ![]() | CaseCodeStyle |
Gets or sets the style of a Case Code for barcode type ITF14. The valid values are [STD|EXT|ADD]
|
![]() ![]() | DisplayResult |
Gets the text that represents the displayed field result.
(Inherited from Field.) |
![]() ![]() | DisplayText |
Gets or sets whether to display barcode data (text) along with image.
|
![]() ![]() | End |
Gets the node that represents the field end.
(Inherited from Field.) |
![]() ![]() | ErrorCorrectionLevel |
Gets or sets an error correction level of QR Code. Valid values are [0, 3].
|
![]() ![]() | FixCheckDigit |
Gets or sets whether to fix the check digit if it’s invalid.
|
![]() ![]() | ForegroundColor |
Gets or sets the foreground color of the barcode symbol. Valid values are in the range [0, 0xFFFFFF]
|
![]() ![]() | Format |
Gets a FieldFormat object that provides typed access to field's formatting.
(Inherited from Field.) |
![]() ![]() | IsDirty |
Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
(Inherited from Field.) |
![]() ![]() | IsLocked |
Gets or sets whether the field is locked (should not recalculate its result).
(Inherited from Field.) |
![]() ![]() | LocaleId |
Gets or sets the LCID of the field.
(Inherited from Field.) |
![]() ![]() | PosCodeStyle |
Gets or sets the style of a Point of Sale barcode (barcode types UPCA|UPCE|EAN13|EAN8). The valid values (case insensitive) are [STD|SUP2|SUP5|CASE].
|
![]() ![]() | Result |
Gets or sets text that is between the field separator and field end.
(Inherited from Field.) |
![]() ![]() | ScalingFactor |
Gets or sets a scaling factor for the symbol. The value is in whole percentage points and the valid values are [10, 1000]
|
![]() ![]() | Separator |
Gets the node that represents the field separator. Can be null.
(Inherited from Field.) |
![]() ![]() | Start |
Gets the node that represents the start of the field.
(Inherited from Field.) |
![]() ![]() | SymbolHeight |
Gets or sets the height of the symbol. The units are in TWIPS (1/1440 inch).
|
![]() ![]() | SymbolRotation |
Gets or sets the rotation of the barcode symbol. Valid values are [0, 3]
|
![]() ![]() | Type |
Gets the Microsoft Word field type.
(Inherited from Field.) |
Name | Description | |
---|---|---|
![]() | Equals | (Inherited from Object.) |
![]() ![]() | GetFieldCode |
Returns text between field start and field separator (or field end if there is no separator).
Both field code and field result of child fields are included.
(Inherited from Field.) |
![]() ![]() | GetFieldCode(Boolean) |
Returns text between field start and field separator (or field end if there is no separator).
(Inherited from Field.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetType | (Inherited from Object.) |
![]() ![]() | Remove |
Removes the field from the document. Returns a node right after the field. If the field's end is the last child
of its parent node, returns its parent paragraph. If the field is already removed, returns null.
(Inherited from Field.) |
![]() | ToString | (Inherited from Object.) |
![]() ![]() | Unlink |
Performs the field unlink.
(Inherited from Field.) |
![]() ![]() | Update |
Performs the field update. Throws if the field is being updated already.
(Inherited from Field.) |
![]() ![]() | Update(Boolean) |
Performs a field update. Throws if the field is being updated already.
(Inherited from Field.) |
public void FieldMergeBarcode_QR() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a QR code FieldMergeBarcode field = (FieldMergeBarcode) builder.InsertField(FieldType.FieldMergeBarcode, true); field.BarcodeType = "QR"; // In a DISPLAYBARCODE field, the BarcodeValue attribute decides what value the barcode will display // However in our MERGEBARCODE fields, it has the same function as the FieldName attribute of a MERGEFIELD field.BarcodeValue = "MyQRCode"; field.BackgroundColor = "0xF8BD69"; field.ForegroundColor = "0xB5413B"; field.ErrorCorrectionLevel = "3"; field.ScalingFactor = "250"; field.SymbolHeight = "1000"; field.SymbolRotation = "0"; Assert.AreEqual(" MERGEBARCODE MyQRCode QR \\b 0xF8BD69 \\f 0xB5413B \\q 3 \\s 250 \\h 1000 \\r 0", field.GetFieldCode()); builder.Writeln(); // Create a data source for our mail merge // This source is a data table, whose column names correspond to the FieldName attributes of MERGEFIELD fields // as well as BarcodeValue attributes of DISPLAYBARCODE fields DataTable table = CreateTable("Barcodes", new[] { "MyQRCode" }, new[,] { { "ABC123" }, { "DEF456" } }); // During the mail merge, all our MERGEBARCODE fields will be converted into DISPLAYBARCODE fields, // with values from the data table rows deposited into corresponding BarcodeValue attributes doc.MailMerge.Execute(table); Assert.AreEqual(FieldType.FieldDisplayBarcode, doc.Range.Fields[0].Type); Assert.AreEqual(FieldType.FieldDisplayBarcode, doc.Range.Fields[1].Type); Assert.AreEqual("DISPLAYBARCODE \"ABC123\" QR \\q 3 \\s 250 \\h 1000 \\r 0 \\b 0xF8BD69 \\f 0xB5413B", doc.Range.Fields[0].GetFieldCode()); Assert.AreEqual("DISPLAYBARCODE \"DEF456\" QR \\q 3 \\s 250 \\h 1000 \\r 0 \\b 0xF8BD69 \\f 0xB5413B", doc.Range.Fields[1].GetFieldCode()); doc.Save(ArtifactsDir + "Field.MERGEBARCODE.docx"); } public void FieldMergeBarcode_EAN13() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a EAN13 barcode FieldMergeBarcode field = (FieldMergeBarcode) builder.InsertField(FieldType.FieldMergeBarcode, true); field.BarcodeType = "EAN13"; field.BarcodeValue = "MyEAN13Barcode"; field.DisplayText = true; field.PosCodeStyle = "CASE"; field.FixCheckDigit = true; Assert.AreEqual(" MERGEBARCODE MyEAN13Barcode EAN13 \\t \\p CASE \\x", field.GetFieldCode()); builder.Writeln(); DataTable table = CreateTable("Barcodes", new[] { "MyEAN13Barcode" }, new[,] { { "501234567890" }, { "123456789012" } }); doc.MailMerge.Execute(table); Assert.AreEqual(FieldType.FieldDisplayBarcode, doc.Range.Fields[0].Type); Assert.AreEqual(FieldType.FieldDisplayBarcode, doc.Range.Fields[1].Type); Assert.AreEqual("DISPLAYBARCODE \"501234567890\" EAN13 \\t \\p CASE \\x", doc.Range.Fields[0].GetFieldCode()); Assert.AreEqual("DISPLAYBARCODE \"123456789012\" EAN13 \\t \\p CASE \\x", doc.Range.Fields[1].GetFieldCode()); doc.Save(ArtifactsDir + "Field.MERGEBARCODE.EAN13.docx"); } public void FieldMergeBarcode_CODE39() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a CODE39 barcode FieldMergeBarcode field = (FieldMergeBarcode) builder.InsertField(FieldType.FieldMergeBarcode, true); field.BarcodeType = "CODE39"; field.BarcodeValue = "MyCODE39Barcode"; field.AddStartStopChar = true; Assert.AreEqual(" MERGEBARCODE MyCODE39Barcode CODE39 \\d", field.GetFieldCode()); builder.Writeln(); DataTable table = CreateTable("Barcodes", new[] { "MyCODE39Barcode" }, new[,] { { "12345ABCDE" }, { "67890FGHIJ" } }); doc.MailMerge.Execute(table); Assert.AreEqual(FieldType.FieldDisplayBarcode, doc.Range.Fields[0].Type); Assert.AreEqual(FieldType.FieldDisplayBarcode, doc.Range.Fields[1].Type); Assert.AreEqual("DISPLAYBARCODE \"12345ABCDE\" CODE39 \\d", doc.Range.Fields[0].GetFieldCode()); Assert.AreEqual("DISPLAYBARCODE \"67890FGHIJ\" CODE39 \\d", doc.Range.Fields[1].GetFieldCode()); doc.Save(ArtifactsDir + "Field.MERGEBARCODE.CODE39.docx"); } public void FieldMergeBarcode_ITF14() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a ITF14 barcode FieldMergeBarcode field = (FieldMergeBarcode) builder.InsertField(FieldType.FieldMergeBarcode, true); field.BarcodeType = "ITF14"; field.BarcodeValue = "MyITF14Barcode"; field.CaseCodeStyle = "STD"; Assert.AreEqual(" MERGEBARCODE MyITF14Barcode ITF14 \\c STD", field.GetFieldCode()); DataTable table = CreateTable("Barcodes", new[] { "MyITF14Barcode" }, new[,] { { "09312345678907" }, { "1234567891234" } }); doc.MailMerge.Execute(table); Assert.AreEqual(FieldType.FieldDisplayBarcode, doc.Range.Fields[0].Type); Assert.AreEqual(FieldType.FieldDisplayBarcode, doc.Range.Fields[1].Type); Assert.AreEqual("DISPLAYBARCODE \"09312345678907\" ITF14 \\c STD", doc.Range.Fields[0].GetFieldCode()); Assert.AreEqual("DISPLAYBARCODE \"1234567891234\" ITF14 \\c STD", doc.Range.Fields[1].GetFieldCode()); doc.Save(ArtifactsDir + "Field.MERGEBARCODE.ITF14.docx"); } /// <summary> /// Creates a DataTable named by dataTableName, adds a column for every element in columnNames /// and fills rows with data from dataSet. /// </summary> public DataTable CreateTable(string dataTableName, string[] columnNames, object[,] dataSet) { if (dataTableName != string.Empty || columnNames.Length != 0) { DataTable table = new DataTable(dataTableName); foreach (string columnName in columnNames) table.Columns.Add(columnName); foreach (object data in dataSet) table.Rows.Add(data); return table; } throw new ArgumentException("DataTable name and Column name must be declared."); }