Ejemplo n.º 1
0
        private static List <object> GetDefaultType()
        {
            List <object> list     = new List <object>();
            CT_Default    default2 = new CT_Default {
                Extension   = "bin",
                ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings"
            };

            list.Add(default2);
            default2 = new CT_Default {
                Extension   = "rels",
                ContentType = "application/vnd.openxmlformats-package.relationships+xml"
            };
            list.Add(default2);
            default2 = new CT_Default {
                Extension   = "xml",
                ContentType = "application/xml"
            };
            list.Add(default2);
            default2 = new CT_Default {
                Extension   = "jpg",
                ContentType = "image/jpg"
            };
            list.Add(default2);
            default2 = new CT_Default {
                Extension   = "png",
                ContentType = "image/png"
            };
            list.Add(default2);
            default2 = new CT_Default {
                Extension   = "bmp",
                ContentType = "image/bmp"
            };
            list.Add(default2);
            default2 = new CT_Default {
                Extension   = "gif",
                ContentType = "image/gif"
            };
            list.Add(default2);
            default2 = new CT_Default {
                Extension   = "emf",
                ContentType = "image/x-emf"
            };
            list.Add(default2);
            return(list);
        }
Ejemplo n.º 2
0
        public static Stream CreateStreamFromObject(object obj, Type type)
        {
            if (obj == null)
            {
                return(null);
            }
            Stream stream = null;

            if (obj is CT_Relationships)
            {
                CT_Relationships relationships = obj as CT_Relationships;
                stream = (Stream) new MemoryStream();
                new XmlWriterSettings().Encoding = Encoding.UTF8;
                XmlWriter @this = XmlWriter.Create(stream, new XmlWriterSettings());
                using (@this.WriteDocument(true))
                {
                    using (@this.WriteElement("Relationships", "http://schemas.openxmlformats.org/package/2006/relationships"))
                    {
                        foreach (Relationship relationship in relationships.Relationship)
                        {
                            using (@this.WriteElement("Relationship"))
                            {
                                @this.WriteAttributeString("Id", relationship.Id);
                                @this.WriteAttributeString("Type", relationship.Type);
                                @this.WriteAttributeString("Target", relationship.Target.Trim(new char[] { '\n', '\b', ' ' }));
                                if (!string.IsNullOrWhiteSpace(relationship.TargetMode))
                                {
                                    @this.WriteAttributeString("TargetMode", relationship.TargetMode);
                                }
                            }
                        }
                    }
                }
                @this.Flush();
                stream.Seek(0L, (SeekOrigin)SeekOrigin.Begin);
                return(stream);
            }
            if (obj is CT_Types)
            {
                CT_Types types = obj as CT_Types;
                stream = (Stream) new MemoryStream();
                new XmlWriterSettings().Encoding = Encoding.UTF8;
                XmlWriter writer2 = XmlWriter.Create(stream, new XmlWriterSettings());
                using (writer2.WriteDocument(true))
                {
                    using (writer2.WriteElement("Types", "http://schemas.openxmlformats.org/package/2006/content-types"))
                    {
                        foreach (object obj2 in types.Items)
                        {
                            if (obj2 is CT_Default)
                            {
                                CT_Default default2 = obj2 as CT_Default;
                                using (writer2.WriteElement("Default"))
                                {
                                    writer2.WriteAttributeString("ContentType", default2.ContentType);
                                    writer2.WriteAttributeString("Extension", default2.Extension);
                                    continue;
                                }
                            }
                            if (obj2 is CT_Override)
                            {
                                CT_Override @override = obj2 as CT_Override;
                                using (writer2.WriteElement("Override"))
                                {
                                    writer2.WriteAttributeString("ContentType", @override.ContentType);
                                    writer2.WriteAttributeString("PartName", @override.PartName);
                                }
                            }
                        }
                    }
                }
                writer2.Flush();
                stream.Seek(0L, (SeekOrigin)SeekOrigin.Begin);
            }
            return(stream);
        }