Example #1
0
 public void FieldMerging(Aspose.Words.Reporting.FieldMergingArgs args)
 {
     if (args.FieldValue != null)
     {
         DocumentBuilder builder = new DocumentBuilder(args.Document);
         builder.MoveToMergeField(args.DocumentFieldName, false, false);
         if (args.FieldValue is mailmergeSpecial)
         {
             builder.CellFormat.HorizontalMerge = (args.FieldValue as mailmergeSpecial).cellmerge;
         }
         //builder.CellFormat.FitText = true;
         //builder.CellFormat.WrapText = true;
         if (args.FieldValue is mailmergeSpecial)
         {
             args.Text = (args.FieldValue as mailmergeSpecial).value;
         }
     }
 }
            public void FieldMerging(Aspose.Words.Reporting.FieldMergingArgs e)
            {
                if (e.FieldName == "入學照片1吋" || e.FieldName == "入學照片2吋")
                {
                    int tmp_width;
                    int tmp_height;
                    if (e.FieldName == "入學照片1吋")
                    {
                        tmp_width  = 25;
                        tmp_height = 35;
                    }
                    else
                    {
                        tmp_width  = 35;
                        tmp_height = 45;
                    }
                    #region 入學照片
                    if (e.FieldValue != null && !string.IsNullOrEmpty(e.FieldValue.ToString()))
                    {
                        byte[] photo = Convert.FromBase64String(e.FieldValue.ToString()); //e.FieldValue as byte[];

                        if (photo != null && photo.Length > 0)
                        {
                            DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
                            photoBuilder.MoveToField(e.Field, true);
                            e.Field.Remove();
                            //Paragraph paragraph = photoBuilder.InsertParagraph();// new Paragraph(e.Document);
                            Shape photoShape = new Shape(e.Document, ShapeType.Image);
                            photoShape.ImageData.ImageBytes = photo;
                            photoShape.WrapType             = WrapType.Inline;
                            //Cell cell = photoBuilder.CurrentParagraph.ParentNode as Cell;
                            //cell.CellFormat.LeftPadding = 0;
                            //cell.CellFormat.RightPadding = 0;

                            photoShape.Width  = ConvertUtil.MillimeterToPoint(tmp_width);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(tmp_height);
                            //paragraph.AppendChild(photoShape);
                            photoBuilder.InsertNode(photoShape);
                        }
                    }
                    #endregion
                }
                else if (e.FieldName == "畢業照片1吋" || e.FieldName == "畢業照片2吋")
                {
                    int tmp_width;
                    int tmp_height;
                    if (e.FieldName == "畢業照片1吋")
                    {
                        tmp_width  = 25;
                        tmp_height = 35;
                    }
                    else
                    {
                        tmp_width  = 35;
                        tmp_height = 45;
                    }
                    #region 畢業照片
                    if (e.FieldValue != null && !string.IsNullOrEmpty(e.FieldValue.ToString()))
                    {
                        byte[] photo = Convert.FromBase64String(e.FieldValue.ToString()); //e.FieldValue as byte[];

                        if (photo != null && photo.Length > 0)
                        {
                            DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
                            photoBuilder.MoveToField(e.Field, true);
                            e.Field.Remove();
                            //Paragraph paragraph = photoBuilder.InsertParagraph();// new Paragraph(e.Document);
                            Shape photoShape = new Shape(e.Document, ShapeType.Image);
                            photoShape.ImageData.ImageBytes = photo;
                            photoShape.WrapType             = WrapType.Inline;
                            //Cell cell = photoBuilder.CurrentParagraph.ParentNode as Cell;
                            //cell.CellFormat.LeftPadding = 0;
                            //cell.CellFormat.RightPadding = 0;
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(tmp_width);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(tmp_height);
                            //paragraph.AppendChild(photoShape);
                            photoBuilder.InsertNode(photoShape);
                        }
                    }
                    #endregion
                }
            }
        public void FieldMerging(Aspose.Words.Reporting.FieldMergingArgs args)
        {
            Node deleteNode = null;

            if (args.FieldName.StartsWith("DynamicField/"))
            {
                if (("" + args.FieldValue) == "")
                {
                    Node node = args.Field.Start;
                    while (node.ParentNode != null)
                    {
                        if (node is Aspose.Words.Tables.Row)
                        {
                            deleteNode = node;
                            break;
                        }
                        node = node.ParentNode;
                    }
                }
            }
            else if (args.FieldName.StartsWith("DynamicCheck/"))
            {
                //DocumentBuilder builder = new DocumentBuilder(args.Document);
                //builder.MoveToMergeField(args.DocumentFieldName, false, false);
                Node node = args.Field.Start;
                if (("" + args.FieldValue) == "")
                {
                    while (node.ParentNode != null)
                    {
                        if (node is Aspose.Words.Tables.Row)
                        {
                            deleteNode = node;
                            break;
                        }
                        node = node.ParentNode;
                    }
                }
                else
                {
                    args.Text = "";
                }
            }
            if (deleteNode != null)
            {
                deleteNode.Remove();
            }

            //if (args.FieldValue != null)
            //{
            //    DocumentBuilder builder = new DocumentBuilder(args.Document);
            //    builder.MoveToMergeField(args.DocumentFieldName, false, false);
            //    if (args.FieldValue is mailmergeSpecial)
            //    {
            //        builder.CellFormat.HorizontalMerge = (args.FieldValue as mailmergeSpecial).cellmerge;
            //    }
            //    builder.CellFormat.FitText = true;
            //    builder.CellFormat.WrapText = true;
            //    if (args.FieldValue is mailmergeSpecial)
            //    {
            //        args.Text = (args.FieldValue as mailmergeSpecial).value;
            //    }
            //}
        }