// 运行excel的vba宏 public object RunExcelMacro(string strMacroName, object args) { LuaTable ltArgs = args as LuaTable; if (ltArgs == null) { MessageBox.Show("调用RunExcelMacro(string strMacroName, object args)时参数为空!"); return(null); } object[] oArgArr = new object[ltArgs.Values.Count]; for (int i = 0; i < oArgArr.Length; i++) { oArgArr[i] = ltArgs[i]; } object[] ArgArr30 = new object[30]; for (int i = 0; i < oArgArr.Length; i++) { ArgArr30[i] = oArgArr[i]; } for (int i = oArgArr.Length; i < ArgArr30.Length; i++) { ArgArr30[i] = Missing.Value; } if (excelApp == null) // 未初始化成功 { MessageBox.Show("运行Excel的vba宏失败!\n\n请检查是否已在机器上装有Excel."); return(null); // 脚本已经对null值的处理 } object result_macro = null; try { result_macro = excelApp.Run(strMacroName, ArgArr30[0], ArgArr30[1], ArgArr30[2], ArgArr30[3], ArgArr30[4], ArgArr30[5], ArgArr30[6], ArgArr30[7], ArgArr30[8], ArgArr30[9], ArgArr30[10], ArgArr30[11], ArgArr30[12], ArgArr30[13], ArgArr30[14], ArgArr30[15], ArgArr30[16], ArgArr30[17], ArgArr30[18], ArgArr30[19], ArgArr30[20], ArgArr30[21], ArgArr30[22], ArgArr30[23], ArgArr30[24], ArgArr30[25], ArgArr30[26], ArgArr30[27], ArgArr30[28], ArgArr30[29]); } catch (Exception ex) { MessageBox.Show("宏运行错误,请不要保存所作修改!"); } return(result_macro as string[]); #if false Excel.ApplicationClass oExcel = new Excel.ApplicationClass(); oExcel.Visible = true; Excel.Workbooks oBooks = oExcel.Workbooks; Excel._Workbook oBook = null; string strXL = "C:/Documents and Settings/kuangsihao/桌面/剑网3-NPC数值.xlsm"; oBook = oBooks.Open(strXL, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing); RunMacro(oExcel, new Object[] { "矩形1_Click" });
private void butIn_Click(object sender, System.EventArgs e) { d.check_process_Excel(); string sql = "select a.ma,a.tenhc,trim(a.ten)||' '||a.hamluong as ten,a.dang as dvt,a.gia_bh from " + user + ".d_dmbd a," + user + ".d_dmnhom c where a.manhom=c.id and a.nhom=" + i_nhom + " and gia_bh>0 and bhyt<>0"; sql += "order by "; if (d.bSort_mabd) { sql += " a.ma"; } else { sql += " a.ten"; } d.check_process_Excel(); string tenfile = d.Export_Excel(d.get_data(sql), "dmthuoc"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlPortrait; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; oxl.Visible = true; }
private void butExcel_Click(object sender, System.EventArgs e) { if (butExcel.Enabled == false) { return; } d.check_process_Excel(); string tenfile = d.Export_Excel(dt, ReportFile.Substring(0, ReportFile.Length - 4)); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; oxl.ActiveWindow.DisplayZeros = false; try { osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; } catch { } oxl.Visible = true; }
private void exp_excel(bool print) { try { int be = 3, dong = 5, sodong = ds.Tables[0].Rows.Count + 5, socot = ds.Tables[0].Columns.Count - 2, dongke = sodong - 1; tenfile = ttb.Export_Excel(ds, "bcngay"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; osheet.get_Range(ttb.getIndex(0) + "1", ttb.getIndex(0) + "1").EntireColumn.Delete(Missing.Value); for (int i = 0; i < be; i++) { osheet.get_Range(ttb.getIndex(i) + "1", ttb.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.get_Range(ttb.getIndex(be) + dong.ToString(), ttb.getIndex(socot + 1) + sodong.ToString()).NumberFormat = "#,##0.00"; osheet.get_Range(ttb.getIndex(0) + "4", ttb.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; for (int i = 1; i < dong; i++) { osheet.Cells[dong - 1, i] = get_ten(i - 1); } orange = osheet.get_Range(ttb.getIndex(0) + "1", ttb.getIndex(socot) + sodong.ToString()); osheet.Cells[dong - 1, dsngay.Tables[0].Rows.Count + 5] = "Cộng"; for (int i = 0; i < dsngay.Tables[0].Rows.Count; i++) { osheet.Cells[dong - 1, i + 5] = " " + dsngay.Tables[0].Rows[i]["ten"].ToString(); } osheet.get_Range(ttb.getIndex(4) + "4", ttb.getIndex(dsngay.Tables[0].Rows.Count + 5) + "4").Orientation = 90; osheet.get_Range(ttb.getIndex(0) + "4", ttb.getIndex(dsngay.Tables[0].Rows.Count + 5) + "4").RowHeight = 30; orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.Cells[1, 2] = ttb.Syte; osheet.Cells[2, 2] = ttb.Tenbv; osheet.Cells[1, 4] = "BÁO CÁO SỬ DỤNG"; osheet.Cells[2, 4] = (tu.Text == den.Text)?"Ngày : " + tu.Text:"Từ ngày : " + tu.Text + " đến : " + den.Text; orange = osheet.get_Range(ttb.getIndex(3) + "1", ttb.getIndex(socot - 1) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void butExcel_Click(object sender, System.EventArgs e) { get_data(); DataSet tmp = new DataSet(); tmp = ds.Copy(); tmp.Clear(); tmp.Merge(ds.Tables[0].Select("true", "tenbd")); if (tmp.Tables[0].Rows.Count > 0) { d.check_process_Excel(); string tenfile = d.Export_Excel(tmp, "dmthuoc"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; for (int i = 0; i < 8; i++) { osheet.Cells[1, i + 1] = get_ten(i); } oxl.ActiveWindow.DisplayGridlines = true; oxl.ActiveWindow.DisplayZeros = false; int row = tmp.Tables[0].Rows.Count + 1; osheet.get_Range(d.getIndex(0) + "1", d.getIndex(tmp.Tables[0].Columns.Count - 1) + row.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; oxl.Visible = true; } }
/// <summary> /// 将datatable的数据导出到excel /// </summary> /// <param name="mdt"></param> private void DataToExcel(DataTable mdt) { Excel.ApplicationClass oExcel = new Excel.ApplicationClass(); Excel.Workbooks oBooks = oExcel.Workbooks; Excel._Workbook oBook = null; oBook = (Excel._Workbook)(oExcel.Workbooks.Add(true));// 引用excel工作薄 for (int i = 0; i < mdt.Columns.Count; i++) { oExcel.Cells[2, i + 1] = mdt.Columns[i].ColumnName.ToString();// m_DataView.Columns[i].HeaderText.ToString(); } for (int i = 0; i < mdt.Rows.Count; i++) { for (int j = 0; j < mdt.Columns.Count; j++) { oExcel.Cells[i + 3, j + 1] = mdt.Rows[i][j].ToString(); } } oExcel.Visible = true; object Missing = System.Reflection.Missing.Value; // oExcel.Run("Sheet1.printdoc", Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing); oBook.Application.DisplayAlerts = false; }
private void exp_excel(bool print) { try { ttb.check_process_Excel(); ds = dsxml.Copy(); int be = 2, dong = 4, sodong = ds.Tables[0].Rows.Count + dong, socot = ds.Tables[0].Columns.Count - 1, dongke = sodong - 1; tenfile = ttb.Export_Excel(ds, "dutru"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; for (int i = 0; i < be; i++) { osheet.get_Range(ttb.getIndex(i) + "1", ttb.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.get_Range(ttb.getIndex(be - 1) + dong.ToString(), ttb.getIndex(socot + 1) + sodong.ToString()).NumberFormat = "#,##0.00"; osheet.get_Range(ttb.getIndex(0) + "3", ttb.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; int pos = 7; foreach (DataRow r in dtmakp.Select("makp<>''", "stt,makp")) { osheet.Cells[dong - 1, pos] = r["tenkp"].ToString(); pos += 1; } //osheet.Cells[dong-1,pos]="Tồn "+makho.Text; for (int i = 0; i < 6; i++) { osheet.Cells[dong - 1, i + 1] = get_ten(i); } orange = osheet.get_Range(ttb.getIndex(0) + "1", ttb.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.Cells[1, 2] = ttb.Syte; osheet.Cells[2, 2] = ttb.Tenbv; s_mmyy = tu.Value.ToString().PadLeft(2, '0') + yyyy.Value.ToString().PadLeft(4, '0').Substring(2, 2); osheet.Cells[1, 4] = "TỔNG HỢP DÙ TRÙ"; string s_title = ttb.title(tu.Value.ToString(), tu.Value.ToString()) + " năm " + yyyy.Value.ToString(); osheet.Cells[2, 4] = s_title; orange = osheet.get_Range(ttb.getIndex(3) + "1", ttb.getIndex(socot - 1) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch { } }
private void exp_excel() { try { string s; int be = 3, dong = 6, sodong = ds.Tables[0].Rows.Count + 6, socot = ds.Tables[0].Columns.Count - 2, dongke = sodong - 2; tenfile = d.Export_Excel(ds, "biendong"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; for (int i = 0; i < be; i++) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.Cells[dong - 2, 3] = "Tên hoạt chất"; osheet.Cells[dong - 2, 4] = "Tên thuốc - hàm lượng"; osheet.Cells[dong - 2, 5] = "ĐVT"; osheet.Cells[dong - 2, 6] = "Diễn giải"; for (int i = 0; i < i_rec; i++) { s = ds.Tables[0].Columns[i + 6].ColumnName.ToString(); osheet.Cells[dong - 2, i + 7] = "'" + s.Substring(4, 2) + "/" + s.Substring(2, 2) + "/" + s.Substring(0, 2); } osheet.Cells[dong - 2, i_rec + 7] = "Tỷ lệ"; osheet.Cells[dong - 2, i_rec + 8] = "Ghi chú"; osheet.get_Range(d.getIndex(0) + "1", d.getIndex(0) + "1").EntireColumn.Delete(Missing.Value); osheet.get_Range(d.getIndex(0) + "1", d.getIndex(0) + "1").EntireColumn.Delete(Missing.Value); osheet.get_Range(d.getIndex(be) + dong.ToString(), d.getIndex(socot) + sodong.ToString()).NumberFormat = "#,##0.00"; osheet.get_Range(d.getIndex(0) + "4", d.getIndex(socot - 1) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.Cells[1, 1] = d.Syte; osheet.Cells[2, 1] = d.Tenbv; osheet.Cells[1, 3] = "BIẾN ĐỘNG GIÁ THUỐC"; osheet.Cells[2, 3] = "Từ ngày " + tu.Text + " đến " + den.Text; orange = osheet.get_Range(d.getIndex(2) + "1", d.getIndex(socot - 1) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; oxl.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exp_excel(bool print) { d.check_process_Excel(); ds = dsxml.Copy(); int be = 2, dong = 4, sodong = ds.Tables[0].Rows.Count + dong, socot = ds.Tables[0].Columns.Count - 1, dongke = sodong - 1; tenfile = d.Export_Excel(ds, "cosotutruc"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; for (int i = 0; i < be; i++) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.get_Range(d.getIndex(be - 1) + dong.ToString(), d.getIndex(socot + 1) + sodong.ToString()).NumberFormat = "#,##0.00"; osheet.get_Range(d.getIndex(0) + "3", d.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; for (int i = 0; i < 8; i++) { osheet.Cells[dong - 1, i + 1] = get_ten(i); } orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.Cells[1, 2] = d.Syte; osheet.Cells[2, 2] = d.Tenbv; osheet.Cells[1, 4] = "BÁO CÁO SỬ DỤNG NỘI TRÚ"; string s_title = "Từ ngày " + tu.Text + " đến ngày " + den.Text; if (tu.Text == den.Text) { s_title = "Ngày " + tu.Text; } osheet.Cells[2, 4] = s_title; orange = osheet.get_Range(d.getIndex(3) + "1", d.getIndex(socot - 1) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } }
private void exp_excel(bool print) { d.check_process_Excel(); ds = dsxml.Copy(); int dong = 2, sodong = ds.Tables[0].Rows.Count + dong, socot = ds.Tables[0].Columns.Count - 1, dongke = sodong - 1; tenfile = d.Export_Excel(ds, "cosotutruc"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; osheet.get_Range(d.getIndex(3) + dong.ToString(), d.getIndex(socot + 1) + sodong.ToString()).NumberFormat = format_soluong; osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; int pos = 5; foreach (DataRow r in dtmakp.Select("makp<>''", "stt,makp")) { osheet.Cells[dong - 1, pos] = r["tenkp"].ToString(); pos += 1; } for (int i = 0; i < 4; i++) { osheet.Cells[dong - 1, i + 1] = get_ten(i); } orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 10; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; string s_title = "Từ ngày " + tu.Text + " đến ngày " + den.Text; if (tu.Text == den.Text) { s_title = "Ngày " + tu.Text; } osheet.PageSetup.LeftHeader = d.Syte + "\n" + d.Tenbv; osheet.PageSetup.CenterHeader = "&\"Arial,Bold\"&14BÁO CÁO CƠ SỐ TỦ TRỰC\n" + s_title; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } }
private void exp_excel(bool print) { d.check_process_Excel(); ds = dsxml.Copy(); int k = 7, dong = 1, sodong = ds.Tables[0].Rows.Count + dong, socot = ds.Tables[0].Columns.Count - 1, dongke = sodong; tenfile = d.Export_Excel(ds, "BCNHAPKHO"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; //for(int i=0;i<2;i++) osheet.get_Range(d.getIndex(i)+"1",d.getIndex(i)+"1").EntireRow.Insert(Missing.Value); osheet.get_Range(d.getIndex(1) + dong.ToString(), d.getIndex(socot + 1) + sodong.ToString()).NumberFormat = format_soluong; osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; for (int i = 0; i < 6; i++) { osheet.Cells[dong, i + 1] = get_ten(i); } for (int j = Convert.ToInt16(tu.Value); j <= Convert.ToInt16(den.Value); j++) { osheet.Cells[dong, k++] = "Tháng " + j.ToString().PadLeft(2, '0'); } osheet.Cells[dong, k] = "Tổng cộng"; orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 10; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; string s_title = "Từ tháng " + tu.Value.ToString().PadLeft(2, '0') + " đến " + den.Value.ToString().PadLeft(2, '0'); if (tu.Text == den.Text) { s_title = "Tháng " + tu.Value.ToString().PadLeft(2, '0'); } s_title += " Năm " + yyyy.Value.ToString(); osheet.PageSetup.LeftHeader = d.Syte + "\n" + d.Tenbv; osheet.PageSetup.CenterHeader = "&\"Arial,Bold\"&14BÁO CÁO NHẬP KHO\n" + s_title; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } }
public ExcelController(bool excelVisible, IReport report) { dtBefore = System.DateTime.Now; CurExcel = new Excel.ApplicationClass(); CurExcel.DisplayAlerts = false; dtAfter = System.DateTime.Now; CurExcel.Visible = excelVisible; //CurExcel.Workbooks.Add(true); CurExcel.Workbooks.Add(mValue); sheetIndex = 1; CurSheet = CurExcel.Worksheets[sheetIndex] as Excel.Worksheet; CurBook = CurExcel.Workbooks[1]; pictureIndex = 0; log = new EasilyReportLog("Excel Report", this.GetType().FullName, LogFileInfo.logFileName, report); }
private void butIn_Click(object sender, System.EventArgs e) { d.check_process_Excel(); int be = 3; int dong = dsxml.Tables[0].Rows.Count + be + 1, socot = dsxml.Tables[0].Columns.Count; string ten, tenfile = d.Export_Excel(dsxml, "sudungthuoc"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; oxl.ActiveWindow.DisplayZeros = false; for (int i = 0; i < be; i++) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.get_Range(d.getIndex(0) + "1", d.getIndex(0) + "1").EntireColumn.Delete(Missing.Value); osheet.Cells[be + 1, 1] = "Tên thuốc - hàm lượng"; osheet.Cells[be + 1, 2] = "ĐVT"; int j = 3; for (; j < socot - 1; j++) { ten = dsxml.Tables[0].Columns[j].ColumnName.Substring(2); osheet.Cells[be + 1, j] = ten.Substring(6, 2) + "/" + ten.Substring(4, 2) + "/" + ten.Substring(2, 2); } osheet.Cells[be + 1, j] = "Tổng cộng"; orange = osheet.get_Range(m.getIndex(0) + "4", m.getIndex(socot - 2) + "4"); orange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; orange.HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter; osheet.get_Range(d.getIndex(be - 1) + "4", d.getIndex(socot - 2) + "4").Orientation = 90; osheet.get_Range(d.getIndex(0) + "4", d.getIndex(socot - 2) + dong.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; osheet.get_Range(m.getIndex(0) + "4", m.getIndex(socot - 2) + dong.ToString()).EntireColumn.AutoFit(); osheet.Cells[1, 1] = "Họ tên :" + dataGrid1[dataGrid1.CurrentCell.RowNumber, 1].ToString().Trim() + "-" + dataGrid1[dataGrid1.CurrentCell.RowNumber, 2].ToString().Trim(); osheet.Cells[2, 1] = "Ngày vào :" + dataGrid1[dataGrid1.CurrentCell.RowNumber, 5].ToString(); osheet.Cells[2, 4] = "Ngày phẫu thủ thuật :" + dataGrid1[dataGrid1.CurrentCell.RowNumber, 6].ToString().Substring(0, 10); osheet.Cells[3, 1] = "Phương pháp phẫu thủ thuật :" + dataGrid1[dataGrid1.CurrentCell.RowNumber, 7].ToString().Trim(); oxl.Visible = true; }
private void butIn_Click(object sender, System.EventArgs e) { d.check_process_Excel(); sql = "select a.ma,trim(a.ten)||' '||trim(a.hamluong) as ten,a.dang,trunc(a.dongia,2) as dongia,trunc(a.giaban,0) as giaban,"; sql += "case when a.dongia<>0 and a.giaban<>0 then round((a.giaban/(a.dongia)-1)*100,2) else 0 end as tyle,"; sql += "b.ten as tenhang,c.ten as tennuoc,d.ten as tennx,e.ten as tennhom "; sql += "from " + user + ".d_dmbd a inner join " + user + ".d_dmhang b on a.mahang=b.id "; sql += " inner join " + user + ".d_dmnuoc c on a.manuoc=c.id "; sql += " left join " + user + ".d_dmnx d on a.madv=d.id "; sql += " inner join " + user + ".d_dmnhom e on a.manhom=e.id "; sql += "where a.dongia<>0 and a.giaban<>0 and a.giaban>=a.dongia and a.nhom=" + i_nhom; sql += " order by a.ma"; ds = d.get_data(sql); DataSet tmp = new DataSet(); tmp = ds.Copy(); tmp.Clear(); tmp.Merge(ds.Tables[0].Select("true", "ma")); string tenfile = d.Export_Excel(tmp, "dmthuoc"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; for (int i = 0; i < 10; i++) { osheet.Cells[1, i + 1] = get_ten(i); } oxl.ActiveWindow.DisplayGridlines = true; oxl.ActiveWindow.DisplayZeros = false; int row = tmp.Tables[0].Rows.Count + 1; osheet.get_Range(d.getIndex(0) + "1", d.getIndex(tmp.Tables[0].Columns.Count - 1) + row.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.PageSetup.LeftHeader = d.Syte + "\n" + d.Tenbv; osheet.PageSetup.RightFooter = "Ngày in :" + d.Ngay_hethong_gio.ToString(); osheet.PageSetup.CenterHeader = "&\"Arial,Bold\"&14THEO DÕI GIÁ THUỐC NHÀ THUỐC BỆNH VIỆN"; oxl.Visible = true; }
private void butExcel_Click(object sender, System.EventArgs e) { if (butExcel.Enabled == false) { MessageBox.Show("Bạn chưa được phân quyền kết xuất."); return; } m_v.check_process_Excel(); string tenfile = m_v.f_export_excel(dt, ReportFile); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; oxl.Visible = true; }
private void exp_excel(bool print) { try { m_v.check_process_Excel(); int i_rec = 0, be = 4, dong = 6, sodong = ads.Tables[0].Rows.Count + 6, socot = ads.Tables[0].Columns.Count - 1, dongke = sodong - 1; char[] cSplit = { '+' }; string[] sTitle = haison.Split(cSplit); i_rec = sTitle.Length; tenfile = m_v.f_export_excel(ads.Tables[0], "doanhthu"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; for (int i = 0; i < be; i++) { osheet.get_Range(m_v.getIndex(i) + "1", m_v.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.get_Range(m_v.getIndex(0) + "5", m_v.getIndex(0) + "5").EntireRow.Delete(Missing.Value);//remove row field osheet.get_Range(m_v.getIndex(2) + "5", m_v.getIndex(socot) + sodong.ToString()).NumberFormat = "###,###,###,###"; osheet.get_Range(m_v.getIndex(0) + "4", m_v.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; osheet.Cells[dong - 2, 1] = "STT"; osheet.Cells[dong - 2, 2] = "Nội dung"; osheet.Cells[dong + 3, 2] = "Tổng cộng"; for (int i = 0; i < i_rec; i++) { osheet.Cells[dong - 2, i + 3] = sTitle[i].ToString(); osheet.Cells[dong + 3, i + 3] = "=SUM(" + m_v.getIndex(i + 2) + "5:" + m_v.getIndex(i + 2) + "8)"; } orange = osheet.get_Range(m_v.getIndex(i_rec * 2 + 4) + "4", m_v.getIndex(i_rec * 2 + 5) + "4"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Bold = true; orange = osheet.get_Range(m_v.getIndex(0) + "1", m_v.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.Cells[1, 1] = m_v.Syte; osheet.Cells[2, 1] = m_v.Tenbv; orange = osheet.get_Range(m_v.getIndex(1) + "1", m_v.getIndex(3) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; osheet.Cells[1, 8] = "BÁO CÁO DOANH THU THEO NGƯỜI THU"; osheet.Cells[2, 8] = (tu.Value == den.Value) ? "Ngày " + tu.Text : "Từ ngày :" + tu.Text + " đến ngày :" + den.Text; orange = osheet.get_Range(m_v.getIndex(3) + "1", m_v.getIndex(socot - 1) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exp_excel(bool print) { try { d.check_process_Excel(); int i_rec = 0, be = 4, dong = 6, sodong = ads.Tables[0].Rows.Count + 6, socot = ads.Tables[0].Columns.Count - 1, dongke = sodong - 1; char[] cSplit = { '+' }; string[] sTitle = haison.Split(cSplit); i_rec = sTitle.Length; tenfile = d.Export_Excel(ads, "HOSOBENHAN"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; for (int i = 0; i < be; i++) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.get_Range(d.getIndex(0) + "5", d.getIndex(0) + "5").EntireRow.Delete(Missing.Value); //remove row field osheet.get_Range(d.getIndex(0) + "4", d.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; for (int i = 0; i < i_rec; i++) { osheet.Cells[dong - 2, i + 1] = sTitle[i].ToString(); } orange = osheet.get_Range(d.getIndex(i_rec * 2 + 4) + "4", d.getIndex(i_rec * 2 + 5) + "4"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Bold = true; orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; // osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; // osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; // osheet.PageSetup.LeftMargin = 20; // osheet.PageSetup.RightMargin = 20; // osheet.PageSetup.TopMargin = 30; // osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.Cells[1, 1] = d.Syte; osheet.Cells[2, 1] = d.Tenbv; orange = osheet.get_Range(d.getIndex(1) + "1", d.getIndex(3) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; osheet.Cells[1, 8] = "SỔ VÀO VIỆN - RA VIỆN - CHUYỂN VIỆN"; osheet.Cells[2, 8] = (tu.Text == den.Text) ? "Tháng " + tu.Text : "Từ ngày " + tu.Text + " đến ngày" + den.Text; if (s_tenkp.Trim().Trim(',') != "") { osheet.Cells[3, 8] = s_tenkp; } orange = osheet.get_Range(d.getIndex(3) + "1", d.getIndex(socot - 1) + "3"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void exp_excel(bool print) { try { int be = 3, cot = ds.Tables[0].Columns.Count, dong = ds.Tables[0].Rows.Count + be + 2; tenfile = d.Export_Excel(ds, "ylenh"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; for (int i = 0; i < be; i++) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } for (int i = 0; i < 5; i++) { osheet.Cells[be + 1, i + 1] = get_ten(i); } DataRow [] dr = dsmabd.Tables[0].Select("true", "stt"); //"tenbd"; for (int i = 0; i < dr.Length; i++) { osheet.Cells[be + 1, i + 6] = dr[i]["tenbd"].ToString(); osheet.Cells[dong, i + 6] = dr[i]["soluong"].ToString(); } //Phong giuong orange = osheet.get_Range(d.getIndex(1) + "4", d.getIndex(2) + "4"); orange.VerticalAlignment = XlVAlign.xlVAlignBottom; orange.Orientation = 90; orange.RowHeight = 180; //Ten Thuoc orange = osheet.get_Range(d.getIndex(be + 2) + "4", d.getIndex(cot - 1) + "4"); orange.VerticalAlignment = XlVAlign.xlVAlignBottom; orange.WrapText = false; orange.Orientation = 90; orange.RowHeight = 180; orange.Font.Bold = true; orange.EntireRow.AutoFit(); //Hien thi chi tiet orange = osheet.get_Range(d.getIndex(0) + "5", d.getIndex(cot - 1) + dong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 10; orange.Font.Bold = false; orange.RowHeight = 16; orange.NumberFormat = "###0.##"; osheet.get_Range(d.getIndex(0) + "4", d.getIndex(cot) + dong.ToString()).Borders.LineStyle = XlLineStyle.xlDot; // XlBorderWeight.xlThin; orange.EntireColumn.AutoFit(); //cot hoten BN: In dam orange = osheet.get_Range(d.getIndex(4) + "4", d.getIndex(4) + dong.ToString()); orange.Font.Name = "Arial"; orange.Font.Bold = true; orange.EntireColumn.AutoFit(); // string s_tt = (tt1.Checked)?tt1.Text:(tt2.Checked)?tt2.Text:""; osheet.get_Range(d.getIndex(4) + dong.ToString(), d.getIndex(cot - 1) + dong.ToString()).Font.Bold = true; oxl.ActiveWindow.DisplayZeros = false; osheet.Cells[1, 2] = makp.Text + " " + s_tt; osheet.Cells[2, 2] = (tu.Text == den.Text)?"Ngày " + tu.Text:"Ngày " + tu.Text + " - " + den.Text; osheet.Cells[2, 6] = ((s_tenphieu == "")?"":s_tenphieu + " : ") + ((s_buoi == "")?"Cả ngày":s_buoi); osheet.Cells[1, 5] = "TỔNG HỢP Y LỆNH"; orange = osheet.get_Range(d.getIndex((cot > 3)?4:cot - 1) + "1", d.getIndex(cot - 1) + "1"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; //border lai dong cot int jcot = (cot < 16)?16:cot; // for (int ji = 0; ji < jcot; ji++) { orange = osheet.get_Range(m.getIndex(ji) + "4", m.getIndex(ji) + dong); orange.Cells.BorderAround(5, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, 0); if (ji >= cot) { orange.ColumnWidth = 3; //[b.getIndex(0)+"3",b.getIndex(ji)] } } for (int ji = 4; ji < dong; ji++) { orange = osheet.get_Range(m.getIndex(0) + ji, m.getIndex(jcot) + ji); orange.Cells.BorderAround(5, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, 0); } orange = osheet.get_Range(m.getIndex(0) + "4:" + m.getIndex(0) + dong, m.getIndex(0) + "4:" + m.getIndex(jcot) + dong); orange.Cells.BorderAround(1, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, 2); // //ke them row trong for (int ji = 0; ji < jcot; ji++) { orange = osheet.get_Range(m.getIndex(ji) + (dong + 3), m.getIndex(ji) + (dong + 15)); orange.Cells.BorderAround(5, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, 0); if (ji >= cot) { orange.ColumnWidth = 3; //[b.getIndex(0)+"3",b.getIndex(ji)] } } for (int ji = dong + 3; ji < dong + 15; ji++) { orange = osheet.get_Range(m.getIndex(0) + ji, m.getIndex(jcot - 1) + ji); orange.Cells.BorderAround(5, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, 0); } // for (int ji = 5; ji <= dong + 15; ji++) { orange = osheet.get_Range(m.getIndex(0) + ji, m.getIndex(cot) + ji); orange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; orange.RowHeight = 16; orange.WrapText = false; } // //Ten Thuoc orange = osheet.get_Range(d.getIndex(be + 2) + "4", d.getIndex(cot - 1) + "4"); orange.VerticalAlignment = XlVAlign.xlVAlignBottom; orange.WrapText = false; orange.Orientation = 90; orange.RowHeight = 180; orange.Font.Bold = true; orange.EntireRow.AutoFit(); //end binh osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exp_excel(bool print) { try { int i_rec = dtdmkho.Rows.Count, be = 4, dong = 6, sodong = ds.Tables[0].Rows.Count + 6, socot = ds.Tables[0].Columns.Count - 1, dongke = sodong - 1; tenfile = d.Export_Excel(ds, "danhap"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; osheet.get_Range(d.getIndex(0) + "1", d.getIndex(0) + "1").EntireColumn.Delete(Missing.Value); for (int i = 0; i < be; i++) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.get_Range(d.getIndex(be) + dong.ToString(), d.getIndex(socot) + sodong.ToString()).NumberFormat = "#,##0.00"; osheet.get_Range(d.getIndex(0) + "4", d.getIndex(socot - 1) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; for (int i = 0; i < i_rec; i++) { osheet.Cells[dong - 2, i *2 + 5] = dtdmkho.Rows[i]["ten"].ToString(); orange = osheet.get_Range(d.getIndex(i * 2 + 4) + "4", d.getIndex(i * 2 + 5) + "4"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Bold = true; } osheet.Cells[dong - 2, i_rec *2 + 5] = "Tổng cộng"; orange = osheet.get_Range(d.getIndex(i_rec * 2 + 4) + "4", d.getIndex(i_rec * 2 + 5) + "4"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Bold = true; for (int i = 1; i <= be; i++) { osheet.Cells[dong - 1, i] = get_ten(i + 1); orange = osheet.get_Range(d.getIndex(i - 1) + "4", d.getIndex(i - 1) + "5"); orange.MergeCells = true; } for (int i = be; i < socot; i++) { osheet.Cells[dong - 1, i + 1] = get_ten(i % 2); } orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.Cells[1, 2] = d.Syte; osheet.Cells[2, 2] = d.Tenbv; orange = osheet.get_Range(d.getIndex(1) + "1", d.getIndex(3) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; s_mmyy = tu.Value.ToString().PadLeft(2, '0') + yyyy.Value.ToString().PadLeft(4, '0').Substring(2, 2); s_tu = tu.Value.ToString().PadLeft(2, '0'); s_den = den.Value.ToString().PadLeft(2, '0'); s_yy = yyyy.Value.ToString().PadLeft(4, '0').Substring(2, 2); osheet.Cells[1, 4] = "BÁO CÁO LĨNH TỪ " + khott.Text.Trim().ToUpper(); osheet.Cells[2, 4] = (tu.Value == den.Value)?"Tháng : " + s_tu + "/" + yyyy.Value.ToString():"Từ tháng :" + s_tu + "/" + yyyy.Value.ToString() + " đến tháng :" + s_den + "/" + yyyy.Value.ToString(); orange = osheet.get_Range(d.getIndex(3) + "1", d.getIndex(socot - 1) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exp_excel(bool print) { d.check_process_Excel(); try { int be = 3, dong = 5, sodong = dsxml.Tables[0].Rows.Count + 5, socot = dsxml.Tables[0].Columns.Count - 1, dongke = sodong; tenfile = d.Export_Excel(dsxml, "solankham"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value));//,Missing.Value,Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; for (int i = 0; i < be; i++) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value); //,Missing.Value); } osheet.get_Range(d.getIndex(be + 2) + dong.ToString(), d.getIndex(socot) + sodong.ToString()).NumberFormat = "#,##0"; osheet.get_Range(d.getIndex(0) + "4", d.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; for (int i = 0; i <= socot; i++) { osheet.Cells[dong - 1, i + 1] = get_ten(i).ToString(); } osheet.Cells[sodong, 2] = "TỔNG CỘNG"; orange = osheet.get_Range(d.getIndex(0) + "4", d.getIndex(1) + "4"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Bold = true; int so = sodong; osheet.Cells[sodong, 4] = soluot; osheet.Cells[sodong, 5] = dcongkham; osheet.Cells[sodong, 6] = dthuoc; osheet.Cells[sodong, 7] = dcls; osheet.Cells[sodong, 8] = dcongkham + dthuoc + dcls; orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlPortrait; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.Cells[sodong + 1, 6] = "Ngày ... tháng ... năm ...."; osheet.Cells[sodong + 2, 2] = "THỦ TRƯỞNG ĐƠN VỊ"; osheet.Cells[sodong + 2, 6] = " NGƯỜI LẬP BIỂU "; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.Cells[1, 1] = d.Syte; osheet.Cells[2, 1] = d.Tenbv; orange = osheet.get_Range(d.getIndex(1) + "1", d.getIndex(3) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; osheet.Cells[1, 3] = "TỔNG HỢP SỐ LƯỢT KHÁM BỆNH " + madoituong.Text.Trim().ToUpper() + " NGỌAI TRÚ"; osheet.Cells[2, 3] = (tu.Text == den.Text)?"Ngày : " + tu.Text:"Từ ngày :" + tu.Text + " đến ngày :" + den.Text; orange = osheet.get_Range(d.getIndex(2) + "1", d.getIndex(socot) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exp_excel(bool print) { try { string loai = loaibenh.Text != ""?"(" + loaibenh.Text.ToUpper() + ")":""; int be = 5, dong = 4, sodong = ds.Tables[0].Rows.Count + 1, socot = ds.Tables[0].Columns.Count + 1, dongke = sodong - 1; tenfile = m.Export_Excel(ds, "bcngay"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; osheet.get_Range(b.getIndex(0) + "1", b.getIndex(0) + "1").EntireRow.Delete(Missing.Value); for (int i = 0; i < be; i++) { osheet.get_Range(b.getIndex(i) + "1", b.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.get_Range(b.getIndex(1) + dong.ToString(), b.getIndex(socot - 2) + (dong + sodong + 1).ToString()).NumberFormat = "#,##"; osheet.get_Range(b.getIndex(0) + dong.ToString(), b.getIndex(socot - 2) + (dong + dongke + 1).ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; osheet.get_Range(b.getIndex(0) + (dong + 1), b.getIndex(0) + dong).Merge(Missing.Value); osheet.get_Range(b.getIndex(0) + (dong + 1), b.getIndex(0) + dong).VerticalAlignment = XlVAlign.xlVAlignCenter; osheet.get_Range(b.getIndex(1) + dong, b.getIndex(16) + dong).Merge(Missing.Value); osheet.get_Range(b.getIndex(1) + dong, b.getIndex(16) + dong).HorizontalAlignment = XlHAlign.xlHAlignCenter; osheet.get_Range(b.getIndex(17) + dong, b.getIndex(32) + dong).Merge(Missing.Value); osheet.get_Range(b.getIndex(17) + dong, b.getIndex(32) + dong).HorizontalAlignment = XlHAlign.xlHAlignCenter; osheet.get_Range(b.getIndex(33) + dong, b.getIndex(48) + dong).Merge(Missing.Value); osheet.get_Range(b.getIndex(33) + dong, b.getIndex(48) + dong).HorizontalAlignment = XlHAlign.xlHAlignCenter; osheet.get_Range(b.getIndex(49) + (dong + 1), b.getIndex(49) + dong).Merge(Missing.Value); osheet.Cells[dong, 1] = get_tenhead(0); osheet.Cells[dong, 2] = get_tenhead(1); osheet.Cells[dong, 18] = get_tenhead(2); osheet.Cells[dong, 34] = get_tenhead(3); osheet.Cells[dong, 50] = get_tenhead(4); for (int i = 1; i < socot; i++) { osheet.Cells[dong + 1, i] = get_ten(i - 1); } orange = osheet.get_Range(b.getIndex(0) + "1", b.getIndex(socot - 1) + (dong + sodong).ToString()); osheet.get_Range(b.getIndex(1) + (dong + 1), b.getIndex(socot - 3) + (dong + 1)).Orientation = 90; osheet.get_Range(b.getIndex(1) + (dong + 1), b.getIndex(socot - 2) + (dong + 1)).RowHeight = 50; orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.Cells[1, 1] = b.Syte; osheet.Cells[2, 1] = b.Tenbv; osheet.Cells[1, 4] = "TÌNH HÌNH BỆNH NHÂN NHẬP XUẤT" + loai; osheet.Cells[2, 4] = (tu.Text == den.Text)?"Ngày : " + tu.Text:"Từ ngày : " + tu.Text + " đến : " + den.Text; orange = osheet.get_Range(b.getIndex(3) + "1", b.getIndex(socot - 1) + "2"); // orange.HorizontalAlignment=XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exp_excel() { m.check_process_Excel(); dsxml.Tables[0].Columns.Remove("MAQL"); int be = 5, dong = 6, sodong = dsxml.Tables[0].Rows.Count + dong, socot = dsxml.Tables[0].Columns.Count - 1, dongke = sodong - 1; string tenfile = m.Export_Excel(dsxml, "sokhambenh"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; for (int i = 0; i < be - 1; i++) { osheet.get_Range(m.getIndex(i) + "1", m.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.get_Range(m.getIndex(0) + "4", m.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; for (int i = 0; i < 11; i++) { osheet.Cells[dong - 1, i + 1] = get_ten(i); if (i != 3 && i != 4 && i != 8 && i != 9) { orange = osheet.get_Range(m.getIndex(i) + "4", m.getIndex(i) + "5"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenter; orange.VerticalAlignment = XlHAlign.xlHAlignCenter; orange.MergeCells = true; } } osheet.Cells[dong - 2, 4] = "Tuổi"; osheet.get_Range(m.getIndex(3) + "4", m.getIndex(4) + "4").HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; osheet.Cells[dong - 2, 9] = "Chẩn đoán"; osheet.get_Range(m.getIndex(8) + "4", m.getIndex(9) + "4").HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; osheet.Cells[dong - 2, 12] = "Xử trí"; int p = 12; foreach (DataRow r in dsxt.Tables[0].Select("true", "ma")) { osheet.Cells[dong - 1, p++] = r["ten"].ToString(); } osheet.get_Range(m.getIndex(11) + "4", m.getIndex(p - 1) + "4").HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange = osheet.get_Range(m.getIndex(11) + "5", m.getIndex(p - 2) + "5"); orange.VerticalAlignment = XlVAlign.xlVAlignBottom; orange.Orientation = 90; osheet.Cells[dong - 1, p] = "Bác sỹ"; orange = osheet.get_Range(m.getIndex(p - 1) + "4", m.getIndex(p - 1) + "5"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenter; orange.VerticalAlignment = XlHAlign.xlHAlignCenter; orange.MergeCells = true; p += 1; int q = p; osheet.Cells[dong - 2, p] = "Đối tượng"; foreach (DataRow r in dsdt.Tables[0].Select("true", "ma")) { osheet.Cells[dong - 1, p++] = r["ten"].ToString(); } osheet.get_Range(m.getIndex(q - 1) + "4", m.getIndex(p - 1) + "4").HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange = osheet.get_Range(m.getIndex(q - 1) + "5", m.getIndex(p - 2) + "5"); orange.VerticalAlignment = XlVAlign.xlVAlignBottom; orange.Orientation = 90; osheet.Cells[dong - 1, p] = "Cấp cứu"; orange = osheet.get_Range(m.getIndex(p - 1) + "4", m.getIndex(p - 1) + "5"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenter; orange.VerticalAlignment = XlHAlign.xlHAlignCenter; orange.MergeCells = true; orange = osheet.get_Range(m.getIndex(0) + "4", m.getIndex(socot) + dongke.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 10; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.Cells[1, 1] = m.Syte; osheet.Cells[2, 1] = m.Tenbv; osheet.Cells[2, 4] = "SỔ KHÁM BỆNH (PHÒNG LƯU)" + ((tu.Text == den.Text)?"Ngày " + tu.Text:"Từ ngày " + tu.Text + " đến " + den.Text); orange = osheet.get_Range(m.getIndex(1) + "2", m.getIndex(socot - 1) + "3"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; oxl.Visible = true; }
private void imp_excel() { oxl = new Excel.Application(); oxl.Visible = true; owb = (Excel._Workbook)(oxl.Workbooks.Add(Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; int i, j, be = 4, k, cot = dt.Columns.Count, dong = dt.Rows.Count; string ten, tit = (maphuongxa.SelectedIndex == 1)?"TỈNH":"QUẬN"; k = (maphuongxa.SelectedIndex == 0)?2:3; DataRow r; for (i = 0; i < cot; i++) { ten = dt.Columns[i].ColumnName.ToString(); if (i > k) { r = m.getrowbyid(dstmp.Tables[0], "ma='" + ten.Substring(2) + "'"); if (r != null) { ten = r["ten"].ToString().Trim(); } } else { switch (i) { case 0: ten = "MÃ ICD"; break; case 1: ten = "TÊN BỆNH"; break; case 2: ten = "TỔNG CỘNG"; break; case 3: ten = "TS TRONG " + tit; break; } } osheet.Cells[3, i + 1] = ten; } for (i = 0; i < dong; i++) { for (j = 0; j < cot; j++) { osheet.Cells[i + be, j + 1] = dt.Rows[i][j].ToString(); } } osheet.get_Range(m.getIndex(0) + "3", m.getIndex(cot - 1) + (dong + be - 1)).Borders.LineStyle = Excel.XlLineStyle.xlContinuous; osheet.get_Range(m.getIndex(2) + "3", m.getIndex(cot) + "3").Orientation = 90; orange = osheet.get_Range(m.getIndex(0) + "3", m.getIndex(1) + "3"); orange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; orange.HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter; orange = osheet.get_Range(m.getIndex(0) + "3", m.getIndex(cot) + "3"); orange.EntireColumn.AutoFit(); orange.Font.Bold = true; dong += be; osheet.get_Range(m.getIndex(2) + dong.ToString(), m.getIndex(cot) + dong.ToString()).Font.Bold = true; osheet.Cells[1, 2] = this.Text.Trim().ToUpper(); if (tu.Text != "" && den.Text != "") { osheet.Cells[2, 2] = "Từ ngày : " + tu.Text + " đến : " + den.Text; } }
private void exp_excel(bool print) { d.check_process_Excel(); ds = dsxml.Copy(); int dong = 2, sodong = ds.Tables[0].Rows.Count + dong, socot = ds.Tables[0].Columns.Count - 1, dongke = sodong - 1; tenfile = d.Export_Excel(ds, "sudung"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; //for(int i=0;i<be;i++) osheet.get_Range(d.getIndex(i)+"1",d.getIndex(i)+"1").EntireRow.Insert(Missing.Value); osheet.get_Range(d.getIndex(3) + dong.ToString(), d.getIndex(socot + 1) + sodong.ToString()).NumberFormat = format_soluong; osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; int pos = 5, colfix = 4; if (bGia) { pos = 6; colfix = 5; } foreach (DataRow r in dtmakp.Select("", "stt,makp")) { osheet.Cells[dong - 1, pos] = r["tenkp"].ToString(); pos += 1; } for (int i = 0; i < colfix; i++) { osheet.Cells[dong - 1, i + 1] = (bGia) ? get_ten_gia(i) : get_ten(i); } // orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 10; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; // osheet.Cells[1,2]=d.Syte;osheet.Cells[2,2]=d.Tenbv; // osheet.Cells[1,4]="BÁO CÁO SỬ DỤNG NỘI TRÚ"; // osheet.Cells[2,4]=s_title; string s_title = "Từ ngày " + tu.Text + " đến ngày " + den.Text; if (tu.Text == den.Text) { s_title = "Ngày " + tu.Text; } osheet.PageSetup.LeftHeader = d.Syte + "\n" + d.Tenbv; osheet.PageSetup.CenterHeader = "&\"Arial,Bold\"&14BÁO CÁO SỬ DỤNG NỘI TRÚ\n" + s_title; // orange=osheet.get_Range(d.getIndex(3)+"1",d.getIndex(socot-1)+"2"); // orange.HorizontalAlignment=XlHAlign.xlHAlignCenterAcrossSelection; // orange.Font.Size=12; // orange.Font.Bold=true; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } }
private void exp_excel_eee(bool print) { try { d.check_process_Excel(); int be = 3, cot = ds.Tables[0].Columns.Count, dong = ds.Tables[0].Rows.Count + be + 2; tenfile = d.Export_Excel(ds, "TONGHOP"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; for (int i = 0; i < be; i++) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } for (int i = 0; i < 4; i++) { osheet.Cells[be + 1, i + 1] = get_ten(i); } DataRow [] dr = dsmabd.Tables[0].Select("true", "tenbd"); for (int i = 0; i < dr.Length; i++) { osheet.Cells[be + 1, i + 4] = dr[i]["tenbd"].ToString(); osheet.Cells[dong, i + 4] = dr[i]["soluong"].ToString(); } orange = osheet.get_Range(d.getIndex(be) + "4", d.getIndex(cot - 1) + "4"); orange.VerticalAlignment = XlVAlign.xlVAlignBottom; orange.Orientation = 90; orange.RowHeight = 200; orange.EntireRow.AutoFit(); orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(cot - 1) + dong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 10; orange.Font.Bold = false; osheet.get_Range(d.getIndex(0) + "4", d.getIndex(cot - 1) + dong.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; //orange.EntireRow.AutoFit(); orange.EntireColumn.AutoFit(); osheet.get_Range(d.getIndex(3) + dong.ToString(), d.getIndex(cot - 1) + dong.ToString()).Font.Bold = true; oxl.ActiveWindow.DisplayZeros = false; osheet.Cells[1, 2] = ""; //makp.Text; osheet.Cells[2, 3] = (tu.Text == den.Text)?"Ngày " + tu.Text:"Ngày " + tu.Text + " - " + den.Text; osheet.Cells[1, 3] = "TỔNG HỢP SỬ DỤNG THUỐC"; orange = osheet.get_Range(d.getIndex(2) + "1", d.getIndex(cot - 1) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exp_excel(bool print) { try { DataSet tmp = new DataSet(); tmp = ds.Copy(); ds.Clear(); ds.Merge(tmp.Tables[0].Select("true", "ten,dang")); int k = 1; foreach (DataRow r in ds.Tables[0].Rows) { r["stt"] = k++; } int be = 5, dong = 7, sodong = ds.Tables[0].Rows.Count + 6, socot = ds.Tables[0].Columns.Count - 1, dongke = sodong; tenfile = d.Export_Excel(ds, "bcngay"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; osheet.get_Range(d.getIndex(0) + "1", d.getIndex(0) + "1").EntireColumn.Delete(Missing.Value); for (int i = 0; i < be; i++) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.get_Range(d.getIndex(be) + dong.ToString(), d.getIndex(socot) + sodong.ToString()).NumberFormat = "#,##0.00"; osheet.get_Range(d.getIndex(0) + "5", d.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; for (int i = 1; i < dong - 2; i++) { osheet.Cells[dong - 1, i] = get_ten(i - 1); } orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot + 7) + (sodong + 7).ToString()); osheet.Cells[dong - 1, dsngay.Tables[0].Rows.Count + 5] = "Tổng cộng"; osheet.Cells[dong - 1, dsngay.Tables[0].Rows.Count + 6] = "Ghi Chú"; for (int i = 0; i < dsngay.Tables[0].Rows.Count; i++) { osheet.Cells[dong - 1, i + 5] = " " + dsngay.Tables[0].Rows[i]["ten"].ToString(); } osheet.get_Range(d.getIndex(4) + "6", d.getIndex(dsngay.Tables[0].Rows.Count + 3) + "6").Orientation = 90; osheet.get_Range(d.getIndex(0) + "6", d.getIndex(dsngay.Tables[0].Rows.Count + 3) + "6").RowHeight = 30; orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.Cells[1, 2] = d.Syte; osheet.Cells[2, 2] = d.Tenbv; osheet.Cells[3, 2] = "Khoa: " + makp.Text; osheet.Cells[1, socot] = "MS: 16D/BV-01"; osheet.Cells[2, socot] = "Số:"; orange = osheet.get_Range(osheet.Cells[1, socot], osheet.Cells[2, socot]); orange.Font.Bold = false; orange.HorizontalAlignment = XlHAlign.xlHAlignLeft; orange = osheet.get_Range(osheet.Cells[dong - 1, 1], osheet.Cells[dong - 1, dsngay.Tables[0].Rows.Count + 6]); orange.Font.Bold = true; orange = osheet.get_Range(d.getIndex(1) + "5", d.getIndex(1) + "6"); orange.Merge(Type.Missing); //excelApp.get_Range("A1:A360,B1:E1", Type.Missing).Merge(Type.Missing) orange = osheet.get_Range(d.getIndex(2) + "5", d.getIndex(2) + "6"); orange.Merge(Type.Missing); orange = osheet.get_Range(d.getIndex(3) + "5", d.getIndex(3) + "6"); orange.Merge(Type.Missing); orange = osheet.get_Range(d.getIndex(0) + "5", d.getIndex(0) + "6"); orange.Merge(Type.Missing); orange = osheet.get_Range(d.getIndex(socot) + "5", d.getIndex(socot) + "6"); orange.Merge(Type.Missing); orange = osheet.get_Range(d.getIndex(socot - 1) + "5", d.getIndex(socot - 1) + "6"); orange.Merge(Type.Missing); orange = osheet.get_Range(d.getIndex(4) + "5", d.getIndex(socot - 2) + "5"); orange.Merge(Type.Missing); orange.HorizontalAlignment = XlHAlign.xlHAlignCenter; osheet.Cells[5, 5] = "Ngày"; osheet.get_Range(d.getIndex(0) + "7", d.getIndex(socot) + "7").EntireRow.Insert(Missing.Value); osheet.Cells[7, 1] = "A"; osheet.Cells[7, 2] = "B"; osheet.Cells[7, 3] = "C"; osheet.Cells[7, 4] = "D"; osheet.Cells[7, socot] = "E"; osheet.Cells[7, socot + 1] = "G"; orange = osheet.get_Range(d.getIndex(0) + "7", d.getIndex(socot + 2) + "7"); string s_ngay = d.Ngay_hethong; osheet.Cells[sodong + 3, 2] = "NGƯỜI THỐNG KÊ"; osheet.Cells[sodong + 3, 6] = "KẾ TOÁN DƯỢC"; osheet.Cells[sodong + 3, 19] = "Ngày " + s_ngay.Substring(0, 2) + " tháng " + s_ngay.Substring(3, 2) + " năm " + s_ngay.Substring(6, 4); osheet.Cells[sodong + 4, 19] = "TRƯỞNG KHOA " + makp.Text.ToUpper(); osheet.Cells[sodong + 7, 2] = "Họ tên: "; osheet.Cells[sodong + 7, 6] = "Họ tên: "; osheet.Cells[sodong + 8, 19] = "Họ tên: "; orange = osheet.get_Range(osheet.Cells[sodong + 3, 2], osheet.Cells[sodong + 4, 20]); orange.Font.Bold = true; //orange.HorizontalAlignment = XlHAlign.xlHAlignCenter; orange.Orientation = 0; //osheet.Cells[1,4]="BÁO CÁO SỬ DỤNG"; osheet.Cells[1, 4] = "THỐNG KÊ " + dsngay.Tables[0].Rows.Count.ToString() + " NGÀY SỬ DỤNG THUỐC, HÓA CHẤT,\n VẬT TƯ Y TẾ TIÊU HAO"; osheet.Cells[2, 4] = (tu.Text == den.Text)?"Ngày : " + tu.Text:"Từ ngày : " + tu.Text + " đến : " + den.Text; orange = osheet.get_Range(d.getIndex(3) + "1", d.getIndex(socot - 2) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exp_excel(bool print, bool biendong) { try { int be = 3, dong = 5, sodong = ds.Tables[0].Rows.Count + 5, socot = ds.Tables[0].Columns.Count - 2, dongke = sodong - 1; tenfile = ttb.Export_Excel(ds, "theodoigia"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; osheet.get_Range(ttb.getIndex(0) + "1", ttb.getIndex(0) + "1").EntireColumn.Delete(Missing.Value); for (int i = 0; i < be; i++) { osheet.get_Range(ttb.getIndex(i) + "1", ttb.getIndex(i) + "1").EntireRow.Insert(Missing.Value); } osheet.get_Range(ttb.getIndex(be) + dong.ToString(), ttb.getIndex(socot + 1) + sodong.ToString()).NumberFormat = "#,##0.000"; osheet.get_Range(ttb.getIndex(0) + "4", ttb.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; for (int i = 1; i < dong; i++) { osheet.Cells[dong - 1, i] = get_ten(i - 1); } orange = osheet.get_Range(ttb.getIndex(0) + "1", ttb.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.Cells[1, 2] = ttb.Syte; osheet.Cells[2, 2] = ttb.Tenbv; s_mmyy = tu.Value.ToString().PadLeft(2, '0') + yyyy.Value.ToString().PadLeft(4, '0').Substring(2, 2); s_tu = tu.Value.ToString().PadLeft(2, '0'); s_den = den.Value.ToString().PadLeft(2, '0'); s_yy = yyyy.Value.ToString().PadLeft(4, '0').Substring(2, 2); osheet.Cells[1, 4] = "THEO DÕI BIẾN ĐỘNG GIÁ"; osheet.Cells[2, 4] = (tu.Value == den.Value && yy.Value == yyyy.Value)?"Tháng : " + s_tu + "/" + yyyy.Value.ToString():"Từ tháng :" + s_tu + "/" + yy.Value.ToString() + " đến tháng :" + s_den + "/" + yyyy.Value.ToString(); orange = osheet.get_Range(ttb.getIndex(3) + "1", ttb.getIndex(socot - 1) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; osheet.get_Range(ttb.getIndex(4) + "4", ttb.getIndex(ds.Tables[0].Columns.Count) + "4").NumberFormat = "@"; osheet.get_Range(ttb.getIndex(4) + "4", ttb.getIndex(ds.Tables[0].Columns.Count) + "4").RowHeight = 24; if (!biendong) { for (int i = 0; i < dtngay.Rows.Count; i++) { osheet.Cells[dong - 1, i + 5] = dtngay.Rows[i]["ngaydoi"].ToString(); } } else { osheet.Cells[dong - 1, 5] = s_tu + "/" + yy.Value.ToString(); if (s_tu != s_den) { osheet.Cells[dong - 1, 6] = s_den + "/" + yyyy.Value.ToString(); osheet.Cells[dong - 1, 7] = "Chênh lệch"; } } orange = osheet.get_Range(ttb.getIndex(4) + "5", ttb.getIndex(socot + 1) + sodong.ToString()); orange.EntireColumn.AutoFit(); if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exp_excel(bool print) { d.check_process_Excel(); try { int be = 3, dong = 5, sodong = dsxml.Tables[0].Rows.Count + 5, socot = dsxml.Tables[0].Columns.Count - 1, dongke = sodong; tenfile = d.Export_Excel(dsxml, "bccpkcb"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value));//,Missing.Value,Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; for (int i = 0; i < be; i++) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value); //,Missing.Value); } osheet.get_Range(d.getIndex(i_cot) + dong.ToString(), d.getIndex(socot) + sodong.ToString()).NumberFormat = "#,##0.00"; osheet.get_Range(d.getIndex(0) + "4", d.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; for (int i = 0; i < i_cot; i++) { osheet.Cells[dong - 1, i + 1] = get_ten(i).ToString(); } osheet.Cells[dong - 1, socot + 1] = "TỔNG CỘNG"; osheet.Cells[sodong, i_cot - 1] = "TỔNG CỘNG"; orange = osheet.get_Range(d.getIndex(0) + "4", d.getIndex(1) + "4"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Bold = true; int so = sodong, j = 1; decimal tc = 0; foreach (DataRow r in dtnhomvp.Select("true", "stt")) { osheet.Cells[dong - 1, j + i_cot] = r["ten"].ToString(); orange = osheet.get_Range(d.getIndex(j + i_cot) + "3", d.getIndex(j + i_cot) + "3"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Bold = true; osheet.Cells[sodong, j + i_cot] = r["tc"].ToString(); osheet.get_Range(d.getIndex(j + i_cot - 1) + so.ToString(), d.getIndex(j + i_cot - 1) + so.ToString()).Font.Bold = true; tc += decimal.Parse(r["tc"].ToString()); j++; } osheet.Cells[sodong, socot + 1] = tc; osheet.get_Range(d.getIndex(socot) + so.ToString(), d.getIndex(socot) + so.ToString()).Font.Bold = true; orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Arial"; orange.Font.Size = 8; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; osheet.Cells[1, 1] = d.Syte; osheet.Cells[2, 1] = d.Tenbv; orange = osheet.get_Range(d.getIndex(1) + "1", d.getIndex(3) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; osheet.Cells[1, 3] = "BÁO CÁO CHI PHÍ KHÁM CHỮA BỆNH " + madoituong.Text.Trim().ToUpper() + " NGỌAI TRÚ"; osheet.Cells[2, 3] = (tu.Text == den.Text)?"Ngày : " + tu.Text:"Từ ngày :" + tu.Text + " đến ngày :" + den.Text; orange = osheet.get_Range(d.getIndex(2) + "1", d.getIndex(socot) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void load_grid() { if (loai.SelectedIndex == -1) { loai.Focus(); return; } if (tu.Text == "" || den.Text == "") { if (tu.Text == "") { tu.Focus(); } else { den.Focus(); } return; } ds.Clear(); songay = 7; sql = "select a.mabn,a.hoten,sum(b.soluong*b.dongia-b.mien-b.thieu-b.tra) as sotien"; sql += " from xxx.v_vienphill a inner join xxx.v_vienphict b on a.id=b.id "; sql += " inner join " + user + ".v_giavp c on b.mavp=c.id "; sql += " inner join " + user + ".v_loaivp d on c.id_loai=d.id "; sql += " inner join " + user + ".v_nhomvp e on d.id_nhom=e.ma "; sql += " where b.soluong*b.dongia-b.mien-b.thieu-b.tra>0 "; sql += " and a.ngay between to_date('" + tu.Text + "'," + stime + ") and to_date('" + den.Text + "'," + stime + ")"; sql += " and d.id=" + decimal.Parse(dtloai.Rows[loai.SelectedIndex]["nhomvp"].ToString()); sql += " group by a.mabn,a.hoten"; sql += " order by a.mabn,a.hoten"; dsvp = m.get_data_mmyy(sql, tu.Text, den.Text, false); sql = "select a.mabn,f.hoten,sum(a.lt) as lt,sum(a.cp) as cp,000000000000.00 as vp"; sql += " from xxx.cls_ketqua a inner join " + user + ".btdbn b on a.mabn=b.mabn "; sql += " inner join " + user + ".cls_loai c on a.loai=c.id "; sql += " left join " + user + ".cls_may d on a.idmay=d.id"; sql += " left join " + user + ".cls_noidung e on a.idvung=e.id"; sql += " left join " + user + ".btdbn f on a.mabn=f.mabn"; sql += " left join " + user + ".dmbs g on a.mabs=g.ma"; sql += " left join xxx.cls_motact h on a.id=h.id "; sql += " where " + m.for_ngay("a.ngay", stime) + " between to_date('" + tu.Text + "'," + stime + ") and to_date('" + den.Text + "'," + stime + ")"; if (loai.SelectedIndex != -1) { sql += " and a.loai=" + int.Parse(loai.SelectedValue.ToString()); } if (s_trasau != "") { sql += " and a.madoituong not in (" + s_trasau.Substring(0, s_trasau.Length - 1) + ")"; } if (s_mien != "") { sql += " and a.madoituong not in (" + s_mien.Substring(0, s_mien.Length - 1) + ")"; } sql += " group by a.mabn,f.hoten"; sql += " order by a.mabn,f.hoten"; DataSet dstmp = m.get_data_mmyy(sql, tu.Text, den.Text, false); ds = dstmp.Copy(); ds.Clear(); if (dstmp.Tables[0].Rows.Count == 0) { MessageBox.Show(lan.Change_language_MessageText("Không có số liệu !"), LibMedi.AccessData.Msg); } else { DataRow r1, r2; DataRow[] dr; foreach (DataRow r in dstmp.Tables[0].Rows) { r1 = m.getrowbyid(ds.Tables[0], "mabn='" + r["mabn"].ToString() + "'"); if (r1 == null) { r2 = ds.Tables[0].NewRow(); r2["mabn"] = r["mabn"].ToString(); r2["hoten"] = r["hoten"].ToString(); r2["cp"] = r["cp"].ToString(); r2["lt"] = r["lt"].ToString(); r2["vp"] = 0; foreach (DataRow r3 in dsvp.Tables[0].Select("mabn='" + r["mabn"].ToString() + "'")) { r2["vp"] = decimal.Parse(r2["vp"].ToString()) + decimal.Parse(r3["sotien"].ToString()); } ds.Tables[0].Rows.Add(r2); } else { dr = ds.Tables[0].Select("mabn='" + r["mabn"].ToString() + "'"); if (dr.Length > 0) { dr[0]["cp"] = decimal.Parse(dr[0]["cp"].ToString()) + decimal.Parse(r["cp"].ToString()); dr[0]["lt"] = decimal.Parse(dr[0]["lt"].ToString()) + decimal.Parse(r["lt"].ToString()); } } } foreach (DataRow r in dsvp.Tables[0].Rows) { r1 = m.getrowbyid(ds.Tables[0], "mabn='" + r["mabn"].ToString() + "'"); if (r1 == null) { r2 = ds.Tables[0].NewRow(); r2["mabn"] = r["mabn"].ToString(); r2["hoten"] = r["hoten"].ToString(); r2["cp"] = 0; r2["lt"] = 0; r2["vp"] = 0; foreach (DataRow r3 in dsvp.Tables[0].Select("mabn='" + r["mabn"].ToString() + "'")) { r2["vp"] = decimal.Parse(r2["vp"].ToString()) + decimal.Parse(r3["sotien"].ToString()); } ds.Tables[0].Rows.Add(r2); } } if (rb2.Checked) { dstmp.Clear(); dstmp = ds.Copy(); ds.Clear(); ds.Merge(dstmp.Tables[0].Select("cp<>vp", "mabn")); } m.check_process_Excel(); string tenfile = m.Export_Excel(ds, "doichieu"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; oxl.ActiveWindow.DisplayZeros = false; for (int i = 0; i < 5; i++) { osheet.Cells[1, i + 1] = get_ten(i); } int socot = ds.Tables[0].Rows.Count + 1; osheet.get_Range(m.getIndex(0) + "1", m.getIndex(ds.Tables[0].Columns.Count - 1) + socot.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; oxl.Visible = true; } }
/// <summary> /// �ͷ��ڴ�ռ� /// </summary> public void Dispose() { try { System.Runtime.InteropServices.Marshal.ReleaseComObject(CurSheet); CurSheet = null; CurBook.Close(false, mValue, mValue); System.Runtime.InteropServices.Marshal.ReleaseComObject(CurBook); CurBook = null; CurExcel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(CurExcel); CurExcel = null; GC.Collect(); GC.WaitForPendingFinalizers(); } catch (System.Exception) { // MessageBox.Show("���ͷ�Excel�ڴ�ռ�ʱ������һ������"+ex.Message); } finally { //foreach (System.Diagnostics.Process pro in System.Diagnostics.Process.GetProcessesByName("Excel")) // if (pro.StartTime > this.dtBefore && pro.StartTime < this.dtAfter) // { // try // { // pro.Kill(); // } // catch { } // } } System.GC.SuppressFinalize(this); }
private void exp_excel(System.Data.DataTable dts) { if (d.check_open_Excel() == true) { DialogResult dlg = MessageBox.Show("Bạn phải tắt các chương trình Excel đang chạy trước khi tổng hợp.\nBạn có muốn tự động tắt luôn không?", "Export to Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (dlg == DialogResult.Yes) { d.check_process_Excel(); } else { return; } } d.check_process_Excel(); try { System.Data.DataTable dtxml = dts; int be = 9, i_cot = 22, dong = 10, sodong = dtxml.Rows.Count + 10, socot = dtxml.Columns.Count - 1, dongke = sodong + 2; string tenfile = d.Export_Excel(dtxml, s_tenreport); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value));//,Missing.Value,Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; for (int i = 0; i < be; i++) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value); //,Missing.Value); } osheet.get_Range(d.getIndex(9) + dong.ToString(), d.getIndex(socot - 5) + dongke.ToString()).NumberFormat = "#,##0"; osheet.get_Range(d.getIndex(0) + "7", d.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; //dong ten cot for (int i = 0; i < i_cot; i++) { osheet.Cells[dong - 1, i + 1] = getTencot(i).ToString(); } orange = osheet.get_Range(d.getIndex(0) + "9", d.getIndex(i_cot - 1) + "9"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Bold = true; //end dong ten cot //dong stt for (int i = 0; i < i_cot; i++) { osheet.Cells[dong, i + 1] = getSTT(i).ToString(); } orange = osheet.get_Range(d.getIndex(0) + "10", d.getIndex(i_cot - 1) + "10"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Bold = true; //end dong stt int so = sodong, j = 0; //Tinh tong osheet.Cells[sodong + 1, 2] = "Tổng cộng A + B + C"; for (int k = 21; k <= 21; k++) { osheet.Cells[sodong + 1, k] = "=SUM(" + d.getIndex(k - 1) + "9:" + d.getIndex(k - 1) + (sodong).ToString() + ")"; } orange = osheet.get_Range(d.getIndex(0) + (sodong + 1).ToString(), d.getIndex(socot) + (sodong + 1).ToString()); orange.HorizontalAlignment = XlHAlign.xlHAlignRight; orange.Font.Bold = true; //end dong tong //tieu de osheet.Cells[1, 1] = "Tên cơ sở khám, chữa bệnh: BỆNH VIỆN NHÂN DÂN 115"; orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(3) + "1"); orange.MergeCells = true; osheet.Cells[2, 1] = "Mã số: 79024"; orange = osheet.get_Range(d.getIndex(0) + "2", d.getIndex(3) + "2"); orange.MergeCells = true; //s_tenBaoCao = "THỐNG KÊ DỊCH VỤ KỸ THUẬT THANH TOÁN BHYT "; osheet.Cells[2, socot - 6] = s_tenBaoCao; s_tieuDeExcel = "THỐNG KÊ DỊCH VỤ KỸ THUẬT THANH TOÁN BHYT "; osheet.Cells[3, 4] = s_tieuDeExcel; orange = osheet.get_Range(d.getIndex(3) + "3", d.getIndex(socot - 5) + "3"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 16; orange.Font.Bold = true; string s_title = haison1.s_title; osheet.Cells[4, 4] = s_title; orange = osheet.get_Range(d.getIndex(3) + "4", d.getIndex(socot - 5) + "4"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 10; orange.Font.Bold = true; osheet.Cells[5, 4] = "(Gửi cùng với file dữ liệu hàng tháng)"; orange = osheet.get_Range(d.getIndex(3) + "5", d.getIndex(socot - 5) + "5"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; osheet.Cells[6, socot - 6] = "Đơn vị : đồng"; //end tieu de //format cột osheet.Cells[7, 2] = "Thông tin về kết quả trúng thầu cơ sở KCB áp dụng để mua sắm"; orange = osheet.get_Range(d.getIndex(1) + "7", d.getIndex(4) + "7"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.MergeCells = true; orange.Font.Bold = true; osheet.Cells[7, 19] = "Số lượng"; orange = osheet.get_Range(d.getIndex(18) + "7", d.getIndex(19) + "7"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.MergeCells = true; orange.Font.Bold = true; /* * osheet.Cells[7, 10] = "TỔNG CHI PHÍ KHÁM, CHỮA BỆNH BHYT"; * orange = osheet.get_Range(d.getIndex(9) + "7", d.getIndex(20) + "7"); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * orange.Font.Bold = true; * * osheet.Cells[7, 23] = "Đề nghị BHXH thanh toán "; * orange = osheet.get_Range(d.getIndex(22) + "7", d.getIndex(23) + "7"); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * orange.Font.Bold = true; * * osheet.Cells[8, 11] = "Không áp dụng tỷ lệ thanh toán"; * orange = osheet.get_Range(d.getIndex(10) + "8", d.getIndex(15) + "8"); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * orange.Font.Bold = true; * * osheet.Cells[8, 17] = "Thanh toán theo tỷ lệ"; * orange = osheet.get_Range(d.getIndex(16) + "8", d.getIndex(18) + "8"); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * orange.Font.Bold = true;*/ //megre cot for (int i = 0; i < i_cot; i++) { if ((i > 0 && i < 5) || (i > 17 && i < 20)) { orange = osheet.get_Range(d.getIndex(i) + "8", d.getIndex(i) + "9"); orange.MergeCells = true; } else { orange = osheet.get_Range(d.getIndex(i) + "7", d.getIndex(i) + "9"); orange.MergeCells = true; } }/* * //end * //end format cột * * //footer * osheet.Cells[sodong + 2, 1] = "Số tiền đề nghị thanh toán (viết bằng chữ) ";// +data.doiTienThanhSo(t_deNghiThanhToan); * orange = osheet.get_Range(d.getIndex(0) + (sodong + 2), d.getIndex(socot - 1) + (sodong + 2)); * orange.MergeCells = true; * * osheet.Cells[sodong + 5, 2] = "Người lập biểu"; * orange = osheet.get_Range(d.getIndex(1) + (sodong + 5), d.getIndex(2) + (sodong + 5)); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * * osheet.Cells[sodong + 6, 2] = "(Ký, họ tên)"; * orange = osheet.get_Range(d.getIndex(1) + (sodong + 6), d.getIndex(2) + (sodong + 6)); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * orange.Font.Italic = true; * * osheet.Cells[sodong + 5, 7] = "Trưởng phòng KHTH"; * orange = osheet.get_Range(d.getIndex(6) + (sodong + 5), d.getIndex(8) + (sodong + 5)); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * * osheet.Cells[sodong + 6, 7] = "(Ký, họ tên)"; * orange = osheet.get_Range(d.getIndex(6) + (sodong + 6), d.getIndex(8) + (sodong + 6)); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * orange.Font.Italic = true; * * /* osheet.Cells[sodong + 5, 15] = "Kế toán trưởng"; * orange = osheet.get_Range(d.getIndex(14) + (sodong + 5), d.getIndex(15) + (sodong + 5)); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * * osheet.Cells[sodong + 6, 15] = "(Ký, họ tên)"; * orange = osheet.get_Range(d.getIndex(14) + (sodong + 6), d.getIndex(15) + (sodong + 6)); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * orange.Font.Italic = true; * * osheet.Cells[sodong + 4, 20] = "....., ngày.....tháng....năm...."; * orange = osheet.get_Range(d.getIndex(18) + (sodong + 4), d.getIndex(21) + (sodong + 4)); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * orange.Font.Italic = true; * * osheet.Cells[sodong + 5, 20] = "Thủ trưởng đơn vị"; * orange = osheet.get_Range(d.getIndex(19) + (sodong + 5), d.getIndex(20) + (sodong + 5)); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * * osheet.Cells[sodong + 6, 20] = "(Ký, họ tên, đóng dấu)"; * orange = osheet.get_Range(d.getIndex(19) + (sodong + 6), d.getIndex(20) + (sodong + 6)); * orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; * orange.MergeCells = true; * orange.Font.Italic = true; * * orange = osheet.get_Range(d.getIndex(0) + (sodong + 3), d.getIndex(socot - 1) + (sodong + 5)); * orange.Font.Bold = true;*/ //format chung orange = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString()); orange.Font.Name = "Times New Roman"; orange.EntireColumn.AutoFit(); oxl.ActiveWindow.DisplayZeros = false; orange = osheet.get_Range(d.getIndex(0) + "7", d.getIndex(socot) + sodong.ToString()); orange.Font.Size = 8; osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = XlPaperSize.xlPaperA4; osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; //end // orange = osheet.get_Range(d.getIndex(socot - 7) + "6", d.getIndex(socot - 7) + "6"); // if (print) osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); // else oxl.Visible = true; //end format chung } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void OpenExcelApp(bool visible) { _excelApplication = new Excel.Application(); _excelApplication.Visible = visible; _workBooks = (Excel.Workbooks)_excelApplication.Workbooks; _workBook = (Excel._Workbook)(_workBooks.Add(_value)); _excelSheets = (Excel.Sheets)_workBook.Worksheets; _excelSheet = (Excel._Worksheet)(_excelSheets.get_Item(1)); }
private void butIn_Click(object sender, System.EventArgs e) { d.check_process_Excel(); #region DataSet dsxml = new DataSet(); dsxml = ds.Copy(); dsxml.Clear(); DataRow r2; int stt = 0, tt = 1; sql = "manhom,tenbd"; DataRow [] dr = ds.Tables[0].Select("true", sql); for (int i = 0; i < dr.Length; i++) { if (stt != int.Parse(dr[i]["manhom"].ToString())) { stt = int.Parse(dr[i]["manhom"].ToString()); r2 = dsxml.Tables[0].NewRow(); r2["stt"] = 0; r2["tenbd"] = dr[i]["tennhom"].ToString().ToUpper(); r2["dang"] = ""; r2["tc"] = 0; foreach (DataRow r3 in dtkho.Rows) { r2["c_" + r3["id"].ToString().PadLeft(3, '0')] = 0; } dsxml.Tables[0].Rows.Add(r2); } r2 = dsxml.Tables[0].NewRow(); r2["stt"] = tt; r2["tenbd"] = dr[i]["tenbd"].ToString(); r2["dang"] = dr[i]["dang"].ToString(); foreach (DataRow r3 in dtkho.Rows) { r2["c_" + r3["id"].ToString().PadLeft(3, '0')] = dr[i]["c_" + r3["id"].ToString().PadLeft(3, '0')]; } r2["tc"] = dr[i]["tc"].ToString(); dsxml.Tables[0].Rows.Add(r2); tt++; } dsxml.Tables[0].Columns.Remove("manhom"); dsxml.Tables[0].Columns.Remove("tennhom"); dsxml.Tables[0].Columns.Remove("mabd"); dsxml.Tables[0].Columns.Remove("manguon"); dsxml.Tables[0].Columns.Remove("tennguon"); dsxml.Tables[0].Columns.Remove("ma"); dsxml.Tables[0].Columns.Remove("tenhc"); #endregion int be = 0; int dong = dsxml.Tables[0].Rows.Count + be + 1, socot = dsxml.Tables[0].Columns.Count + 1; string tenfile = d.Export_Excel(dsxml, "tonkho"); oxl = new Excel.Application(); owb = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; oxl.ActiveWindow.DisplayZeros = false; int j = 0; for (; j < 4; j++) { osheet.Cells[be + 1, j + 1] = get_ten(j); } foreach (DataRow r in dtkho.Rows) { osheet.Cells[be + 1, ++j] = r["ten"].ToString(); } osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot - 2) + dong.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot - 2) + dong.ToString()).EntireColumn.AutoFit(); oxl.Visible = true; }
public void OpenExcelAppWithFile(string filePath, int sheetIndex, string sheetName, bool visible) { _excelApplication = new Excel.Application(); _excelApplication.Visible = visible; _workBooks = (Excel.Workbooks)_excelApplication.Workbooks; _workBook = (Excel._Workbook)(_workBooks.Add(filePath)); _excelSheets = (Excel.Sheets)_workBook.Worksheets; _excelSheet = (Excel._Worksheet)(_excelSheets.get_Item(sheetIndex)); _excelSheet.Name = sheetName; }