/// <summary> /// 从Excel文件中读取树节点的父子级关系。 /// </summary> /// <returns></returns> private TreeValue InitTreeNode() { TreeValue value = null, parent = null, root = null; Hashtable table = new Hashtable(); using (Office.Excel.ForwardExcelReader reader = new Office.Excel.ForwardExcelReader(@"..\..\..\演示数据\CCC\目录字典.xlsx")) { reader.Open(); Office.Excel.ForwardReadWorksheet sheet = reader.Activate(1) as Office.Excel.ForwardReadWorksheet; sheet.ReadFollowingRow(2); string id = null, name = null, parentId = null; object content = null; do { while (sheet.ReadNextCell(false)) { content = sheet.GetContent(); switch (sheet.CurrentCell.ColumnIndex) { case 1: id = content == null ? null : content.ToString(); break; case 2: name = content == null ? null : content.ToString(); break; case 3: parentId = content == null ? null : content.ToString(); break; } } if (id == null || name == null) { continue; } value = new TreeValue(name, parentId, null); table.Add(id, value); } while (sheet.ReadNextRow()); } foreach (DictionaryEntry entry in table) { value = entry.Value as TreeValue; if (value != null) { if (value.Parent == null) { root = value; } else { parent = table[value.Parent.Name] as TreeValue; parent.AddChild(value); } } } return(root); }
/// <summary> /// 从Excel文件中读取树节点的父子级关系。 /// </summary> /// <returns></returns> private TreeValue InitTreeNode() { TreeValue value = null, parent = null, root = null; string fileName = FileHelper.GetPublicPage(FillRuleVerson, FillType); string ruleFilePath = FileHelper.GetFillVersionByName(FillRuleVerson); Hashtable table = new Hashtable(); using (Office.Excel.ForwardExcelReader reader = new Office.Excel.ForwardExcelReader(string.Format(@"{0}\{1}", ruleFilePath, fileName))) { reader.Open(); Office.Excel.ForwardReadWorksheet sheet = reader.Activate(1) as Office.Excel.ForwardReadWorksheet; sheet.ReadFollowingRow(2); string name = null, parentName = null; object content = null; do { while (sheet.ReadNextCell(false)) { content = sheet.GetContent(); switch (sheet.CurrentCell.ColumnIndex) { case 1: name = content == null ? null : content.ToString(); break; case 2: parentName = content == null ? null : content.ToString(); break; } } if (name == null) { continue; } value = new TreeValue(name, parentName, null); table.Add(name, value); } while (sheet.ReadNextRow()); } foreach (DictionaryEntry entry in table) { value = entry.Value as TreeValue; if (value != null) { if (value.Parent == null) { root = value; } else { parent = table[value.Parent.Name] as TreeValue; parent.AddChild(value); } } } return(root); }
public virtual bool FillPage() { if (editRange == IntPtr.Zero) { return(false); } if (sheet.ReadFollowingRow(2)) { bool isEmptyRow; Dictionary <int, string> values = new Dictionary <int, string>(); IntPtr ok; do { values.Clear(); object content; isEmptyRow = true; string str = ""; while (sheet.ReadNextCell(false)) { content = sheet.GetContent(); str = content == null ? "" : content.ToString(); if (string.IsNullOrEmpty(str) == false) { isEmptyRow = false; } values.Add(sheet.CurrentCell.ColumnIndex - 1, content == null ? null : content.ToString()); } if (isEmptyRow) { continue; } ApiSetter.ClickButton(add, hwnd, null, null); ok = IntPtr.Zero; List <IntPtr> list = ControlSorter.SortContainer(editRange); StringBuilder className = new StringBuilder(256); int index = 0; foreach (var handle in list) { className.Clear(); NativeApi.GetClassName(handle, className, 255); string classNameStr = className.ToString(); if (classNameStr.StartsWith(CCCFillManager.ComboBoxClassName)) { if (values.ContainsKey(index) && ApiSetter.IsEditable(handle)) { ApiSetter.SetComboBoxSelected(hwnd, handle, values[index]); index++; } } else if (classNameStr.StartsWith(CCCFillManager.EditClassName)) { if (values.ContainsKey(index) && ApiSetter.IsEditable(handle)) { ApiSetter.SetText(handle, values[index]); index++; } } else if (classNameStr.StartsWith(CCCFillManager.ButtonClassName)) { StringBuilder text = className.Clear(); NativeApi.GetWindowText(handle, text, 255); if (text.ToString() == "确定") { ok = handle; } else if (text.ToString() == "附件" && values.ContainsKey(index) && string.IsNullOrEmpty(values[index]) == false) { ApiSetter.ClickButton(handle, hwnd, ListenAttachWindow, new FillValue3C() { PublicAttachFile = values[index], Separators = FillParameter3C.DefaultSeparators }); } } } if (ok != IntPtr.Zero) { ApiSetter.ClickButton(ok, hwnd, null, null); } } while (sheet.ReadNextRow()); this.Main.ClickSaveButton(this.Save); return(true); } return(false); }