private void cmdExportToExcel_Click(object sender, EventArgs e) { try { _dtData = SPs.BaocaoThongkeSonoitru(dtFromDate.Value, dtToDate.Value, Utility.Int16Dbnull(cboDoituongKCB.SelectedValue, -1), Utility.Int16Dbnull(txtNhanvientiepdon.txtMyID, -1), Utility.sDbnull(cboKhoa.SelectedValue, "KKB"), thamso, Utility.Int16Dbnull(cboTinhTrang.SelectedValue, -1)).GetDataSet(). Tables[0]; if (_dtData.Rows.Count > 0) { Utility.SetDataSourceForDataGridEx(grdList, _dtData, true, true, "1=1", ""); const string reportcode = "baocao_thongke_sokhambenh_noitru"; string duongdan = Utility.GetPathExcel(reportcode); var book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); XLSheet sheet = book.Sheets[0]; DataTable dt = _dtData; int idxRow = 9; int idxColSh = 0; string condition = string.Format("Từ ngày {0} đến {1} - Đối tượng : {2} - Tình trạng :{3}", dtFromDate.Text, dtToDate.Text, cboDoituongKCB.SelectedIndex >= 0 ? Utility.sDbnull(cboDoituongKCB.Text) : "Tất cả", cboTinhTrang.SelectedIndex > 0 ? Utility.sDbnull(cboKhoa.Text) : "Tất cả"); sheet[4, idxColSh].SetValue(Convert.ToString(condition), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["tuoinam"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["tuoinu"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["IsCongNhanVienChuc"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["Isbhyt"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["thanh_thi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["nong_thon"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["Nho12thang"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["tu1den15tuoi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["nghe_nghiep"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(dt.Rows[i]["noi_gioithieu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(dt.Rows[i]["ngay_vaovien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(dt.Rows[i]["ngay_chuyenvien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 15].SetValue(Convert.ToString(dt.Rows[i]["ngay_ravien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 16].SetValue(Convert.ToString(dt.Rows[i]["chandoantuyenduoi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 17].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 18].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 19].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 20].SetValue(Convert.ToString(dt.Rows[i]["khoi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 21].SetValue(Convert.ToString(dt.Rows[i]["do_giam"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 22].SetValue(Convert.ToString(dt.Rows[i]["nang_hon"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 23].SetValue(Convert.ToString(dt.Rows[i]["khong_thay_doi"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } // vị trí dòng dữ liệu của table tiếp theo, vị trí cột bắt đầu t? 0 string getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); string pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); } else { Utility.ShowMsg("Không có dữ liệu để báo cáo!"); } } catch (Exception ex) { Utility.ShowMsg("Lỗi: " + ex.Message); } }
/// <summary> /// hàm thực iheenj viecj /// export to excel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdExportToExcel_Click(object sender, EventArgs e) { try { try { _dtData = SPs.ThuocSotonghopthuocHangngay(dtFromDate.Value, dtToDate.Value, Utility.Int16Dbnull(cboStock.SelectedValue, -1), Utility.Int16Dbnull(cboDoiTuong.SelectedValue, -1), Utility.Int16Dbnull(cbotinhtrang.SelectedValue, -1), "").GetDataSet(). Tables[0]; if (_dtData.Rows.Count > 0) { Utility.SetDataSourceForDataGridEx(grdList, _dtData, true, true, "1=1", ""); const string reportcode = "thuoc_sotonghop_hangngay"; string duongdan = Utility.GetPathExcel(reportcode); var book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); XLSheet sheet = book.Sheets[0]; DataTable dt = _dtData; int idxRow = 6; int idxColSh = 0; string condition = string.Format("Từ ngày {0} đến {1} - Đối tượng : {2} - Tình trạng :{3}", dtFromDate.Text, dtToDate.Text, cboDoiTuong.SelectedIndex >= 0 ? Utility.sDbnull(cboDoiTuong.Text) : "Tất cả", cbotinhtrang.SelectedIndex > 0 ? Utility.sDbnull(cbotinhtrang.Text) : "Tất cả"); const int idxRowT = 5; const int idxColShT = 0; //sheet[5, 0].SetValue("STT", HamDungChung.styleStringCenter(book)); //sheet[5, 1].SetValue("HỌ TÊN NGƯỜI BỆNH", HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Columns.Count; i++) { if (Utility.sDbnull(dt.Columns[i].ColumnName) == "ten_benhnhan") { sheet[idxRowT, idxColShT + i].SetValue(Utility.sDbnull("HỌ TÊN NGƯỜI BỆNH"), HamDungChung.styleStringCenter_Bold(book)); } sheet[idxRowT, idxColShT + i].SetValue(Utility.sDbnull(dt.Columns[i].ColumnName), HamDungChung.styleStringCenter_Bold(book)); if (i >= 2) { sheet[idxRowT, idxColShT + i].SetValue(Utility.sDbnull(dt.Columns[i].ColumnName), HamDungChung.styleStringCenter_Rotate(book)); } } //sheet[3, idxColSh].SetValue(Convert.ToString(condition), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); for (int j = 2; j < dt.Columns.Count; j++) { sheet[idxRow, idxColSh + j].SetValue(Convert.ToString(dt.Rows[i][dt.Columns[j].ColumnName]), HamDungChung.styleNumber(book)); } idxRow = idxRow + 1; } // vị trí dòng dữ liệu của table tiếp theo, vị trí cột bắt đầu t? 0 string getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); string pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); } else { Utility.ShowMsg("Không có dữ liệu để báo cáo!"); } } catch (Exception ex) { Utility.ShowMsg("Lỗi: " + ex.Message); } //Janus.Windows.GridEX.GridEXRow[] gridExRows = grdList.GetCheckedRows(); //if (grdList.RowCount <= 0) //{ // Utility.ShowMsg("Không có dữ liệu", "Thông báo"); // grdList.Focus(); // return; //} //saveFileDialog1.Filter = "Excel File(*.xls)|*.xls"; //saveFileDialog1.FileName = string.Format("{0}.xls", baocaO_TIEUDE1.TIEUDE); ////saveFileDialog1.ShowDialog(); //if (saveFileDialog1.ShowDialog() == DialogResult.OK) //{ // string sPath = saveFileDialog1.FileName; // FileStream fs = new FileStream(sPath, FileMode.Create); // fs.CanWrite.CompareTo(true); // fs.CanRead.CompareTo(true); // gridEXExporter1.Export(fs); // fs.Dispose(); //} //saveFileDialog1.Dispose(); //saveFileDialog1.Reset(); } catch (Exception exception) { } }
private void cmdExcel_Click(object sender, EventArgs e) { try { string reportcode = "BHYT_21A_EXCEL"; string duongdan = Utility.GetPathExcel(reportcode); var book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); XLSheet sheet = book.Sheets[0]; DataTable dt = m_dataTH; int idxRow = 6; int idxColSh = 0; string codintion = string.Format("Từ ngày {0} đến ngày {1}. Tuyến {2}", dtpFromDate.Value.ToString("dd/MM/yyyy"), dtpToDate.Value.ToString("dd/MM/yyyy"), cboTuyen.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); int sttloaidichvu = 1; if (chktuyen.Checked) { for (int i = 0; i < dt.Rows.Count; i++) { if (i == 0) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(dt.Rows[i]["DoiTuong"]), HamDungChung.styleStringLeft_Bold(book)); idxRow = idxRow + 1; sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); sttloaidichvu = sttloaidichvu + 1; idxRow = idxRow + 1; } else { if (dt.Rows[i]["DoiTuong"].ToString() != dt.Rows[i - 1]["DoiTuong"].ToString()) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(dt.Rows[i]["DoiTuong"]), HamDungChung.styleStringLeft_Bold(book)); idxRow = idxRow + 1; sttloaidichvu = 1; sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); sttloaidichvu = sttloaidichvu + 1; idxRow = idxRow + 1; } if (dt.Rows[i]["DoiTuong"].ToString() == dt.Rows[i - 1]["DoiTuong"].ToString() && dt.Rows[i]["Ten_nhombaocao_dichvu"].ToString() != dt.Rows[i - 1]["Ten_nhombaocao_dichvu"].ToString()) { sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); sttloaidichvu = sttloaidichvu + 1; idxRow = idxRow + 1; } } sheet[idxRow, idxColSh].SetValue(Convert.ToString(dt.Rows[i]["ma_QD"]), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ma_chitiet_bhyt"]), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToDecimal(dt.Rows[i]["SO_LUONG"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToDecimal(dt.Rows[i]["soluong_nt"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToDecimal(dt.Rows[i]["DON_GIA"]), HamDungChung.styleDecimalBoldAllBorder_Money(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToDecimal(dt.Rows[i]["thanh_tien"]), HamDungChung.styleDecimalBoldAllBorder_Money(book)); idxRow = idxRow + 1; } } else { for (int i = 0; i < dt.Rows.Count; i++) { if (i == 0) { sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); sttloaidichvu = sttloaidichvu + 1; idxRow = idxRow + 1; } else { if (dt.Rows[i]["Ten_nhombaocao_dichvu"].ToString() != dt.Rows[i - 1]["Ten_nhombaocao_dichvu"].ToString()) { sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); sttloaidichvu = sttloaidichvu + 1; idxRow = idxRow + 1; } } sheet[idxRow, idxColSh].SetValue(Convert.ToString(dt.Rows[i]["ma_QD"]), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ma_chitiet_bhyt"]), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToDecimal(dt.Rows[i]["SO_LUONG"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToDecimal(dt.Rows[i]["soluong_nt"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToDecimal(dt.Rows[i]["DON_GIA"]), HamDungChung.styleDecimalBoldAllBorder_Money(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToDecimal(dt.Rows[i]["thanh_tien"]), HamDungChung.styleDecimalBoldAllBorder_Money(book)); idxRow = idxRow + 1; } } sheet[idxRow, idxColSh + 3].SetValue(Convert.ToDecimal(dt.Compute("Sum(SO_LUONG)", "1=1")), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToDecimal(dt.Compute("Sum(soluong_nt)", "1=1")), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToDecimal(dt.Compute("Sum(thanh_tien)", "1=1")), HamDungChung.styleDecimalBoldAllBorder_Money(book)); string getdate = string.Format("Ngày {0} tháng {1} năm {2}", dtpNgayIn.Value.Day, dtpNgayIn.Value.Month, dtpNgayIn.Value.Year); sheet[idxRow + 2, 5].SetValue(getdate, HamDungChung.styleStringCenter_UnBorder(book)); sheet[idxRow + 3, 1].SetValue("NGƯỜI LẬP BẢNG", HamDungChung.styleDecimalBoldAllBorder_Money(book)); sheet[idxRow + 3, 4].SetValue("PHÒNG TÀI CHÍNH KẾ TOÁN", HamDungChung.styleDecimalBoldAllBorder_Money(book)); sheet[idxRow + 3, 5].SetValue("GIÁM ĐỐC BỆNH VIỆN", HamDungChung.styleDecimalBoldAllBorder_Money(book)); // vị trí dòng dữ liệu của table tiếp theo, vị trí cột bắt đầu t? 0 string getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); string pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); } catch (Exception ex) { Utility.ShowMsg("Lỗi: " + ex.Message); } }
private void cmdExportToExcel_Click(object sender, EventArgs e) { try { int trangthai = -1; if (radTatca.Checked) { trangthai = -1; } if (radDathuchien.Checked) { trangthai = 1; } if (radChuathuchien.Checked) { trangthai = 0; } DataTable dtDanhsach = SPs.BaocaoThongkedanhsachThuchienchucnang(dtFromDate.Value, dtToDate.Value, Utility.Int16Dbnull(cboDoituongKCB.SelectedValue, -1), Utility.sDbnull(cboKhoa.SelectedValue, "KKB"), Args, Utility.Int32Dbnull(txtdichvu.MyID, -1), trangthai).GetDataSet().Tables[0]; if (dtDanhsach.Rows.Count > 0) { Utility.SetDataSourceForDataGridEx(grdResult, dtDanhsach, false, true, "1=1", ""); string reportcode = ""; string duongdan = ""; string codintion = ""; DataTable dt = new DataTable(); int idxRow = 0; int idxColSh = 0; var book = new C1XLBook(); XLSheet sheet = book.Sheets[0]; string getTime = ""; string pathDirectory = ""; switch (Args.Substring(0, 2)) { case "SA": reportcode = "baocao_thongkedanhsach_sieuam"; duongdan = Utility.GetPathExcel(reportcode); book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); sheet = book.Sheets[0]; dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_khoaphong"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["ket_qua"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; case "XQ": reportcode = "baocao_thongkedanhsach_xquang"; duongdan = Utility.GetPathExcel(reportcode); book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); sheet = book.Sheets[0]; dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_khoaphong"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["ket_qua"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; break; case "DT": break; case "NS": reportcode = "baocao_thongkedanhsach_noisoi"; duongdan = Utility.GetPathExcel(reportcode); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_khoaphong"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["ket_qua"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; case "PT": reportcode = "baocao_thongkedanhsach_pttt"; duongdan = Utility.GetPathExcel(reportcode); book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); sheet = book.Sheets[0]; dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["phuongphap_vocam"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["ngay_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["loai_phauthuat"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(dt.Rows[i]["bacsy_gayme"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; case "TT": reportcode = "baocao_thongkedanhsach_tt"; duongdan = Utility.GetPathExcel(reportcode); book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); sheet = book.Sheets[0]; dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["phuongphap_vocam"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["ngay_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["loai_phauthuat"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(dt.Rows[i]["bacsy_gayme"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; default: reportcode = "baocao_thongkedanhsach_tt"; duongdan = Utility.GetPathExcel(reportcode); book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); sheet = book.Sheets[0]; dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["phuongphap_vocam"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["ngay_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["loai_phauthuat"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(dt.Rows[i]["bacsy_gayme"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; } } else { Utility.ShowMsg("Không có dữ liệu để báo cáo!"); } // ExcelUtlity.ExportGridEx(grdResult); } catch (Exception exception) { Utility.ShowMsg("Lỗi:" + exception.Message); } }
private void cboXuatTrenLuoi_Click(object sender, EventArgs e) { try { _dtData = SPs.BaoCaoChiDinhHangNgay(dtFromDate.Value, dtToDate.Value, Utility.Int16Dbnull(cboDoituongKCB.SelectedValue, -1), Utility.Int16Dbnull(cboTinhTrang.SelectedValue, -1)).GetDataSet(). Tables[0]; if (_dtData.Rows.Count > 0) { Utility.SetDataSourceForDataGridEx(grdList, _dtData, true, true, "1=1", ""); const string reportcode = "BAOCAO_HANGNGAY"; string duongdan = Utility.GetPathExcel(reportcode); var book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); XLSheet sheet = book.Sheets[0]; DataTable dt = _dtData; int idxRow = 5; int idxColSh = 0; string condition = string.Format("Từ ngày {0} đến {1} - Đối tượng : {2} - Trạng thái :{3} ", dtFromDate.Text, dtToDate.Text, cboDoituongKCB.SelectedIndex >= 0 ? Utility.sDbnull(cboDoituongKCB.Text) : "Tất cả", cboTinhTrang.SelectedIndex > 0 ? Utility.sDbnull(cboTinhTrang.Text) : "Tất cả"); sheet[3, idxColSh].SetValue(Convert.ToString(condition), HamDungChung.styleStringCenter(book)); int idx = 0; foreach (GridEXRow grdExRow in grdList.GetDataRows()) { if (idx == 0) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(grdExRow.Cells["DoiTuong"]), HamDungChung.styleStringLeft_Bold(book)); idxRow = idxRow + 1; } else { if (dt.Rows[idx]["DoiTuong"].ToString() != dt.Rows[idx - 1]["DoiTuong"].ToString()) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(grdExRow.Cells["DoiTuong"]), HamDungChung.styleStringLeft_Bold(book)); idxRow = idxRow + 1; } //if (dt.Rows[i]["DoiTuong"].ToString() == dt.Rows[i - 1]["DoiTuong"].ToString() && dt.Rows[i]["Ten_nhombaocao_dichvu"].ToString() != dt.Rows[i - 1]["Ten_nhombaocao_dichvu"].ToString()) //{ // sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); // sttloaidichvu = sttloaidichvu + 1; // idxRow = idxRow + 1; //} } sheet[idxRow, idxColSh].SetValue(Convert.ToString(idx + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToInt64(grdExRow.Cells["id_benhnhan"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(grdExRow.Cells["ma_luotkham"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(grdExRow.Cells["ten_benhnhan"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(grdExRow.Cells["nam_sinh"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(grdExRow.Cells["gioitinh"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(grdExRow.Cells["mathe_bhyt"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(grdExRow.Cells["gt_the_tu"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(grdExRow.Cells["gt_the_den"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(grdExRow.Cells["dia_chi"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(grdExRow.Cells["mabenh_chinh"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(grdExRow.Cells["mabenh_phu"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(grdExRow.Cells["ma_kcbbd"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(grdExRow.Cells["ngay_vao"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(grdExRow.Cells["ngay_ra"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 15].SetValue(Convert.ToDecimal(grdExRow.Cells["tong_tien"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 16].SetValue(Convert.ToDecimal(grdExRow.Cells["t_bhyt_chitra"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 17].SetValue(Convert.ToDecimal(grdExRow.Cells["t_bnhan_chitra"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 18].SetValue(Convert.ToString(grdExRow.Cells["loai_kcb"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 19].SetValue(Convert.ToString(grdExRow.Cells["loai_dichvu"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 20].SetValue(Convert.ToString(grdExRow.Cells["ma_dichvu"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 21].SetValue(Convert.ToString(grdExRow.Cells["ten_dichvu"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 22].SetValue(Convert.ToDecimal(grdExRow.Cells["so_luong"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 23].SetValue(Convert.ToDecimal(grdExRow.Cells["don_gia"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 24].SetValue(Convert.ToDecimal(grdExRow.Cells["thanh_tien"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 25].SetValue(Convert.ToDecimal(grdExRow.Cells["bhyt_chitra"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 26].SetValue(Convert.ToDecimal(grdExRow.Cells["bnhan_chitra"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 27].SetValue(Convert.ToString(grdExRow.Cells["ngay_thanhtoan"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 28].SetValue(Convert.ToString(grdExRow.Cells["ten_dung_tuyen"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 29].SetValue(Convert.ToString(grdExRow.Cells["DoiTuong"]), HamDungChung.styleStringLeft(book)); idx++; idxRow = idxRow + 1; } // vị trí dòng dữ liệu của table tiếp theo, vị trí cột bắt đầu t? 0 string getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); string pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); } else { Utility.ShowMsg("Không có dữ liệu để báo cáo!"); } } catch (Exception ex) { Utility.ShowMsg("Lỗi: " + ex.Message); } }
/// <summary> /// hàm thực hiện việc export excel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdExportToExcel_Click(object sender, EventArgs e) { try { if (_dtData.Rows.Count > 0) { Utility.SetDataSourceForDataGridEx(grdList, _dtData, true, true, "1=1", ""); const string reportcode = "baocao_tiepdonbenhnhan_chitiet"; string duongdan = Utility.GetPathExcel(reportcode); var book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); XLSheet sheet = book.Sheets[0]; DataTable dt = _dtData; int idxRow = 6; int idxColSh = 0; string condition = string.Format("Từ ngày {0} đến {1} - Đối tượng : {2} ", dtFromDate.Text, dtToDate.Text, cboDoituongKCB.SelectedIndex >= 0 ? Utility.sDbnull(cboDoituongKCB.Text) : "Tất cả" ); sheet[4, idxColSh].SetValue(Convert.ToString(condition), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["id_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["ma_luotkham"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["mathe_bhyt"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_nhanvien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["ngay_tiepdon"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } // vị trí dòng dữ liệu của table tiếp theo, vị trí cột bắt đầu t? 0 string getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); string pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); //saveFileDialog1.Filter = "Excel File(*.xls)|*.xls"; //saveFileDialog1.FileName = string.Format("{0}.xls",tieude); ////saveFileDialog1.ShowDialog(); //if (saveFileDialog1.ShowDialog() == DialogResult.OK) //{ // string sPath = saveFileDialog1.FileName; // FileStream fs = new FileStream(sPath, FileMode.Create); // fs.CanWrite.CompareTo(true); // fs.CanRead.CompareTo(true); // gridEXExporter1.Export(fs); // fs.Dispose(); //} //saveFileDialog1.Dispose(); //saveFileDialog1.Reset(); } } catch (Exception exception) { } }