コード例 #1
0
        /// <summary>
        /// Replaces the corresponding fields (values, that start with "F_") with the given values.
        /// </summary>
        /// <param name="values"></param>
        public void MailMergeSimpleFields(Dictionary <string, string> values)
        {
            Console.WriteLine("Merging fields...");
            using (WordprocessingDocument doc = WordprocessingDocument.Open(path, true))
            {
                FieldDatasHolder holder = new FieldDatasHolder(values);
                new WordGeneratorField().MergeData(doc, holder);
            }

            Console.WriteLine("Field merge done!");
        }
コード例 #2
0
        public void MergeData(WordprocessingDocument doc, BaseData baseData)
        {
            List <SimpleField>          simpleFields = GetSimpleFields(doc);
            List <FieldCode>            fieldCodes   = GetFieldCodes(doc);
            FieldDatasHolder            holder       = baseData as FieldDatasHolder;
            Dictionary <string, string> data         = holder.Datas;

            if (simpleFields.Count > 0)
            {
                foreach (var field in simpleFields)
                {
                    dataSwapper.SwapData(field, data);
                }
            }
            else if (fieldCodes.Count > 0)
            {
                foreach (var field in fieldCodes)
                {
                    dataSwapper.SwapData(field, data);
                }
            }
            else
            {
                Console.WriteLine("There was no SimpleField or FieldCode");
            }

            foreach (var para in doc.MainDocumentPart.RootElement.Descendants <Paragraph>().ToList())
            {
                if (para.InnerText.Contains("F_"))
                {
                    para.Remove();
                }

                DeleteFlagTags(para);
            }
        }
コード例 #3
0
 public XmlDataHandler()
 {
     GroupDatas     = new List <GroupData>();
     RecursiveDatas = new List <RecursiveData>();
     FieldDatas     = new FieldDatasHolder();
 }