Created
January 17, 2018 06:41
-
-
Save weiting-tw/cd142f2766a9ae597c2ff75ac7544136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Stream ExportSheet(DocumentSearchCriteria criteria) | |
{ | |
var sheets = SpreadsheetServiceFactory.CreateInstance(); | |
var sheetList = new Dictionary<string, IList<IDictionary<string, object>>>(); | |
IElapsedTimePagedList<Document> docList = Query(criteria); | |
docList.ToList<Document>().ForEach(x => | |
{ | |
var docAttrs = new ConcurrentDictionary<string, object>(); | |
foreach (DocumentAttribute attr in x.Attributes) | |
{ | |
if (attr.DisplayName != "OwnerSubjectId") | |
{ | |
if (docAttrs.Where(a => a.Key == attr.DisplayName).Count() == 0) | |
{ | |
docAttrs.TryAdd(attr.DisplayName, attr.Value.FirstOrDefault()); | |
} | |
else | |
{ | |
docAttrs[docAttrs.Where(a => a.Key == attr.DisplayName).FirstOrDefault().Key] += "\r\n" + attr.Value.FirstOrDefault(); | |
} | |
} | |
} | |
var selectSheet = sheetList.Where(s => s.Key == x.Form.DisplayName); | |
if (selectSheet.Count() == 0) | |
{ | |
var list = new List<IDictionary<string, object>> | |
{ | |
docAttrs | |
}; | |
sheetList.Add(x.Form.DisplayName, list); | |
} | |
else | |
{ | |
sheetList.Where(s => s.Key == x.Form.DisplayName).FirstOrDefault().Value.Add(docAttrs); | |
} | |
}); | |
var stream = sheets.WriteMutipleSheet(sheetList); | |
return stream; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment