public void FillMutilRows(ExcelAccess ea, int i, LP_Temple lp, string str, List<int> arrCellCount, string[] arrCellPos) { StringHelper help = new StringHelper(); str = help.GetPlitString(str, arrCellCount[1]); string[] extraWord = lp.ExtraWord.Split(pchar); string[] arrRst = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int j = 0; for (; i < arrCellPos.Length; i++) { if (j >= arrRst.Length) break; ea.SetCellValue(arrRst[j], GetCellPos(arrCellPos[i])[0], GetCellPos(arrCellPos[i])[1]); if (valuehs.ContainsKey(lp.LPID + "$" + arrCellPos[i])) { WF_TableFieldValue tfv = valuehs[lp.LPID + "$" + arrCellPos[i]] as WF_TableFieldValue; tfv.ControlValue = arrRst[j]; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellPos[i])[0]; tfv.YExcelPos = GetCellPos(arrCellPos[i])[1]; tfv.ExcelSheetName = activeSheetName; } else { WF_TableFieldValue tfv = new WF_TableFieldValue(); tfv.ControlValue = arrRst[j]; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellPos[i])[0]; tfv.YExcelPos = GetCellPos(arrCellPos[i])[1]; tfv.ExcelSheetName = activeSheetName; valuehs.Add(lp.LPID + "$" + arrCellPos[i], tfv); } j++; } }
void ContentChanged(Control ctrl) { LP_Temple lp = (LP_Temple)ctrl.Tag; string str = ctrl.Text; if (dsoFramerWordControl1.MyExcel == null) { return; } Excel.Workbook wb = dsoFramerWordControl1.AxFramerControl.ActiveDocument as Excel.Workbook; Excel.Worksheet sheet; ExcelAccess ea = new ExcelAccess(); ea.MyWorkBook = wb; ea.MyExcel = wb.Application; if (lp.KindTable != "") { activeSheetName = lp.KindTable; sheet = wb.Application.Sheets[lp.KindTable] as Excel.Worksheet; activeSheetIndex = sheet.Index; } else { sheet = wb.Application.Sheets[1] as Excel.Worksheet; activeSheetIndex = sheet.Index; activeSheetName = sheet.Name; } ea.ActiveSheet(activeSheetIndex); unLockExcel(wb, sheet); if (lp.CtrlType.Contains("uc_gridcontrol")) { FillTable(ea, lp, (ctrl as uc_gridcontrol).GetContent(String2Int(lp.WordCount.Split(pchar)))); return; } else if (lp.CtrlType.Contains("DevExpress.XtraEditors.DateEdit")) { FillTime(ea, lp, (ctrl as DateEdit).DateTime); return; } string[] arrCellpos = lp.CellPos.Split(pchar); string[] arrtemp = lp.WordCount.Split(pchar); arrCellpos = StringHelper.ReplaceEmpty(arrCellpos).Split(pchar); arrtemp = StringHelper.ReplaceEmpty(arrtemp).Split(pchar); List<int> arrCellCount = String2Int(arrtemp); if (arrCellpos.Length == 1 || string.IsNullOrEmpty(arrCellpos[1])) { ea.SetCellValue(str, GetCellPos(lp.CellPos)[0], GetCellPos(lp.CellPos)[1]); if (valuehs.ContainsKey(lp.LPID +"$" +lp.CellPos)) { WF_TableFieldValue tfv = valuehs[lp.LPID + "$" + lp.CellPos] as WF_TableFieldValue; tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(lp.CellPos)[0]; tfv.YExcelPos = GetCellPos(lp.CellPos)[1]; } else { WF_TableFieldValue tfv = new WF_TableFieldValue (); tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(lp.CellPos)[0]; tfv.YExcelPos = GetCellPos(lp.CellPos)[1]; valuehs.Add(lp.LPID + "$" + lp.CellPos, tfv); } } else if (arrCellpos.Length > 1 && (!string.IsNullOrEmpty(arrCellpos[1]))) { StringHelper help = new StringHelper(); if (lp.CellName == "编号") { for (int j = 0; j < arrCellpos.Length; j++) { if (str.IndexOf("\r\n") == -1 && str.Length <= help.GetFristLen(str, arrCellCount[j])) { string strNew = str.Substring(0, (str.Length > 0 ? str.Length : 1) - 1) + (j + 1).ToString(); ea.SetCellValue(strNew, GetCellPos(arrCellpos[j])[0], GetCellPos(arrCellpos[j])[1]); if (valuehs.ContainsKey(lp.LPID + "$" + arrCellpos[j])) { WF_TableFieldValue tfv = valuehs[lp.LPID + "$" + arrCellpos[j]] as WF_TableFieldValue; tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[j])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[j])[1]; tfv.ExcelSheetName = sheet.Name; } else { WF_TableFieldValue tfv = new WF_TableFieldValue(); tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[j])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[j])[1]; tfv.ExcelSheetName = sheet.Name; valuehs.Add(lp.LPID + "$" + arrCellpos[j], tfv); } } } return; } int i = 0; if (arrCellCount[0] != arrCellCount[1]) { if (str.IndexOf("\r\n") == -1 && str.Length <= help.GetFristLen(str, arrCellCount[0])) { ea.SetCellValue(str, GetCellPos(arrCellpos[0])[0], GetCellPos(arrCellpos[0])[1]); if (valuehs.ContainsKey(lp.LPID + "$" + arrCellpos[0])) { WF_TableFieldValue tfv = valuehs[lp.LPID + "$" + arrCellpos[0]] as WF_TableFieldValue; tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[0])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[0])[1]; tfv.ExcelSheetName = sheet.Name; } else { WF_TableFieldValue tfv = new WF_TableFieldValue(); tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[0])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[0])[1]; tfv.ExcelSheetName = sheet.Name; valuehs.Add(lp.LPID + "$" + arrCellpos[0], tfv); } return; } ea.SetCellValue(str.Substring(0, str.IndexOf("\r\n") != -1 && help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])), GetCellPos(arrCellpos[0])[0], GetCellPos(arrCellpos[0])[1]); if (valuehs.ContainsKey(lp.LPID + "$" + arrCellpos[0])) { WF_TableFieldValue tfv = valuehs[lp.LPID + "$" + arrCellpos[0]] as WF_TableFieldValue; tfv.ControlValue = str.Substring(0, str.IndexOf("\r\n") != -1 && help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])); tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[0])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[0])[1]; tfv.ExcelSheetName = sheet.Name; } else { WF_TableFieldValue tfv = new WF_TableFieldValue(); tfv.ControlValue = str.Substring(0, str.IndexOf("\r\n") != -1 && help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])); tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[0])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[0])[1]; tfv.ExcelSheetName = sheet.Name; valuehs.Add(lp.LPID + "$" + arrCellpos[0], tfv); } str = str.Substring(help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") && str.IndexOf("\r\n") != -1 ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])); i++; } str = help.GetPlitString(str, arrCellCount[1]); FillMutilRows(ea, i, lp, str, arrCellCount, arrCellpos); } LockExcel(wb,sheet); }
void ctrl_Leave(object sender, EventArgs e) { LP_Temple lp = (LP_Temple)(sender as Control).Tag; string str = (sender as Control).Text; if (dsoFramerWordControl1.MyExcel==null) { return; } Excel.Workbook wb = dsoFramerWordControl1.AxFramerControl.ActiveDocument as Excel.Workbook; ExcelAccess ea = new ExcelAccess(); ea.MyWorkBook = wb; ea.MyExcel = wb.Application; Excel.Worksheet xx; if (lp.KindTable != "") { activeSheetName = lp.KindTable; xx = wb.Application.Sheets[lp.KindTable] as Excel.Worksheet; activeSheetIndex = xx.Index; } else { xx = wb.Application.Sheets[1] as Excel.Worksheet; activeSheetIndex = xx.Index; activeSheetName = xx.Name; } if (lp.KindTable != "") { ea.ActiveSheet(lp.KindTable); } else { ea.ActiveSheet(1); } if (lp.CellPos == "") { lp.CellPos = lp.CellPos; if (valuehs.ContainsKey(lp.LPID)) { WF_TableFieldValue tfv = valuehs[lp.LPID] as WF_TableFieldValue; tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = -1; tfv.YExcelPos = -1; } else { WF_TableFieldValue tfv = new WF_TableFieldValue(); tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = -1; tfv.YExcelPos = -1; tfv.ExcelSheetName = xx.Name; valuehs.Add(lp.LPID, tfv); } return; } unLockExcel(wb,xx); if (lp.CtrlType.Contains("uc_gridcontrol")) { FillTable(ea, lp, (sender as uc_gridcontrol).GetContent(String2Int(lp.WordCount.Split(pchar)))); LockExcel(wb, xx); return; } else if (lp.CtrlType.Contains("DevExpress.XtraEditors.DateEdit")) { FillTime(ea, lp, (sender as DateEdit).DateTime); LockExcel(wb, xx); return; } string[] arrCellpos = lp.CellPos.Split(pchar); string[] arrtemp = lp.WordCount.Split(pchar); arrCellpos = StringHelper.ReplaceEmpty(arrCellpos).Split(pchar); string[] extraWord = lp.ExtraWord.Split(pchar); List<int> arrCellCount = String2Int(arrtemp); if (arrCellpos.Length == 1 || string.IsNullOrEmpty(arrCellpos[1])) { ea.SetCellValue(str, GetCellPos(lp.CellPos)[0], GetCellPos(lp.CellPos)[1]); if (valuehs.ContainsKey(lp.LPID + "$" + lp.CellPos)) { WF_TableFieldValue tfv = valuehs[lp.LPID + "$" + lp.CellPos] as WF_TableFieldValue; tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(lp.CellPos)[0]; tfv.YExcelPos = GetCellPos(lp.CellPos)[1]; tfv.ExcelSheetName = xx.Name; } else { WF_TableFieldValue tfv = new WF_TableFieldValue(); tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(lp.CellPos)[0]; tfv.YExcelPos = GetCellPos(lp.CellPos)[1]; tfv.ExcelSheetName = xx.Name; valuehs.Add(lp.LPID + "$" + lp.CellPos, tfv); } } else if (arrCellpos.Length > 1 && (!string.IsNullOrEmpty(arrCellpos[1]))) { StringHelper help = new StringHelper(); if (lp.CellName == "编号") { for (int j = 0; j < arrCellpos.Length; j++) { if (str.IndexOf("\r\n") == -1 && str.Length <= help.GetFristLen(str, arrCellCount[j]) && str != "") { string strNew = str.Substring(0, str.Length - 1) + (j + 1).ToString(); ea.SetCellValue(strNew, GetCellPos(arrCellpos[j])[0], GetCellPos(arrCellpos[j])[1]); if (valuehs.ContainsKey(lp.LPID + "$" + arrCellpos[j])) { WF_TableFieldValue tfv = valuehs[lp.LPID + "$" + arrCellpos[j]] as WF_TableFieldValue; tfv.ControlValue = strNew; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[j])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[j])[1]; tfv.ExcelSheetName = xx.Name; } else { WF_TableFieldValue tfv = new WF_TableFieldValue(); tfv.ControlValue = strNew; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[j])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[j])[1]; tfv.ExcelSheetName = xx.Name; valuehs.Add(lp.LPID + "$" + arrCellpos[j], tfv); } } } LockExcel(wb, xx); return; } int i = 0; if (arrCellCount[0] != arrCellCount[1]) { if (str.IndexOf("\r\n") == -1 && str.Length <= help.GetFristLen(str, arrCellCount[0])) { ea.SetCellValue(str, GetCellPos(arrCellpos[0])[0], GetCellPos(arrCellpos[0])[1]); if (valuehs.ContainsKey(lp.LPID + "$" + arrCellpos[0])) { WF_TableFieldValue tfv = valuehs[lp.LPID + "$" + arrCellpos[0]] as WF_TableFieldValue; tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[0])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[0])[1]; tfv.ExcelSheetName = xx.Name; } else { WF_TableFieldValue tfv = new WF_TableFieldValue(); tfv.ControlValue = str; tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[0])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[0])[1]; tfv.ExcelSheetName = xx.Name; valuehs.Add(lp.LPID + "$" + arrCellpos[0], tfv); } LockExcel(wb, xx); return; } ea.SetCellValue(str.Substring(0, str.IndexOf("\r\n") != -1 && help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])), GetCellPos(arrCellpos[0])[0], GetCellPos(arrCellpos[0])[1]); if (valuehs.ContainsKey(lp.LPID + "$" + arrCellpos[0])) { WF_TableFieldValue tfv = valuehs[lp.LPID + "$" + arrCellpos[0]] as WF_TableFieldValue; tfv.ControlValue = (str.Substring(0, str.IndexOf("\r\n") != -1 && help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0]))); tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[0])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[0])[1]; tfv.ExcelSheetName = xx.Name; } else { WF_TableFieldValue tfv = new WF_TableFieldValue(); tfv.ControlValue = (str.Substring(0, str.IndexOf("\r\n") != -1 && help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0]))); tfv.FieldId = lp.LPID; tfv.FieldName = lp.CellName; tfv.XExcelPos = GetCellPos(arrCellpos[0])[0]; tfv.YExcelPos = GetCellPos(arrCellpos[0])[1]; tfv.ExcelSheetName = xx.Name; valuehs.Add(lp.LPID + "$" + arrCellpos[0], tfv); } str = str.Substring(help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") && str.IndexOf("\r\n") != -1 ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])); i++; } str = help.GetPlitString(str, arrCellCount[1]); FillMutilRows(ea, i, lp, str, arrCellCount, arrCellpos); } if (lp.CellName == "单位") { IList list = Client.ClientHelper.PlatformSqlMap.GetList("SelectOneStr", "select OrgCode from mOrg where OrgName='" + str + "'"); if (list.Count > 0) { switch (kind) { case "电力线路第一种工作票": case "yzgzp": strNumber = "07" + System.DateTime.Now.Year.ToString() + list[0].ToString().Substring(list[0].ToString().Length - 2, 2); break; case "电力线路第二种工作票": case "ezgzp": strNumber = "08" + System.DateTime.Now.Year.ToString() + list[0].ToString().Substring(list[0].ToString().Length - 2, 2); break; case "电力线路倒闸操作票": case "dzczp": strNumber = "BJ" + System.DateTime.Now.Year.ToString(); break; case "电力线路事故应急抢修单": case "xlqxp": strNumber = list[0].ToString().Substring(list[0].ToString().Length - 2, 2) + System.DateTime.Now.Year.ToString(); break; default: strNumber = "07" + System.DateTime.Now.Year.ToString() + list[0].ToString().Substring(list[0].ToString().Length - 2, 2); break; } IList<LP_Record> listLPRecord = ClientHelper.PlatformSqlMap.GetList<LP_Record>("SelectLP_RecordList", " where kind = '" + kind + "' and number like '" + strNumber + "%'"); if (kind == "yzgzp") { strNumber += (listLPRecord.Count + 1).ToString().PadLeft(3, '0') + "-1"; } else { strNumber += (listLPRecord.Count + 1).ToString().PadLeft(3, '0'); } if (ctrlNumber != null) { ctrlNumber.Text = strNumber; currRecord.Number = ctrlNumber.Text; } if (currRecord!=null) currRecord.OrgName = str; //ContentChanged(ctrlNumber); } } LockExcel(wb, xx); }
public void FillMutilRows(ExcelAccess ea, int i, LP_Temple lp, string str, List<int> arrCellCount, string[] arrCellPos) { StringHelper help = new StringHelper(); str = help.GetPlitString(str, arrCellCount[1]); string[] extraWord = lp.ExtraWord.Split(pchar); string[] arrRst = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int j = 0; for (; i < arrCellPos.Length; i++) { if (j >= arrRst.Length) break; ea.SetCellValue(arrRst[j], GetCellPos(arrCellPos[i])[0], GetCellPos(arrCellPos[i])[1]); j++; } }
void ctrl_Leave(object sender, EventArgs e) { unLockExcel(); LP_Temple lp = (LP_Temple)(sender as Control).Tag; string str = (sender as Control).Text; if (dsoFramerWordControl1.MyExcel==null) { return; } Excel.Workbook wb = dsoFramerWordControl1.AxFramerControl.ActiveDocument as Excel.Workbook; ExcelAccess ea = new ExcelAccess(); ea.MyWorkBook = wb; ea.MyExcel=wb.Application; if (lp.CtrlType.Contains("uc_gridcontrol")) { FillTable(ea, lp, (sender as uc_gridcontrol).GetContent(String2Int(lp.WordCount.Split(pchar)))); LockExcel(); return; } else if (lp.CtrlType.Contains("DevExpress.XtraEditors.DateEdit")) { FillTime(ea, lp, (sender as DateEdit).DateTime); LockExcel(); return; } string[] arrCellpos = lp.CellPos.Split(pchar); string[] arrtemp = lp.WordCount.Split(pchar); arrCellpos = StringHelper.ReplaceEmpty(arrCellpos).Split(pchar); string[] extraWord = lp.ExtraWord.Split(pchar); List<int> arrCellCount = String2Int(arrtemp); if (arrCellpos.Length == 1||string.IsNullOrEmpty(arrCellpos[1])) ea.SetCellValue(str, GetCellPos(lp.CellPos)[0], GetCellPos(lp.CellPos)[1]); else if(arrCellpos.Length>1&&(!string.IsNullOrEmpty(arrCellpos[1]))) { StringHelper help = new StringHelper(); if (lp.CellName == "编号") { for (int j = 0; j < arrCellpos.Length; j++) { if (str.IndexOf("\r\n") == -1 && str.Length <= help.GetFristLen(str, arrCellCount[j])&&str!="" ) { string strNew = str.Substring(0, str.Length - 1) + (j + 1).ToString(); ea.SetCellValue(strNew, GetCellPos(arrCellpos[j])[0], GetCellPos(arrCellpos[j])[1]); } } LockExcel(); return; } int i = 0; if (arrCellCount[0] != arrCellCount[1]) { if (str.IndexOf("\r\n") == -1 && str.Length <= help.GetFristLen(str, arrCellCount[0])) { ea.SetCellValue(str, GetCellPos(arrCellpos[0])[0], GetCellPos(arrCellpos[0])[1]); LockExcel(); return; } ea.SetCellValue(str.Substring(0, str.IndexOf("\r\n") != -1 && help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])), GetCellPos(arrCellpos[0])[0], GetCellPos(arrCellpos[0])[1]); str = str.Substring(help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") && str.IndexOf("\r\n") != -1 ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])); i++; } str = help.GetPlitString(str, arrCellCount[1]); FillMutilRows(ea, i, lp, str, arrCellCount, arrCellpos); } if (lp.CellName == "单位") { IList list = Client.ClientHelper.PlatformSqlMap.GetList("SelectOneStr", "select OrgCode from mOrg where OrgName='" + str + "'"); if (ctrlOrgName != null) ctrlOrgName.Text = str; if (list.Count > 0) { switch (kind) { case "yzgzp": strNumber = "07" + System.DateTime.Now.Year.ToString() + list[0].ToString().Substring(list[0].ToString().Length - 2, 2); break; case "ezgzp": strNumber = "08" + System.DateTime.Now.Year.ToString() + list[0].ToString().Substring(list[0].ToString().Length - 2, 2); break; case "dzczp": strNumber = "BJ" + System.DateTime.Now.Year.ToString(); break; case "xlqxp": strNumber = list[0].ToString().Substring(list[0].ToString().Length - 2, 2) + System.DateTime.Now.Year.ToString(); break; default: strNumber = "07" + System.DateTime.Now.Year.ToString() + list[0].ToString().Substring(list[0].ToString().Length - 2, 2); break; } IList<LP_Record> listLPRecord = ClientHelper.PlatformSqlMap.GetList<LP_Record>("SelectLP_RecordList", " where kind = '" + kind + "' and number like '" + strNumber + "%'"); if (kind == "yzgzp") { strNumber += (listLPRecord.Count + 1).ToString().PadLeft(3, '0') + "-1"; } else { strNumber += (listLPRecord.Count + 1).ToString().PadLeft(3, '0'); } ctrlNumber.Text = strNumber; //ContentChanged(ctrlNumber); } } LockExcel(); }
void ContentChanged(Control ctrl) { LP_Temple lp = (LP_Temple)ctrl.Tag; string str = ctrl.Text; if (dsoFramerWordControl1.MyExcel == null) { return; } unLockExcel(); Excel.Workbook wb = dsoFramerWordControl1.AxFramerControl.ActiveDocument as Excel.Workbook; ExcelAccess ea = new ExcelAccess(); ea.MyWorkBook = wb; ea.MyExcel = wb.Application; if (lp.CtrlType.Contains("uc_gridcontrol")) { FillTable(ea, lp, (ctrl as uc_gridcontrol).GetContent(String2Int(lp.WordCount.Split(pchar)))); return; } else if (lp.CtrlType.Contains("DevExpress.XtraEditors.DateEdit")) { FillTime(ea, lp, (ctrl as DateEdit).DateTime); return; } string[] arrCellpos = lp.CellPos.Split(pchar); string[] arrtemp = lp.WordCount.Split(pchar); arrCellpos = StringHelper.ReplaceEmpty(arrCellpos).Split(pchar); arrtemp = StringHelper.ReplaceEmpty(arrtemp).Split(pchar); List<int> arrCellCount = String2Int(arrtemp); if (arrCellpos.Length == 1 || string.IsNullOrEmpty(arrCellpos[1])) ea.SetCellValue(str, GetCellPos(lp.CellPos)[0], GetCellPos(lp.CellPos)[1]); else if (arrCellpos.Length > 1 && (!string.IsNullOrEmpty(arrCellpos[1]))) { StringHelper help = new StringHelper(); if (lp.CellName == "编号") { for (int j = 0; j < arrCellpos.Length; j++) { if (str.IndexOf("\r\n") == -1 && str.Length <= help.GetFristLen(str, arrCellCount[j])) { string strNew = str.Substring(0, (str.Length>0?str.Length:1)- 1) + (j + 1).ToString(); ea.SetCellValue(strNew, GetCellPos(arrCellpos[j])[0], GetCellPos(arrCellpos[j])[1]); } } return; } int i = 0; if (arrCellCount[0] != arrCellCount[1]) { if (str.IndexOf("\r\n") == -1 && str.Length <= help.GetFristLen(str, arrCellCount[0])) { ea.SetCellValue(str, GetCellPos(arrCellpos[0])[0], GetCellPos(arrCellpos[0])[1]); return; } ea.SetCellValue(str.Substring(0, str.IndexOf("\r\n") != -1 && help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])), GetCellPos(arrCellpos[0])[0], GetCellPos(arrCellpos[0])[1]); str = str.Substring(help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") && str.IndexOf("\r\n") != -1 ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])); i++; } str = help.GetPlitString(str, arrCellCount[1]); FillMutilRows(ea, i, lp, str, arrCellCount, arrCellpos); } LockExcel(); }
void ctrl_Leave(object sender, EventArgs e) { LP_Temple lp = (LP_Temple)(sender as Control).Tag; string str = (sender as Control).Text; Excel.Workbook wb = dsoFramerWordControl1.AxFramerControl.ActiveDocument as Excel.Workbook; ExcelAccess ea = new ExcelAccess(); ea.MyWorkBook = wb; ea.MyExcel=wb.Application; if (lp.CtrlType.Contains("uc_gridcontrol")) { FillTable(ea, lp, (sender as uc_gridcontrol).GetContent(String2Int(lp.WordCount.Split(pchar)))); return; } else if (lp.CtrlType.Contains("DevExpress.XtraEditors.DateEdit")) { FillTime(ea, lp, (sender as DateEdit).DateTime); return; } string[] arrCellpos = lp.CellPos.Split(pchar); string[] arrtemp = lp.WordCount.Split(pchar); List<int> arrCellCount = String2Int(arrtemp); if (arrCellpos.Length == 1) ea.SetCellValue(str, GetCellPos(lp.CellPos)[0], GetCellPos(lp.CellPos)[1]); else if(arrCellpos.Length>1) { StringHelper help = new StringHelper(); int i = 0; if (arrCellCount[0] != arrCellCount[1]) { if (str.IndexOf("\r\n") == -1 && str.Length <= help.GetFristLen(str, arrCellCount[0])) { ea.SetCellValue(str, GetCellPos(arrCellpos[0])[0], GetCellPos(arrCellpos[0])[1]); return; } ea.SetCellValue(str.Substring(0, str.IndexOf("\r\n") != -1 && help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])), GetCellPos(arrCellpos[0])[0], GetCellPos(arrCellpos[0])[1]); str = str.Substring(help.GetFristLen(str, arrCellCount[0]) >= str.IndexOf("\r\n") && str.IndexOf("\r\n") != -1 ? str.IndexOf("\r\n") : help.GetFristLen(str, arrCellCount[0])); i++; } str = help.GetPlitString(str, arrCellCount[1]); FillMutilRows(ea, i, lp, str, arrCellCount, arrCellpos); } }