public Dictionary <int, string> FindMany(OpenXmlElementList source, string id, int dashIndex = -1) { if (dashIndex == -1) { dashIndex = source.Count; } var result = source .Select((x, i) => new { Value = x, index = i }) .Where(x => x.index < dashIndex) .Where(x => (x.Value is Paragraph)) .Where(x => (x.Value as Paragraph).ParagraphProperties != null) .Where(x => (x.Value as Paragraph).ParagraphProperties.ParagraphStyleId != null) .Where(x => (x.Value as Paragraph).ParagraphProperties?.ParagraphStyleId?.Val?.Value?.ToLower() == id.ToLower()) .ToList(); Dictionary <int, string> returnDictionary = new Dictionary <int, string>(); foreach (var item in result) { returnDictionary.Add(item.index, item.Value.InnerText); } return(returnDictionary); }
public Dictionary <int, string> FindManyBetween(OpenXmlElementList source, List <string> idList, int lowerLimit, int upperLimit, int dashIndex = -1) { if (dashIndex == -1) { dashIndex = source.Count; } idList = idList.ConvertAll(d => d.ToLower()); var result = source .Select((x, i) => new { Value = x, index = i }) .Where(x => x.index < dashIndex) .Where(x => (x.Value is Paragraph)) .Where(x => (x.Value as Paragraph).ParagraphProperties != null) .Where(x => (x.Value as Paragraph).ParagraphProperties.ParagraphStyleId != null) .Where(x => idList.Contains((x.Value as Paragraph).ParagraphProperties.ParagraphStyleId.Val.Value.ToLower())) .Where(x => x.index >= lowerLimit) .Where(x => x.index <= upperLimit) .ToList(); Dictionary <int, string> returnDictionary = new Dictionary <int, string>(); foreach (var item in result) { returnDictionary.Add(item.index, item.Value.InnerText); } return(returnDictionary); }
public KeyValuePair <int, string> FindFirst(OpenXmlElementList source, string id) { var result = source .Select((x, i) => new { Value = x, Index = i }) .Where(x => (x.Value is Paragraph)) .Where(x => (x.Value as Paragraph).ParagraphProperties != null) .Where(x => (x.Value as Paragraph).ParagraphProperties.ParagraphStyleId != null) .Where(x => (x.Value as Paragraph).ParagraphProperties?.ParagraphStyleId?.Val?.Value?.ToLower() == id.ToLower()) .ToList(); if (result.Count == 0) { return(new KeyValuePair <int, string>(-1, "")); } KeyValuePair <int, string> returnValue = new KeyValuePair <int, string>(result.First().Index, result.First().Value.InnerText); return(returnValue); }
public KeyValuePair <int, string> FindFirstOfBetween(OpenXmlElementList source, List <string> idList, int lowerLimit, int upperLimit) { idList = idList.ConvertAll(x => x.ToLower()).ToList(); var result = source .Select((x, i) => new { Value = x, Index = i }) .Where(x => (x.Value is Paragraph)) .Where(x => (x.Value as Paragraph).ParagraphProperties != null) .Where(x => (x.Value as Paragraph).ParagraphProperties.ParagraphStyleId != null) .Where(x => idList.Contains((x.Value as Paragraph).ParagraphProperties?.ParagraphStyleId?.Val?.Value?.ToLower())) .Where(x => x.Index >= lowerLimit) .Where(x => x.Index <= upperLimit) .ToList(); if (result.Count == 0) { return(new KeyValuePair <int, string>(-1, "")); } KeyValuePair <int, string> returnValue = new KeyValuePair <int, string>(result.First().Index, result.First().Value.InnerText); return(returnValue); }