コード例 #1
0
        internal string Write()
        {
            XNamespace xn2 = "http://schemas.openxmlformats.org/package/2006/relationships";

            var t = new XElement(xn2 + "Relationships");

            foreach (var z in rels)
            {
                t.Add(new XElement(xn2 + "Relationship", new XAttribute("Type", z.Value.RelationshipType), new XAttribute("Target", z.Value.PackagePath), new XAttribute("Id", z.Key.ToString())));
            }
            XDocument x = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), t);

            return(XlsxPart.Write(x));
        }
コード例 #2
0
ファイル: XlsxParts.cs プロジェクト: derekfrye/tsoyeow
        public XlsxParts(Stream path)
        {
            p = path;
            z = new ZipFile();

            mainRels = new Relationships();
            xlRels   = new Relationships();

            #region workbook.xml_Content_Type

            workbookXml            = new XlsxWorkbookMetadata();
            workbookXmlPackagePart = XlsxPart.LinkToPackage("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "xl/workbook.xml");
            mainRels.Link(workbookXmlPackagePart);

            #endregion

            #region core.xml

            XDocument xdjfkd = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));

            xdjfkd = XDocument.Parse(Settings.Default.CoreXml.OuterXml, LoadOptions.None);
            mainRels.Link(XlsxPart.LinkToPackage("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml"
                                                 ));

            using (StringWriterWithEncoding sb = new StringWriterWithEncoding(Encoding.UTF8))
            {
                var za = new XmlWriterSettings();
                za.Encoding = Encoding.UTF8;
                using (XmlWriter apo = XmlWriter.Create(sb, za))
                {
                    xdjfkd.Save(apo);
                    apo.Close();
                    z.AddEntry("/docProps/core.xml", sb.ToString());
                }
            }

            #endregion

            #region theme

            XDocument xdjfkdd = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));

            xdjfkdd = XDocument.Parse(Settings.Default.ThemeXml.OuterXml, LoadOptions.None);
            xlRels.Link(XlsxPart.LinkToPackage("http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", "theme/theme1.xml"
                                               ));

            using (StringWriterWithEncoding sbs = new StringWriterWithEncoding(Encoding.UTF8))
            {
                var zas = new XmlWriterSettings();
                zas.Encoding = Encoding.UTF8;

                using (XmlWriter apos = XmlWriter.Create(sbs, zas))
                {
                    xdjfkdd.Save(apos);
                    apos.Close();
                    z.AddEntry("/xl/theme/theme1.xml", sbs.ToString());
                }
            }


            #endregion

            #region styles

            XDocument xdjfkdsa = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));

            xdjfkdsa = XDocument.Parse(Settings.Default.StylesXml.OuterXml, LoadOptions.None);
            xlRels.Link(XlsxPart.LinkToPackage("http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml"
                                               ));

            using (StringWriterWithEncoding sasb = new StringWriterWithEncoding(Encoding.UTF8))
            {
                var zaaa = new XmlWriterSettings();
                zaaa.Encoding = Encoding.UTF8;

                using (XmlWriter apso = XmlWriter.Create(sasb, zaaa))
                {
                    xdjfkdsa.Save(apso);
                    apso.Close();
                    z.AddEntry("/xl/styles.xml", sasb.ToString());
                }
            }

            #endregion

            #region sharedstrings

            string jf    = Path.GetTempFileName();
            var    strm1 = new FileStream(jf, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
            z.AddEntry("/xl/sharedStrings.xml", strm1);
            sharedStrings = new XlsxSharedStringsXml(strm1, jf);

            xlRels.Link(XlsxPart.LinkToPackage("http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings", "sharedStrings.xml"));

            #endregion
        }