/// <summary> /// 利用Excel的QueryTable导出数据 /// </summary> /// <param name="intSheetNumber">导出第几个sheet</param> /// <param name="blIsMoreThan">余下的数据是否大于指定的每个Sheet的最大记录数</param> /// <param name="strTitle">表头,需与查询sql语句对齐一致。</param> /// <param name="strSql">查询的sql语句,表头的文字需与该sql语句对齐一致。</param> /// <param name="strTablName">查询的表名</param> /// <param name="strMastTitle">主标题</param> /// </summary> public void ExportDataByQueryTable(int intSheetNumber, bool blIsMoreThan, string[] strTitle, string strSql, string strTablName, string strMastTitle) { string strQuery = string.Empty; if (blIsMoreThan) { strQuery = "Select Top " + this.dbSheetSize + strSql + " From " + strTablName + " Where Not OrderID In (Select Top " + dbSheetSize * (intSheetNumber - 1) + " OrderID From " + strTablName + ")"; } else { strQuery = "Select Top " + this.dbSheetSize + strSql + " From " + strTablName; } m_objSheet = (Excel._Worksheet)(m_objSheets.get_Item(intSheetNumber)); m_objSheet.Cells[1, 1] = strMastTitle; m_objSheet.Cells[2, 1] = "打印日期" + DateTime.Now.ToShortDateString(); for (int i = 1; i <= strTitle.Length; i++) { m_objSheet.Cells[4, i] = strTitle[i - 1].ToString(); } m_objRange = m_objSheet.get_Range("A5", m_objOpt); m_objQryTable = m_objSheet.QueryTables.Add("OLEDB;Provider=SQLOLEDB.1;" + sqlConn.ConnectionString, m_objRange, strQuery); m_objQryTable.RefreshStyle = Excel.XlCellInsertionMode.xlInsertEntireRows; m_objQryTable.FieldNames = false; m_objQryTable.Refresh(false); }
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 { int be = 3, dong = 5, sodong = ds.Tables[0].Rows.Count + 5, socot = ds.Tables[0].Columns.Count - 2, dongke = sodong - 1; 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 + 1) + sodong.ToString()).NumberFormat = "#,##0.00"; osheet.get_Range(d.getIndex(0) + "4", d.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(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString()); osheet.Cells[dong - 1, dsngay.Tables[0].Rows.Count + 5] = "Cộng"; osheet.Cells[dong - 1, dsngay.Tables[0].Rows.Count + 6] = "Tổng trả"; 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) + "4", d.getIndex(dsngay.Tables[0].Rows.Count + 5) + "4").Orientation = 90; osheet.get_Range(d.getIndex(0) + "4", d.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] = d.Syte; osheet.Cells[2, 2] = d.Tenbv; osheet.Cells[1, 4] = "BÁO CÁO SỬ DỤNG"; string s_title = (tu.Text == den.Text)?"Ngày : " + tu.Text:"Từ ngày : " + tu.Text + " đến : " + den.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; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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 { 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 { 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 = d.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(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 + 1) + sodong.ToString()).NumberFormat = "#,##0.000"; osheet.get_Range(d.getIndex(0) + "4", d.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(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; 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(d.getIndex(3) + "1", d.getIndex(socot - 1) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; osheet.get_Range(d.getIndex(4) + "4", d.getIndex(ds.Tables[0].Columns.Count) + "4").NumberFormat = "@"; osheet.get_Range(d.getIndex(4) + "4", d.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(d.getIndex(4) + "5", d.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) { 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 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; }
private void exp_excel() { try { int be = 21, dong = 23, sodong = ds.Tables[0].Rows.Count + 24, socot = ds.Tables[0].Columns.Count - 2, dongke = sodong - 1; tenfile = ttb.Export_Excel(ds, "bbthanhly"); 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(1) + "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(5) + dong.ToString(), ttb.getIndex(socot) + sodong.ToString()).NumberFormat = "#,##0.00"; osheet.get_Range(ttb.getIndex(0) + "21", ttb.getIndex(socot - 1) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline; for (int i = 1; i < 6; i++) { osheet.Cells[dong - 1, i] = get_title(i - 1); orange = osheet.get_Range(ttb.getIndex(i - 1) + "21", ttb.getIndex(i - 1) + "22"); orange.MergeCells = true; } for (int i = 0; i < dtkho.Rows.Count; i++) { osheet.Cells[dong - 1, i + 6] = dtkho.Rows[i]["ten"].ToString(); } i_rec = dtkho.Rows.Count; for (int i = 5; i < 9; i++) { osheet.Cells[dong - 1, i + i_rec + 1] = get_title(i); } for (int i = 6 + i_rec; i < 6 + i_rec + 3; i++) { orange = osheet.get_Range(ttb.getIndex(i) + "21", ttb.getIndex(i) + "22"); orange.MergeCells = true; } osheet.Cells[dong - 2, 6] = "Số lượng"; orange = osheet.get_Range(ttb.getIndex(5) + "21", ttb.getIndex(i_rec + 5) + "21"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Bold = true; orange = osheet.get_Range(ttb.getIndex(0) + dong.ToString(), 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, 1] = ttb.Syte; osheet.Cells[2, 1] = ttb.Tenbv; osheet.Cells[1, 3] = "BIÊN BẢN THANH LÝ,HỦY"; osheet.Cells[2, 3] = ngay; for (int i = 0; i < 16; i++) { osheet.Cells[i + 4, 2] = get_ten(i); } for (int i = 0; i < 12; i++) { osheet.Cells[i + 6, 7] = get_chucdanh(i); } orange = osheet.get_Range(ttb.getIndex(2) + "1", ttb.getIndex(socot - 1) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; osheet.Cells[sodong - 1, 2] = "Tổng số tiền :"; osheet.Cells[sodong - 1, 5 + i_rec + 3] = tongcong; string s = doiso.Doiso_Unicode(ds.Tables[0].Rows.Count.ToString()).Trim(); osheet.Cells[sodong + 1, 2] = "Tổng số :" + s.Substring(0, s.Length - 4) + " khoản"; osheet.Cells[sodong + 2, 2] = "Số tiền :" + doiso.Doiso_Unicode(Convert.ToInt64(tongcong).ToString()); int so1 = sodong + 4, so2 = sodong + 5; osheet.Cells[sodong + 4, 3] = "HỘI ĐỒNG THANH LÝ"; osheet.Cells[sodong + 5, 3] = "(Ký)"; orange = osheet.get_Range(ttb.getIndex(2) + so1.ToString(), ttb.getIndex(7) + so2.ToString()); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; so1 = sodong - 1; orange = osheet.get_Range(ttb.getIndex(1) + so1.ToString(), ttb.getIndex(socot) + so2.ToString()); orange.Font.Bold = true; for (int i = sodong + 6; i < sodong + 6 + 12; i++) { osheet.Cells[i, 2] = get_ten(i - sodong - 4); } for (int i = sodong + 6; i < sodong + 6 + 12; i++) { osheet.Cells[i, 7] = get_chucdanh(i - sodong - 6); } oxl.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exp_excel(bool print) { try { ds.Tables[0].Columns.Remove("DOITUONG");//KHUYEN 07/03/14 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, "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 < 6; i++) { osheet.Cells[be + 1, i + 1] = get_ten(i); } for (int i = 0; i < dsmabd.Tables[0].Rows.Count; i++) { osheet.Cells[be + 1, i + 7] = dsmabd.Tables[0].Rows[i]["tenbd"].ToString(); osheet.Cells[dong, i + 7] = dsmabd.Tables[0].Rows[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 = 8; 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(4) + dong.ToString(), d.getIndex(cot - 1) + dong.ToString()).Font.Bold = true; oxl.ActiveWindow.DisplayZeros = false; osheet.Cells[1, 2] = makp.Text; osheet.Cells[2, 2] = (tu.Text == den.Text)?"Ngày " + tu.Text:"Ngày " + tu.Text + " - " + den.Text; osheet.Cells[1, 3] = "TỔNG HỢP Y LỆNH"; orange = osheet.get_Range(d.getIndex(2) + "1", d.getIndex(cot - 1) + "1"); 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); } //osheet.PrintPreview(Missing.Value); else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exp_excelCanLoc(bool print) { try { d.check_process_Excel(); int be = 3, cot = ds.Tables[0].Columns.Count, dong = ds.Tables[0].Rows.Count + be + 2; DataColumn dc = new DataColumn(); dc.ColumnName = "ghichu"; dc.DataType = Type.GetType("System.String"); ds.Tables[0].Columns.Add(dc); DataRow drstt = ds.Tables[0].NewRow(); for (int i = 0; i < cot + 1; i++) { drstt[i] = i.ToString(); } ds.Tables[0].Rows.InsertAt(drstt, 0); 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 < 7; i++) { osheet.Cells[be + 1, i + 1] = get_ten(i); } for (int i = 0; i < dsmabd.Tables[0].Rows.Count; i++) { osheet.Cells[be + 1, i + 8] = dsmabd.Tables[0].Rows[i]["tenbd"].ToString(); osheet.Cells[dong + 1, i + 8] = dsmabd.Tables[0].Rows[i]["soluong"].ToString(); } osheet.Cells[4, cot + 1] = "Ghi chú"; orange = osheet.get_Range(d.getIndex(be) + "4", d.getIndex(cot) + "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 + 10) + dong + 10); orange.Font.Name = "Arial"; orange.Font.Size = 10; orange.Font.Bold = false; osheet.get_Range(d.getIndex(0) + "4", d.getIndex(cot) + (dong + 1)).Borders.LineStyle = XlBorderWeight.xlHairline; //orange.EntireRow.AutoFit(); orange.EntireColumn.AutoFit(); orange = osheet.get_Range(d.getIndex(cot) + "1", d.getIndex(cot + 100) + dong + 10); orange.Cells.ColumnWidth = 3; //to mau tu cot thu 6 for (int i = 7; i < cot; i++) { if (i % 2 == 0) { orange = osheet.get_Range(d.getIndex(i) + "4", d.getIndex(i) + dong.ToString()); orange.Interior.Color = System.Drawing.Color.Beige.ToArgb(); } } // osheet.get_Range(d.getIndex(4) + (dong + 1), d.getIndex(cot - 1) + (dong + 1)).Font.Bold = true; oxl.ActiveWindow.DisplayZeros = false; osheet.Cells[1, 2] = d.Tenbv; osheet.Cells[2, 2] = (tu.Text == den.Text) ? "Ngày " + tu.Text : "Ngày " + tu.Text + " - " + den.Text; osheet.Cells[1, 4] = "TỔNG HỢP Y LỆNH"; orange = osheet.get_Range(d.getIndex(2) + "1", d.getIndex(cot - 1) + "1"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Size = 12; orange.Font.Bold = true; osheet.Cells[dong + 4, 26] = "In ngày " + System.DateTime.Today.Day.ToString() + " tháng " + System.DateTime.Today.Month.ToString() + " năm " + System.DateTime.Today.Year.ToString(); osheet.Cells[dong + 5, 2] = "Khoa Dược"; osheet.Cells[dong + 5, 7] = "Bác Sĩ"; osheet.Cells[dong + 5, 15] = "Điều dưỡng thực hiện"; osheet.Cells[dong + 5, 26] = "Người sao y lệnh"; osheet.Cells[dong + 8, 2] = "Họ tên..................."; osheet.Cells[dong + 8, 7] = "Họ tên..................."; osheet.Cells[dong + 8, 15] = "Họ tên..................."; osheet.Cells[dong + 8, 26] = "Họ tên..................."; //orange = osheet.get_Range(d.getIndex(0) + dong+4, d.getIndex(cot) + dong+4); //orange.Font.Name = "Arial"; //orange.Font.Size = 8; //orange.Font.Bold = 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"; if (print) { osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } //osheet.PrintPreview(Missing.Value); else { oxl.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//gam 23/02/2012 private void exp_excel(bool print, DataSet ads1) { try { d.check_process_Excel(); int i_rec = 0, be = 4, dong = 6, sodong = ads1.Tables[0].Rows.Count + 6, socot = ads1.Tables[0].Columns.Count - 1, dongke = sodong - 1; char[] cSplit = { '+' }; string[] sTitle = haison.Split(cSplit); i_rec = sTitle.Length; tenfile = d.Export_Excel(ads1, "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Ổ LƯU TRỮ HỒ SƠ BỆNH ÁN"; osheet.Cells[2, 8] = (tu.Text == den.Text) ? "Tháng " + tu.Text : "Từ ngày " + tu.Text + " đến ngày" + den.Text; 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, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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; } }
private void exp_excel(bool print) { d.check_process_Excel(); ds = dsxml.Copy(); int dong = 3, sodong = ds.Tables[0].Rows.Count + dong, socot = ds.Tables[0].Columns.Count - 1, dongke = sodong + 1; tenfile = d.Export_Excel(ds, "BAOCAONXT"); 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(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 = 11; int row = dong - 1; foreach (DataRow r in dtdmkho.Rows) { osheet.Cells[row, pos] = r["ten"].ToString(); osheet.get_Range(d.getIndex(pos - 1) + row.ToString(), d.getIndex(pos) + row.ToString()).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; pos += 2; } for (int i = 0; i < 10; i++) { osheet.Cells[dong, i + 1] = get_ten(i); if (i < 4) { osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + dong.ToString()).MergeCells = true; } //else osheet.get_Range(d.getIndex(i)+"1",d.getIndex(i)+"2").MergeCells=true; } for (int i = 8; i < ds.Tables[0].Columns.Count; i++) { osheet.Cells[dong, i + 1] = get_ten((i % 2 == 0)?4:5); } osheet.Cells[dong - 1, 5] = "Tồn đầu"; osheet.Cells[dong - 1, 7] = "Nhập"; osheet.Cells[dong - 1, 9] = "Nhập khác"; osheet.Cells[dong - 2, 11] = "Xuất"; osheet.Cells[dong - 1, 11 + dtdmkho.Rows.Count * 2] = "Tồn cuối"; osheet.get_Range(d.getIndex(10) + "1", d.getIndex(ds.Tables[0].Columns.Count - 3) + "1").HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange = osheet.get_Range(d.getIndex(4) + "1", d.getIndex(5) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.VerticalAlignment = XlVAlign.xlVAlignCenter; orange.MergeCells = true; orange = osheet.get_Range(d.getIndex(6) + "1", d.getIndex(7) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.VerticalAlignment = XlVAlign.xlVAlignCenter; orange.MergeCells = true; orange = osheet.get_Range(d.getIndex(8) + "1", d.getIndex(9) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.VerticalAlignment = XlVAlign.xlVAlignCenter; orange.MergeCells = true; orange = osheet.get_Range(d.getIndex(socot - 1) + "1", d.getIndex(socot) + "2"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.VerticalAlignment = XlVAlign.xlVAlignCenter; orange.MergeCells = true; 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 XUẤT TỒN\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(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 = 24, 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(17) + dong.ToString(), d.getIndex(socot - 1) + 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Ê VẬT TƯ Y 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(5) + "7"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.MergeCells = true; orange.Font.Bold = true; osheet.Cells[7, 15] = "Mã hóa DVKT"; orange = osheet.get_Range(d.getIndex(14) + "7", d.getIndex(15) + "7"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.MergeCells = true; orange.Font.Bold = true; osheet.Cells[7, 21] = "Số lượng"; orange = osheet.get_Range(d.getIndex(20) + "7", d.getIndex(21) + "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 < 6) || (i >= 14 && i <= 15) || (i >= 20 && i <= 21)) { 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); } }
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(be + 2 - i_cot) + 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 < 5 - 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, 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 = 0; decimal tc = 0; foreach (DataRow r in dtnhomvp.Select("true", "stt")) { osheet.Cells[dong - 1, j + 6 - i_cot] = r["ten"].ToString(); orange = osheet.get_Range(d.getIndex(j + 6) + "3", d.getIndex(j + 6) + "3"); orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; orange.Font.Bold = true; osheet.Cells[sodong, j + 6 - i_cot] = r["tc"].ToString(); tc += decimal.Parse(r["tc"].ToString()); j++; } osheet.Cells[sodong, socot + 1] = tc; if (bCongkham) { osheet.Cells[dong - 1, socot] = "Tiền khám"; osheet.Cells[sodong, socot] = dcongkham; osheet.Cells[sodong, socot + 1] = tc + dcongkham; } if (theo.SelectedIndex == 1) { osheet.Cells[sodong, 3] = soluot; osheet.Cells[sodong, 4] = songay; } 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); } }
/*<summary> * 将DataTable中的数据导出到Excel中,并在服务器端AppData文件夹中生成xls文件 * </summary> * <param name="dt">要导出数据的DataTable</param> * <param name="head">题头数据</param> * <param name="absFileName">文件的绝对路径</param> * <returns></returns> */ public static void ExportToExcelDiagramfor9(System.Data.DataTable dt, string[] head, string absFileName) { //设置多少行为一个Sheet int RowsToDivideSheet = 65535; //计算Sheet数 int sheetCount = (dt.Rows.Count - 1) / RowsToDivideSheet + 1; GC.Collect(); string excelTemplateDPath; //EXCEL模板默认服务器物理存放路径 string tempEFilePath = "\\TempFiles"; //EXCEL临时文件保存服务器物理存放路径 string tempEFileXPath = "/TempFiles"; //EXCEL临时文件保存服务器虚拟存放路径 Excel.Application excel = null; Excel._Workbook xBk = null; Excel._Worksheet xSt = null; Excel.Workbooks workbooks; //工作簿集合 Excel.Sheets sheets; //SHEET页集合 #region //读取配置文件中路线模板路径及名称并验证是否存在 //获取配置文件中路线模板路径及名称 excelTemplateDPath = System.Web.HttpContext.Current.Server.MapPath("~/moban"); tempEFileXPath = "~/moban" + tempEFileXPath; tempEFilePath = excelTemplateDPath + tempEFilePath; excelTemplateDPath += "\\TaskTemplet9.xls"; //验证EXCEL临时文件夹是否存在 if (!File.Exists(tempEFilePath)) { Directory.CreateDirectory(tempEFilePath); } #endregion try { #region //启动excel进程并加载模板 //启动EXCEL进程 excel = new Excel.Application(); excel.Visible = false; excel.UserControl = true; excel.DisplayAlerts = false; //加载读取模板 workbooks = excel.Workbooks; xBk = workbooks.Add(excelTemplateDPath); sheets = xBk.Worksheets; xSt = (Excel._Worksheet)sheets.get_Item(1); #endregion //循环中要使用的变量 int dvRowStart; int dvRowEnd; //对全部Sheet进行操作 for (int sheetIndex = 0; sheetIndex < sheetCount; sheetIndex++) { //计算起始行 dvRowStart = sheetIndex * RowsToDivideSheet; dvRowEnd = dvRowStart + RowsToDivideSheet - 1; if (dvRowEnd > dt.Rows.Count - 1) { dvRowEnd = dt.Rows.Count - 1; } //创建一个Sheet if (null == xSt) { xSt = (Excel._Worksheet)xBk.Worksheets.Add(Type.Missing, Type.Missing, 1, Type.Missing); } else { xSt = (Excel._Worksheet)xBk.Worksheets.Add(Type.Missing, xSt, 1, Type.Missing); } //设置SheetName xSt.Name = "Excel"; if (sheetCount > 1) { xSt.Name += ((int)(sheetIndex + 1)).ToString(); } //题头导出 int rowCount = head.Length; int colCount = 1; object[,] dataArray = new object[colCount, rowCount]; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { dataArray[j, i] = head[i]; } } xSt.get_Range(xSt.Cells[1, 1], xSt.Cells[colCount, rowCount]).NumberFormatLocal = "@"; //设置单元格格式为文本 xSt.get_Range(xSt.Cells[1, 1], xSt.Cells[colCount, rowCount]).Value2 = dataArray; xSt.get_Range(xSt.Cells[1, 1], xSt.Cells[colCount, rowCount]).Font.Name = "Arial"; xSt.get_Range(xSt.Cells[1, 1], xSt.Cells[colCount, rowCount]).Font.Size = 10; //数据导出 System.Data.DataTable SheetTable = new System.Data.DataTable(); foreach (DataColumn dc in dt.Columns) { DataColumn newdc = new DataColumn(); newdc.ColumnName = dc.ColumnName; newdc.DataType = dc.DataType; SheetTable.Columns.Add(newdc); } for (int drvIndex = dvRowStart; drvIndex <= dvRowEnd; drvIndex++) { SheetTable.ImportRow(dt.Rows[drvIndex]); } //保存数据 rowCount = SheetTable.Rows.Count; colCount = SheetTable.Columns.Count; object[,] dataArray1 = new object[rowCount, colCount]; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { dataArray1[i, j] = SheetTable.Rows[i][j]; } } xSt.get_Range(xSt.Cells[2, 1], xSt.Cells[rowCount + 1, colCount]).NumberFormatLocal = "0.00_ "; //保留小数位数为2; xSt.get_Range(xSt.Cells[2, 1], xSt.Cells[rowCount + 1, colCount]).Value2 = dataArray1; xSt.get_Range(xSt.Cells[2, 1], xSt.Cells[rowCount + 1, colCount]).Font.Name = "Arial"; xSt.get_Range(xSt.Cells[2, 1], xSt.Cells[rowCount + 1, colCount]).Font.Size = 10; //单元格边框 xSt.get_Range(xSt.Cells[1, 1], xSt.Cells[rowCount + 1, colCount]).Borders.LineStyle = 1; xSt.get_Range(xSt.Cells[1, 1], xSt.Cells[rowCount + 1, colCount]).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter; //设置居中对齐 xSt.Columns.AutoFit(); //自适应宽度 //设置图标的标题 string Charttitle = dt.Rows[0][0].ToString(); } //删除Sheet1 excel.DisplayAlerts = false; //注意一定要加上这句 ((Microsoft.Office.Interop.Excel.Worksheet)xBk.Worksheets["Sheet1"]).Delete(); excel.DisplayAlerts = true; //注意一定要加上这句 object objOpt = System.Reflection.Missing.Value; excel.Visible = false; xBk.SaveCopyAs(absFileName); xBk.Close(false, null, null); excel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk); System.Runtime.InteropServices.Marshal.ReleaseComObject(excel); System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt); xBk = null; excel = null; xSt = null; } catch (Exception e) { //throw (e); xBk.Close(false, null, null); excel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk); System.Runtime.InteropServices.Marshal.ReleaseComObject(excel); System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt); xBk = null; excel = null; xSt = null; } }
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 " + ((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; }