コード例 #1
0
        void SetMailMergeSetting(WordprocessingDocument doc, DocumentSettingsPart settingPart, string udlPath, string query, string connectionString)
        {
            int mailmergecount = doc.MainDocumentPart.DocumentSettingsPart.Settings.Elements <XOPEN.Wordprocessing.MailMerge>().Count();

            if (mailmergecount != 1)
            {
                throw new ArgumentException("mailmergecount is not 1");
            }
            // Get the Document Settings Part

            var newUri = new Uri(udlPath);


            var mymerge = settingPart.Settings.Elements <XOPEN.Wordprocessing.MailMerge>().First();
            var myDataSourceReference = mymerge.DataSourceReference;

            if (myDataSourceReference != null)
            {
                var myOldRelationship = settingPart.GetExternalRelationship(myDataSourceReference.Id);
                if (myOldRelationship != null)
                {
                    settingPart.DeleteExternalRelationship(myOldRelationship);
                    settingPart.AddExternalRelationship(myOldRelationship.RelationshipType, newUri, myDataSourceReference.Id);
                }
            }
            if (mymerge.DataSourceObject != null && mymerge.DataSourceObject.SourceReference != null)
            {
                var myOldRelationship2 = settingPart.GetExternalRelationship(mymerge.DataSourceObject.SourceReference.Id);
                if (myOldRelationship2 != null)
                {
                    settingPart.DeleteExternalRelationship(myOldRelationship2);
                    settingPart.AddExternalRelationship(myOldRelationship2.RelationshipType, newUri, mymerge.DataSourceObject.SourceReference.Id);
                }
                if (mymerge.DataSourceObject.UdlConnectionString != null)
                {
                    mymerge.DataSourceObject.UdlConnectionString.Val = connectionString;
                }
            }
            mymerge.ConnectString.Val = connectionString;
            mymerge.Query.Val         = query;
        }
コード例 #2
0
        void SetMacroPath(WordprocessingDocument doc, DocumentSettingsPart settingPart, string macroTemplatePath)
        {
            if (!String.IsNullOrEmpty(macroTemplatePath))
            {
                var hasMacros = doc.MainDocumentPart.DocumentSettingsPart.Settings.Elements <XOPEN.Wordprocessing.AttachedTemplate>().Count();

                var newUriMacr = new Uri(macroTemplatePath);
                if (hasMacros > 0)
                {
                    AttachedTemplate attachTemplate = doc.MainDocumentPart.DocumentSettingsPart.Settings.Elements <XOPEN.Wordprocessing.AttachedTemplate>().First();

                    var attachTemplateRelationship = settingPart.GetExternalRelationship(attachTemplate.Id);

                    // attachTemplateRelationship.Uri=  new Uri(macroTemplatePath, UriKind.Absolute);

                    if (attachTemplateRelationship != null)
                    {
                        settingPart.DeleteExternalRelationship(attachTemplateRelationship);
                        settingPart.AddExternalRelationship(attachTemplateRelationship.RelationshipType, newUriMacr, attachTemplate.Id);
                    }
                }
            }
        }