private Dictionary<string, List<TemplateValue>> GetTemplateList(XmlNode root) { Dictionary<string, List<TemplateValue>> dic = new Dictionary<string, List<TemplateValue>>(); foreach (XmlNode node in root.ChildNodes) { foreach (XmlNode item in node.ChildNodes) { if (item.NodeType != XmlNodeType.Element) continue; if (!dic.ContainsKey(item.LocalName)) { dic[item.LocalName] = new List<TemplateValue>(); } TemplateValue tv = new TemplateValue(); dic[item.LocalName].Add(tv); tv.NodeName = item.LocalName; tv.Props = new Dictionary<string, string>(); foreach (XmlAttribute att in item.Attributes) { tv.Props[att.LocalName] = att.Value; } } } return dic; }
private Dictionary<string, List<TemplateValue>> GetExcelList(MSExcel.Workbook wbook, Dictionary<string, TemplateStruct> list) { Dictionary<string, List<TemplateValue>> dic = new Dictionary<string, List<TemplateValue>>(); int count = wbook.Worksheets.Count; for (int i = 0; i < count; i++) { MSExcel.Worksheet sheet = wbook.Worksheets[i + 1]; TemplateStruct ts = list[sheet.Name]; if (!dic.ContainsKey(ts.NodeName)) { dic[ts.NodeName] = new List<TemplateValue>(); } int start = ExcelDataStart; bool endRow = false; for (int j = 0; j < ExcelMaxRow; j++) { TemplateValue tv = new TemplateValue(); tv.NodeName = ts.NodeName; tv.Props = new Dictionary<string, string>(); for (int k = 0; k < ts.Attributes.Count; k++) { string attribute = ts.Attributes[k]; MSExcel.Range r = sheet.get_Range(getCell(start, k + StructCol)); if (k == 0 && string.IsNullOrEmpty(r.FormulaLocal)) { endRow = true; break; } if (r.FormulaLocal.StartsWith("=")) { int temp = Convert.ToInt32(r.Value2); if (r.Value2 > temp) { tv.Props[attribute] = Convert.ToString(r.Value2); } else { tv.Props[attribute] = temp.ToString(); } } else { tv.Props[attribute] = r.FormulaLocal; } } start++; if (endRow) { break; } dic[ts.NodeName].Add(tv); } } return dic; }