/// <summary> /// Read shared strings to list /// </summary> private void GetSharedStrings() { if (_package.Package.PartExists(SharedStringsUri)) { var xml = _package.GetXmlFromUri(SharedStringsUri); XmlNodeList nl = xml.SelectNodes("//d:sst/d:si", NameSpaceManager); _sharedStringsList = new List <SharedStringItem>(); if (nl != null) { foreach (XmlNode node in nl) { XmlNode n = node.SelectSingleNode("d:t", NameSpaceManager); if (n != null) { _sharedStringsList.Add(new SharedStringItem() { Text = ExcelDecodeString(n.InnerText) }); } else { _sharedStringsList.Add(new SharedStringItem() { Text = node.InnerXml, isRichText = true }); } } } } }
private XmlDocument GetXmlDocument(string startXml, Uri uri, string contentType, string relationship) { XmlDocument xmlDoc; if (_package.Package.PartExists(uri)) { xmlDoc = _package.GetXmlFromUri(uri); } else { xmlDoc = new XmlDocument(); xmlDoc.LoadXml(startXml); // Create a the part and add to the package PackagePart part = _package.Package.CreatePart(uri, contentType); // Save it to the package StreamWriter stream = new StreamWriter(part.GetStream(FileMode.Create, FileAccess.Write)); xmlDoc.Save(stream); stream.Close(); _package.Package.Flush(); // create the relationship between the workbook and the new shared strings part _package.Package.CreateRelationship(PackUriHelper.GetRelativeUri(new Uri("/xl", UriKind.Relative), uri), TargetMode.Internal, relationship); _package.Package.Flush(); } return(xmlDoc); }