Exemple #1
0
        private void WriteInfoXmlFile(ZipPackage pkg)
        {
            var version = typeof(Workbook).GetTypeInfo().Assembly.GetName().Version;

            var infoXml = new XmlFile();

            infoXml.Path    = "simplexcel.xml";
            infoXml.Content = new XDocument(new XElement(Namespaces.simplexcel + "docInfo", new XAttribute("xmlns", Namespaces.simplexcel)));

            infoXml.Content.Root.Add(new XElement(Namespaces.simplexcel + "version",
                                                  new XAttribute("major", version.Major),
                                                  new XAttribute("minor", version.Minor),
                                                  new XAttribute("build", version.Build),
                                                  new XAttribute("revision", version.Revision)
                                                  ));

            infoXml.Content.Root.Add(new XElement(Namespaces.simplexcel + "created", DateTime.UtcNow));

            pkg.WriteXmlFile(infoXml);
        }
Exemple #2
0
        private void WriteInfoXmlFile(ZipPackage pkg)
        {
            var infoXml = new XmlFile
            {
                Path    = "simplexcel.xml",
                Content = new XDocument(new XElement(Namespaces.simplexcel + "docInfo", new XAttribute("xmlns", Namespaces.simplexcel)))
            };

            infoXml.Content.Root.Add(new XElement(Namespaces.simplexcel + "version",
                                                  new XAttribute("major", SimplexcelVersion.Version.Major),
                                                  new XAttribute("minor", SimplexcelVersion.Version.Minor),
                                                  new XAttribute("build", SimplexcelVersion.Version.Build),
                                                  new XAttribute("revision", SimplexcelVersion.Version.Revision),
                                                  new XText(SimplexcelVersion.VersionString)
                                                  ));

            infoXml.Content.Root.Add(new XElement(Namespaces.simplexcel + "created", DateTime.UtcNow));

            pkg.WriteXmlFile(infoXml);
        }
Exemple #3
0
        /// <summary>
        /// Save the Xlsx Package to a new Stream (that the caller owns and has to dispose)
        /// </summary>
        /// <returns></returns>
        internal void SaveToStream(Stream outputStream, bool compress)
        {
            using (var pkg = new ZipPackage(outputStream, compress))
            {
                WriteInfoXmlFile(pkg);

                foreach (var file in XmlFiles)
                {
                    pkg.WriteXmlFile(file);

                    var relations = Relationships.Where(r => r.Target == file);
                    foreach (var rel in relations)
                    {
                        pkg.AddRelationship(rel);
                    }
                }

                if (WorkbookRelationships.Count > 0)
                {
                    pkg.WriteXmlFile(WorkbookRelsXml());
                }
            }
            outputStream.Seek(0, SeekOrigin.Begin);
        }