Beispiel #1
0
        private static CT_Relationships ToRelationships(Dictionary <string, string[]> htRelationShip)
        {
            if (htRelationShip == null)
            {
                return(null);
            }
            CT_Relationships relationships = new CT_Relationships {
                Relationship = new Dt.Xls.OOXml.Relationship[htRelationShip.Count]
            };
            int index = 0;

            foreach (string str in htRelationShip.Keys)
            {
                string[] strArray = htRelationShip[str];
                if ((strArray != null) && (strArray.Length >= 2))
                {
                    Dt.Xls.OOXml.Relationship relationship = new Dt.Xls.OOXml.Relationship {
                        Id     = str,
                        Target = strArray[0],
                        Type   = strArray[1]
                    };
                    if (((!relationship.Target.EndsWith(".xml") && !relationship.Target.EndsWith("png")) && (!relationship.Target.EndsWith("jpg") && !relationship.Target.EndsWith("bmp"))) && ((!relationship.Target.EndsWith("gif") && !relationship.Target.EndsWith("vml")) && (!relationship.Target.EndsWith("emf") && (relationship.Type != "http://schemas.microsoft.com/office/2006/relationships/vbaProject"))))
                    {
                        relationship.TargetMode = "External";
                    }
                    relationships.Relationship[index] = relationship;
                }
                index++;
            }
            return(relationships);
        }
Beispiel #2
0
        private static List <Dt.Xls.OOXml.Relationship> ReadRelationships(Stream stream)
        {
            List <Dt.Xls.OOXml.Relationship> list = new List <Dt.Xls.OOXml.Relationship>();

            try
            {
                if (stream == null)
                {
                    return(list);
                }
                stream.Seek(0L, (SeekOrigin)SeekOrigin.Begin);
                foreach (XNode node in XElement.Load(stream).Nodes())
                {
                    Dt.Xls.OOXml.Relationship relationship = new Dt.Xls.OOXml.Relationship();
                    XElement element2 = node as XElement;
                    if (element2 != null)
                    {
                        if (element2.Attribute("Id") != null)
                        {
                            relationship.Id = element2.Attribute("Id").Value;
                        }
                        if (element2.Attribute("Target") != null)
                        {
                            relationship.Target = element2.Attribute("Target").Value;
                        }
                        if (element2.Attribute("TargetMode") != null)
                        {
                            relationship.TargetMode = element2.Attribute("TargetMode").Value;
                        }
                        if (element2.Attribute("Type") != null)
                        {
                            relationship.Type = element2.Attribute("Type").Value;
                        }
                        if (element2.Attribute("Value") != null)
                        {
                            relationship.Value = element2.Attribute("Value").Value;
                        }
                        list.Add(relationship);
                    }
                }
            }
            catch
            {
            }
            return(list);
        }