Ejemplo n.º 1
0
        internal static void CreateRelsPackagePart(DocX Document, Uri uri)
        {
            PackagePart pp = Document._package.CreatePart(uri, DocX.ContentTypeApplicationRelationShipXml, CompressionOption.Maximum);

            using (Stream s = pp.GetStream())
                using (PackagePartStream pps = new PackagePartStream(s))
                    using (TextWriter tw = new StreamWriter(pps))
                    {
                        XDocument d = new XDocument
                                      (
                            new XDeclaration("1.0", "UTF-8", "yes"),
                            new XElement(XName.Get("Relationships", DocX.rel.NamespaceName))
                                      );
                        var root = d.Root;
                        d.Save(tw);
                    }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add the default numbering.xml if it is missing from this document
        /// </summary>
        internal static XDocument AddDefaultNumberingXml(Package package)
        {
            XDocument numberingDoc;

            var numberingPart = package.CreatePart(new Uri("/word/numbering.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", CompressionOption.Maximum);

            numberingDoc = DecompressXMLResource("DocXStandard.Resources.numbering.xml.gz");

            using (Stream s = numberingPart.GetStream(FileMode.Create, FileAccess.Write))
                using (PackagePartStream pps = new PackagePartStream(s))
                    using (TextWriter tw = new StreamWriter(pps))
                    {
                        numberingDoc.Save(tw, SaveOptions.None);
                    }

            var mainDocPart = GetMainDocumentPart(package);

            mainDocPart.CreateRelationship(numberingPart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering");
            return(numberingDoc);
        }
Ejemplo n.º 3
0
        internal static void CreateCustomPropertiesPart(DocX document)
        {
            var customPropertiesPart = document._package.CreatePart(new Uri("/docProps/custom.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.custom-properties+xml", CompressionOption.Maximum);

            var customPropDoc = new XDocument
                                (
                new XDeclaration("1.0", "UTF-8", "yes"),
                new XElement
                (
                    XName.Get("Properties", DocX.customPropertiesSchema.NamespaceName),
                    new XAttribute(XNamespace.Xmlns + "vt", DocX.customVTypesSchema)
                )
                                );

            using (Stream s = customPropertiesPart.GetStream(FileMode.Create, FileAccess.Write))
                using (PackagePartStream pps = new PackagePartStream(s))
                    using (TextWriter tw = new StreamWriter(pps))
                    {
                        customPropDoc.Save(tw, SaveOptions.None);
                    }

            document._package.CreateRelationship(customPropertiesPart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// If this document does not contain a /word/styles.xml add the default one generated by Microsoft Word.
        /// </summary>
        /// <param name="package"></param>
        /// <returns></returns>
        internal static XDocument AddDefaultStylesXml(Package package)
        {
            XDocument stylesDoc;
            // Create the main document part for this package
            var word_styles = package.CreatePart(new Uri("/word/styles.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", CompressionOption.Maximum);

            stylesDoc = HelperFunctions.DecompressXMLResource("DocXStandard.Resources.default_styles.xml.gz");
            var lang = stylesDoc.Root.Element(XName.Get("docDefaults", DocX.w.NamespaceName)).Element(XName.Get("rPrDefault", DocX.w.NamespaceName)).Element(XName.Get("rPr", DocX.w.NamespaceName)).Element(XName.Get("lang", DocX.w.NamespaceName));

            lang.SetAttributeValue(XName.Get("val", DocX.w.NamespaceName), CultureInfo.CurrentCulture);

            // Save /word/styles.xml
            using (Stream s = word_styles.GetStream(FileMode.Create, FileAccess.Write))
                using (PackagePartStream pps = new PackagePartStream(s))
                    using (TextWriter tw = new StreamWriter(pps))
                    {
                        stylesDoc.Save(tw, SaveOptions.None);
                    }

            var mainDocumentPart = GetMainDocumentPart(package);

            mainDocumentPart.CreateRelationship(word_styles.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles");
            return(stylesDoc);
        }
Ejemplo n.º 5
0
        internal static PackagePart CreateOrGetSettingsPart(Package package)
        {
            PackagePart settingsPart;

            var settingsUri = new Uri("/word/settings.xml", UriKind.Relative);

            if (!package.PartExists(settingsUri))
            {
                settingsPart = package.CreatePart(settingsUri, HelperFunctions.SETTING_DOCUMENTTYPE, CompressionOption.Maximum);

                var mainDocPart = GetMainDocumentPart(package);

                mainDocPart.CreateRelationship(settingsUri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings");

                var settings = XDocument.Parse
                                   (@"<?xml version='1.0' encoding='utf-8' standalone='yes'?>
                <w:settings xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' xmlns:m='http://schemas.openxmlformats.org/officeDocument/2006/math' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:w10='urn:schemas-microsoft-com:office:word' xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' xmlns:sl='http://schemas.openxmlformats.org/schemaLibrary/2006/main'>
                  <w:zoom w:percent='100' />
                  <w:defaultTabStop w:val='720' />
                  <w:characterSpacingControl w:val='doNotCompress' />
                  <w:compat />
                  <w:rsids>
                    <w:rsidRoot w:val='00217F62' />
                    <w:rsid w:val='001915A3' />
                    <w:rsid w:val='00217F62' />
                    <w:rsid w:val='00A906D8' />
                    <w:rsid w:val='00AB5A74' />
                    <w:rsid w:val='00F071AE' />
                  </w:rsids>
                  <m:mathPr>
                    <m:mathFont m:val='Cambria Math' />
                    <m:brkBin m:val='before' />
                    <m:brkBinSub m:val='--' />
                    <m:smallFrac m:val='off' />
                    <m:dispDef />
                    <m:lMargin m:val='0' />
                    <m:rMargin m:val='0' />
                    <m:defJc m:val='centerGroup' />
                    <m:wrapIndent m:val='1440' />
                    <m:intLim m:val='subSup' />
                    <m:naryLim m:val='undOvr' />
                  </m:mathPr>
                  <w:themeFontLang w:val='en-IE' w:bidi='ar-SA' />
                  <w:clrSchemeMapping w:bg1='light1' w:t1='dark1' w:bg2='light2' w:t2='dark2' w:accent1='accent1' w:accent2='accent2' w:accent3='accent3' w:accent4='accent4' w:accent5='accent5' w:accent6='accent6' w:hyperlink='hyperlink' w:followedHyperlink='followedHyperlink' />
                  <w:shapeDefaults>
                    <o:shapedefaults v:ext='edit' spidmax='2050' />
                    <o:shapelayout v:ext='edit'>
                      <o:idmap v:ext='edit' data='1' />
                    </o:shapelayout>
                  </w:shapeDefaults>
                  <w:decimalSymbol w:val='.' />
                  <w:listSeparator w:val=',' />
                </w:settings>"
                                   );

                var themeFontLang = settings.Root.Element(XName.Get("themeFontLang", DocX.w.NamespaceName));
                themeFontLang.SetAttributeValue(XName.Get("val", DocX.w.NamespaceName), CultureInfo.CurrentCulture);

                // Save the settings document.
                using (Stream s = settingsPart.GetStream())
                    using (PackagePartStream pps = new PackagePartStream(s))
                        using (TextWriter tw = new StreamWriter(pps))
                        {
                            settings.Save(tw);
                        }
            }
            else
            {
                settingsPart = package.GetPart(settingsUri);
            }
            return(settingsPart);
        }