private void barButtonItem13_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { Init(); //刷新元件树 resulttb = new DataTable(); resulttb.Columns.Add("fhname", typeof(string)); resulttb.Columns.Add("zbname", typeof(string)); resulttb.Columns.Add("result", typeof(double)); resulttb.Columns.Add("pdfs", typeof(string)); resulttb.Columns.Add("A", typeof(string)); resulttb.Columns.Add("B", typeof(string)); order = 0; resultzbtb = new DataTable(); resultzbtb.Columns.Add("fhname", typeof(string)); resultzbtb.Columns.Add("zbname", typeof(string)); resultzbtb.Columns.Add("result", typeof(double)); resultzbtb.Columns.Add("pdfs", typeof(string)); resultzbtb.Columns.Add("A", typeof(string)); resultzbtb.Columns.Add("B", typeof(string)); ExcelAccess ex = new ExcelAccess(); try { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); string fname = Application.StartupPath + "\\xls\\tempt.xls"; ex.Open(fname); //ex.ActiveSheet(1); ex.SetCellValue("指标", 1, 1); ex.SetCellValue("不同的配点方式", 1, 3); ex.AlignmentCells(1, 1, 1, 1, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中); ex.SetFontStyle(1, 1, 1, 1, true, false, ExcelStyle.UnderlineStyle.无下划线); ex.CellsBackColor(1, 1, 1, 1, ExcelStyle.ColorIndex.黄色); ex.UnitCells(1, 1, 2, 2); DataTable dt = new DataTable(); frmfxlx fm = new frmfxlx(); if (fm.ShowDialog() == DialogResult.OK) { dt = fm.DT1; int columnscount = 0; foreach (DataRow dr in dt.Rows) { if (Convert.ToInt32(dr["B"]) == 1) { TreeListNode tln = treeList1.FindNodeByKeyID(pdreltypeid); bool flag = relanalsy(tln, Convert.ToInt32(dr["D"]), columnscount, ex); columnscount++; if (!flag) { ex.DisPoseExcel(); return; } } } //FrmResult FR = new FrmResult(); //FR.DT = resulttb; //FR.DT1 = resultzbtb; //FR.ShowDialog(); if (columnscount==0) { return; } ex.UnitCells(1, 3, 1, 2 + columnscount); ex.AlignmentCells(1, 3, 1, 2 + columnscount, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中); ex.SetFontStyle(1, 3, 1, 2 + columnscount, true, false, ExcelStyle.UnderlineStyle.无下划线); ex.CellsBackColor(1, 3, 1, 2 + columnscount, ExcelStyle.ColorIndex.黄色); ex.ShowExcel(); } else { ex.DisPoseExcel(); } } catch (System.Exception exe) { ex.DisPoseExcel(); MessageBox.Show("存在问题!请检查数据后再计算"); } }
private void Extbdzreport(ArrayList extsublist1) { ExcelAccess ex = new ExcelAccess(); try { string fname = Application.StartupPath + "\\xls\\tempt.xls"; ex.Open(fname); //ex.ActiveSheet(1); ex.SetCellValue("变电站名称", 1, 1); ex.SetCellValue("容量", 1, 2); ex.SetCellValue("容载比", 1, 3); ex.AlignmentCells(1, 1, 1, 3, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中); ex.SetFontStyle(1, 1, 1, 3, true, false, ExcelStyle.UnderlineStyle.无下划线); ex.CellsBackColor(1, 1, 1, 3, ExcelStyle.ColorIndex.黄色); //输出地块负荷情况 ex.SetCellValue("变电站供应负荷情况", 3 + extsublist1.Count, 1); ex.UnitCells(3 + extsublist.Count, 1, 3 + extsublist1.Count, 3); ex.SetCellValue("变电站名称", 4 + extsublist1.Count, 1); ex.SetCellValue("地块编号", 4 + extsublist1.Count, 2); ex.SetCellValue("供应负荷", 4 + extsublist1.Count, 3); ex.AlignmentCells(3 + extsublist1.Count, 1, 4 + extsublist.Count, 3, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中); ex.SetFontStyle(3 + extsublist1.Count, 1, 4 + extsublist.Count, 3, true, false, ExcelStyle.UnderlineStyle.无下划线); ex.CellsBackColor(3 + extsublist1.Count, 1, 4 + extsublist.Count, 3, ExcelStyle.ColorIndex.黄色); int rowcount = 0; for (int i = 0; i < extsublist1.Count; i++) { XmlElement xe = extsublist1[i] as XmlElement; if (!string.IsNullOrEmpty(xe.GetAttribute("subname"))) { ex.SetCellValue(xe.GetAttribute("subname"), 2 + i, 1); ex.AlignmentCells(2 + i, 1, 2 + i, 1, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中); ex.SetFontStyle(2 + i, 1, 2 + i, 1, true, false, ExcelStyle.UnderlineStyle.无下划线); ex.CellsBackColor(2 + i, 1, 2 + i, 1, ExcelStyle.ColorIndex.绿色); } if (!string.IsNullOrEmpty(xe.GetAttribute("rl"))) { ex.SetCellValue(xe.GetAttribute("rl"), 2 + i, 2); ex.AlignmentCells(2 + i, 2, 2 + i, 2, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中); ex.SetFontStyle(2 + i, 2, 2 + i, 2, true, false, ExcelStyle.UnderlineStyle.无下划线); } if (!string.IsNullOrEmpty(xe.GetAttribute("yfcrzb"))) { ex.SetCellValue(xe.GetAttribute("yfcrzb"), 2 + i, 3); ex.AlignmentCells(2 + i, 3, 2 + i, 3, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中); ex.SetFontStyle(2 + i, 3, 2 + i, 3, true, false, ExcelStyle.UnderlineStyle.无下划线); } //地块负荷供应情况 string fhdk = xe.GetAttribute("fhdk"); if (!string.IsNullOrEmpty(fhdk)) { string[] dkqk = (fhdk.Substring(0, fhdk.LastIndexOf(";"))).Split(';'); for (int j = 0; j < dkqk.Length; j++) { string[] dk = dkqk[j].Split(','); if (!string.IsNullOrEmpty(xe.GetAttribute("subname"))) { ex.SetCellValue(xe.GetAttribute("subname"), 5 + extsublist1.Count + rowcount, 1); ex.AlignmentCells(5 + extsublist1.Count + rowcount, 1, 5 + extsublist1.Count + rowcount, 1, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中); ex.SetFontStyle(5 + extsublist1.Count + rowcount, 1, 5 + extsublist1.Count + rowcount, 1, true, false, ExcelStyle.UnderlineStyle.无下划线); ex.CellsBackColor(5 + extsublist1.Count + rowcount, 1, 5 + extsublist1.Count + rowcount, 1, ExcelStyle.ColorIndex.绿色); } if (dk.Length > 0) { glebeProperty pl = new glebeProperty(); pl.EleID = dk[0]; pl.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid; pl = (glebeProperty)Services.BaseService.GetObject("SelectglebePropertyByEleID", pl); ex.SetCellValue(pl.UseID, 5 + extsublist1.Count + rowcount, 2); ex.SetCellValue((Convert.ToDouble(dk[1]) / dbl_rzb).ToString("N2"), 5 + extsublist1.Count + rowcount, 3); ex.AlignmentCells(5 + extsublist1.Count + rowcount, 2, 5 + extsublist1.Count + rowcount, 3, ExcelStyle.ExcelHAlign.居中, ExcelStyle.ExcelVAlign.居中); ex.SetFontStyle(5 + extsublist1.Count + rowcount, 2, 5 + extsublist1.Count + rowcount, 3, true, false, ExcelStyle.UnderlineStyle.无下划线); } rowcount++; } } } ex.ShowExcel(); } catch (System.Exception e) { ex.DisPoseExcel(); } }