private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { progressBar1.Step = 1; progressBar1.Value = 0; progressBar1.Maximum = dataGridView1.RowCount; progressBar1.Minimum = 0; ModifyProgressBarColor.SetState(progressBar1, 1); h = 2; string Truong66 = ""; bool IsLoai2 = false; for (int i = 0; i < dataGridView1.RowCount; i++) { Truong66 = ""; if (i > 0 & IsLoai2 & dataGridView1[1, i].Value + "" == "Loai3") { Truong66 = "1"; } if (dataGridView1[1, i].Value + "" == "Loai2") { IsLoai2 = true; } else if (dataGridView1[1, i].Value + "" == "Loai1") { IsLoai2 = false; } wrksheet.Cells[h, 1] = dataGridView1[0, i].Value + ""; //Trường 01/ Tên hình wrksheet.Cells[h, 2] = dataGridView1[1, i].Value + ""; //LoaiPhieu wrksheet.Cells[h, 3] = dataGridView1[2, i].Value + ""; //Truong001 wrksheet.Cells[h, 4] = dataGridView1[3, i].Value + ""; wrksheet.Cells[h, 5] = dataGridView1[4, i].Value + ""; wrksheet.Cells[h, 6] = dataGridView1[5, i].Value + ""; wrksheet.Cells[h, 7] = dataGridView1[6, i].Value + ""; wrksheet.Cells[h, 8] = dataGridView1[7, i].Value + ""; wrksheet.Cells[h, 9] = dataGridView1[8, i].Value + ""; wrksheet.Cells[h, 10] = dataGridView1[9, i].Value + ""; wrksheet.Cells[h, 11] = dataGridView1[10, i].Value + ""; wrksheet.Cells[h, 12] = dataGridView1[11, i].Value + ""; wrksheet.Cells[h, 13] = dataGridView1[12, i].Value + ""; wrksheet.Cells[h, 14] = dataGridView1[13, i].Value + ""; wrksheet.Cells[h, 15] = dataGridView1[14, i].Value + ""; wrksheet.Cells[h, 16] = dataGridView1[15, i].Value + ""; wrksheet.Cells[h, 17] = dataGridView1[16, i].Value + ""; //Truong015 wrksheet.Cells[h, 18] = dataGridView1[17, i].Value + ""; //Truong016 wrksheet.Cells[h, 19] = dataGridView1[18, i].Value + ""; //Truong017 wrksheet.Cells[h, 20] = dataGridView1[19, i].Value + ""; //Truong018 wrksheet.Cells[h, 21] = dataGridView1[20, i].Value + ""; //Truong019 wrksheet.Cells[h, 22] = dataGridView1[21, i].Value + ""; //Truong020 wrksheet.Cells[h, 23] = dataGridView1[22, i].Value + ""; //Truong021 wrksheet.Cells[h, 24] = dataGridView1[23, i].Value + ""; //Truong022 wrksheet.Cells[h, 25] = dataGridView1[24, i].Value + ""; //Truong023 wrksheet.Cells[h, 26] = dataGridView1[25, i].Value + ""; //Truong024 wrksheet.Cells[h, 27] = dataGridView1[26, i].Value + ""; //Truong025 wrksheet.Cells[h, 28] = dataGridView1[27, i].Value + ""; //Truong026 wrksheet.Cells[h, 29] = dataGridView1[28, i].Value + ""; //Truong027 wrksheet.Cells[h, 30] = dataGridView1[29, i].Value + ""; //Truong028 wrksheet.Cells[h, 31] = dataGridView1[30, i].Value + ""; //Truong029 wrksheet.Cells[h, 32] = dataGridView1[31, i].Value + ""; //Truong030 wrksheet.Cells[h, 33] = dataGridView1[32, i].Value + ""; //Truong031 wrksheet.Cells[h, 34] = dataGridView1[33, i].Value + ""; //Truong032 wrksheet.Cells[h, 35] = dataGridView1[34, i].Value + ""; //Truong033 wrksheet.Cells[h, 36] = dataGridView1[35, i].Value + ""; //Truong034 wrksheet.Cells[h, 37] = dataGridView1[36, i].Value + ""; //Truong035 wrksheet.Cells[h, 38] = dataGridView1[37, i].Value + ""; //Truong036 wrksheet.Cells[h, 39] = dataGridView1[38, i].Value + ""; //Truong037 wrksheet.Cells[h, 40] = dataGridView1[39, i].Value + ""; //Truong038 wrksheet.Cells[h, 41] = dataGridView1[40, i].Value + ""; //Truong039 wrksheet.Cells[h, 42] = dataGridView1[41, i].Value + ""; //Truong040 wrksheet.Cells[h, 43] = dataGridView1[42, i].Value + ""; //Truong041 wrksheet.Cells[h, 44] = dataGridView1[43, i].Value + ""; //Truong042 wrksheet.Cells[h, 45] = dataGridView1[44, i].Value + ""; //Truong043 wrksheet.Cells[h, 46] = dataGridView1[45, i].Value + ""; //Truong044 wrksheet.Cells[h, 47] = dataGridView1[46, i].Value + ""; //Truong045 wrksheet.Cells[h, 48] = dataGridView1[47, i].Value + ""; //Truong046 wrksheet.Cells[h, 49] = dataGridView1[48, i].Value + ""; //Truong047 wrksheet.Cells[h, 50] = dataGridView1[49, i].Value + ""; //Truong048 wrksheet.Cells[h, 51] = dataGridView1[50, i].Value + ""; //Truong049 wrksheet.Cells[h, 52] = dataGridView1[51, i].Value + ""; //Truong050 wrksheet.Cells[h, 53] = dataGridView1[52, i].Value + ""; //Truong051 wrksheet.Cells[h, 54] = dataGridView1[53, i].Value + ""; //Truong052 wrksheet.Cells[h, 55] = dataGridView1[54, i].Value + ""; //Truong053 wrksheet.Cells[h, 56] = dataGridView1[55, i].Value + ""; //Truong054 wrksheet.Cells[h, 57] = dataGridView1[56, i].Value + ""; //Truong055 wrksheet.Cells[h, 58] = dataGridView1[57, i].Value + ""; //Truong056 wrksheet.Cells[h, 59] = dataGridView1[58, i].Value + ""; //Truong057 wrksheet.Cells[h, 60] = dataGridView1[59, i].Value + ""; //Truong058 wrksheet.Cells[h, 61] = dataGridView1[60, i].Value + ""; //Truong059 wrksheet.Cells[h, 62] = dataGridView1[61, i].Value + ""; //Truong060 wrksheet.Cells[h, 63] = dataGridView1[62, i].Value + ""; //Truong061 wrksheet.Cells[h, 64] = dataGridView1[63, i].Value + ""; //Truong062 wrksheet.Cells[h, 65] = dataGridView1[64, i].Value + ""; //Truong063 wrksheet.Cells[h, 66] = dataGridView1[65, i].Value + ""; //Truong064 wrksheet.Cells[h, 67] = dataGridView1[66, i].Value + ""; //Truong065 wrksheet.Cells[h, 68] = Truong66; //Truong066 wrksheet.Cells[h, 69] = dataGridView1[68, i].Value + ""; //Truong067 wrksheet.Cells[h, 70] = dataGridView1[69, i].Value + ""; //Truong068 wrksheet.Cells[h, 71] = dataGridView1[70, i].Value + ""; //Truong069 wrksheet.Cells[h, 72] = dataGridView1[71, i].Value + ""; //Truong070 wrksheet.Cells[h, 73] = dataGridView1[72, i].Value + ""; //Truong071 wrksheet.Cells[h, 74] = dataGridView1[73, i].Value + ""; //Truong072 wrksheet.Cells[h, 75] = dataGridView1[74, i].Value + ""; //Truong073 wrksheet.Cells[h, 76] = dataGridView1[75, i].Value + ""; //Truong074 wrksheet.Cells[h, 77] = dataGridView1[76, i].Value + ""; //Truong075 wrksheet.Cells[h, 78] = dataGridView1[77, i].Value + ""; //Truong076 wrksheet.Cells[h, 79] = dataGridView1[78, i].Value + ""; //Truong077 wrksheet.Cells[h, 80] = dataGridView1[79, i].Value + ""; //Truong078 wrksheet.Cells[h, 81] = dataGridView1[80, i].Value + ""; //Truong079 wrksheet.Cells[h, 82] = dataGridView1[81, i].Value + ""; //Truong080 wrksheet.Cells[h, 83] = dataGridView1[82, i].Value + ""; //Truong081 wrksheet.Cells[h, 84] = dataGridView1[83, i].Value + ""; //Truong082 wrksheet.Cells[h, 85] = dataGridView1[84, i].Value + ""; //Truong083 wrksheet.Cells[h, 86] = dataGridView1[85, i].Value + ""; //Truong084 wrksheet.Cells[h, 87] = dataGridView1[86, i].Value + ""; //Truong085 wrksheet.Cells[h, 88] = dataGridView1[87, i].Value + ""; //Truong086 wrksheet.Cells[h, 89] = dataGridView1[88, i].Value + ""; //Truong087 wrksheet.Cells[h, 90] = dataGridView1[89, i].Value + ""; //Truong088 wrksheet.Cells[h, 91] = dataGridView1[90, i].Value + ""; //Truong089 wrksheet.Cells[h, 92] = dataGridView1[91, i].Value + ""; //Truong090 wrksheet.Cells[h, 93] = dataGridView1[92, i].Value + ""; //Truong091 wrksheet.Cells[h, 94] = dataGridView1[93, i].Value + ""; //Truong092 wrksheet.Cells[h, 95] = dataGridView1[94, i].Value + ""; //Truong093 wrksheet.Cells[h, 96] = dataGridView1[95, i].Value + ""; //Truong094 wrksheet.Cells[h, 97] = dataGridView1[96, i].Value + ""; //Truong095 wrksheet.Cells[h, 98] = dataGridView1[97, i].Value + ""; //Truong096 wrksheet.Cells[h, 99] = dataGridView1[98, i].Value + ""; //Truong097 wrksheet.Cells[h, 100] = dataGridView1[99, i].Value + ""; //Truong098 wrksheet.Cells[h, 101] = dataGridView1[100, i].Value + ""; //Truong099 wrksheet.Cells[h, 102] = dataGridView1[101, i].Value + ""; //Truong100 wrksheet.Cells[h, 103] = dataGridView1[102, i].Value + ""; //Truong101 wrksheet.Cells[h, 104] = dataGridView1[103, i].Value + ""; //Truong102 wrksheet.Cells[h, 105] = dataGridView1[104, i].Value + ""; //Truong103 wrksheet.Cells[h, 106] = dataGridView1[105, i].Value + ""; //Truong104 wrksheet.Cells[h, 107] = dataGridView1[106, i].Value + ""; //Truong105 wrksheet.Cells[h, 108] = dataGridView1[107, i].Value + ""; //Truong106 wrksheet.Cells[h, 109] = dataGridView1[108, i].Value + ""; //Truong107 wrksheet.Cells[h, 110] = dataGridView1[109, i].Value + ""; //Truong108 wrksheet.Cells[h, 111] = dataGridView1[110, i].Value + ""; //Truong109 wrksheet.Cells[h, 112] = dataGridView1[111, i].Value + ""; //Truong110 wrksheet.Cells[h, 113] = dataGridView1[112, i].Value + ""; //Truong111 wrksheet.Cells[h, 114] = ""; //Truong112 lb_Complete.Text = (i + 1) + "/" + dataGridView1.RowCount; progressBar1.PerformStep(); h++; } Microsoft.Office.Interop.Excel.Range rowHead = wrksheet.get_Range("A1", "DJ" + (h - 1)); rowHead.Borders.LineStyle = Microsoft.Office.Interop.Excel.Constants.xlSolid; }
private void UpLoadSingle() { progressBar1.Step = 1; progressBar1.Value = 1; progressBar1.Maximum = _lFileNames.Length; progressBar1.Minimum = 0; ModifyProgressBarColor.SetState(progressBar1, 1); string sBatchID = (txt_BatchName.Text + txt_LoaiPhieu.Text + txt_DateCreate.Text).Replace("/", "").Replace(@"\", "").Replace(@":", "").Replace(@"-", ""); var batch = (from w in Global.Db.tbl_Batches.Where(w => w.BatchID == sBatchID) select w.BatchID).FirstOrDefault(); if (!string.IsNullOrEmpty(txt_ImagePath.Text)) { if (string.IsNullOrEmpty(batch)) { var fBatch = new tbl_Batch { BatchID = sBatchID, City = txt_LoaiPhieu.Text, BatchName = txt_BatchName.Text, UserCreate = txt_UserCreate.Text, DateCreate = DateTime.Now, PathPicture = txt_Location.Text, Location = txt_ImagePath.Text, NumberImage = soluonghinh.ToString(), ChiaUser = chk_ChiaUser.Checked ? true : false, CongKhaiBatch = false, Truong_005 = txt_Truong_005.Text, Truong_006 = txt_Truong_006.Text, Truong_016 = txt_Truong_016.Text, Truong_017 = txt_Truong_017.Text, }; Global.Db.tbl_Batches.InsertOnSubmit(fBatch); Global.Db.SubmitChanges(); } else { MessageBox.Show("Batch đã tồn tại vui lòng điền tên batch khác!"); return; } } else { MessageBox.Show("Bạn chưa chọn hình ảnh!"); return; } string temp = Global.StrPath + "\\" + sBatchID; if (!Directory.Exists(temp)) { Directory.CreateDirectory(temp); } else { MessageBox.Show("Bị trùng tên batch!"); return; } DataTable dt = new DataTable(); dt.Columns.AddRange(new[] { new DataColumn("ImageID", typeof(string)) }); for (int i = 0; i < _lFileNames.Count(); i++) { FileInfo fi = new FileInfo(_lFileNames[i]); dt.Rows.Add(fi.Name); } string ConnectionString = Global.Db.Connection.ConnectionString; SqlConnection con = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand("Insert_Image", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@BatchID", sBatchID); cmd.Parameters.AddWithValue("@City", txt_LoaiPhieu.Text + ""); cmd.Parameters.AddWithValue("@FileNameTXT", cbb_FileTXT.Text + ""); cmd.Parameters.AddWithValue("@ListIdImage", dt); cmd.Parameters.AddWithValue("@ChiaUser", chk_ChiaUser.Checked ? 1 : 0); con.Open(); cmd.ExecuteNonQuery(); for (int i = 0; i < _lFileNames.Count(); i++) { File.Copy(_lFileNames[i], temp + @"\" + new FileInfo(_lFileNames[i]).Name); progressBar1.PerformStep(); lb_SoImageDaHoanThanh.Text = (i + 1) + @"\" + _lFileNames.Count(); } txt_DateCreate.Text = DateTime.Now.ToShortDateString() + "-" + DateTime.Now.ToShortTimeString(); MessageBox.Show("Tạo batch mới thành công!"); txt_BatchName.Text = ""; txt_ImagePath.Text = ""; lb_SoLuongHinh.Text = ""; }
private void UpLoadMulti() { btn_Browser.Enabled = false; txt_PathFolder.Enabled = false; txt_Location.Enabled = false; List <string> lStrBath = new List <string>(); lStrBath.AddRange(Directory.GetDirectories(txt_PathFolder.Text)); int countBatchExists = 0; string listBatchExxists = ""; for (int i = 0; i < lStrBath.Count; i++) { sBatchID = (new DirectoryInfo(lStrBath[i]).Name + txt_LoaiPhieu.Text + txt_DateCreate.Text).Replace("/", "").Replace(@"\", "").Replace(@":", "").Replace(@"-", ""); batch = (from w in Global.Db.tbl_Batches.Where(w => w.BatchID == sBatchID) select w.BatchID).FirstOrDefault(); if (!string.IsNullOrEmpty(batch)) { countBatchExists += 1; listBatchExxists += lStrBath[i] + "\r\n"; } } if (countBatchExists > 0) { MessageBox.Show("Batch đã tồn tại :\r\n" + listBatchExxists); btn_Browser.Enabled = true; txt_PathFolder.Enabled = true; txt_Location.Enabled = true; return; } int n = 0; DataTable dt = new DataTable(); dt.Columns.AddRange(new[] { new DataColumn("ImageID", typeof(string)) }); foreach (string itemBatch in lStrBath) { dt.Clear(); string batchName = ""; int m = 0; batchName = (new DirectoryInfo(itemBatch).Name + txt_LoaiPhieu.Text + txt_DateCreate.Text).Replace("/", "").Replace(@"\", "").Replace(@":", "").Replace(@"-", ""); n += 1; lb_SobatchHoanThanh.Text = n + @" :"; var filters = new String[] { "jpg", "jpeg", "png", "gif", "tif", "bmp" }; string[] pathImageLocation = GetFilesFrom(itemBatch, filters, false); var fBatch = new tbl_Batch { BatchID = batchName, City = txt_LoaiPhieu.Text, BatchName = new DirectoryInfo(itemBatch).Name, UserCreate = txt_UserCreate.Text, DateCreate = DateTime.Now, PathPicture = txt_Location.Text, Location = txt_PathFolder.Text, NumberImage = pathImageLocation.Length + "", ChiaUser = chk_ChiaUser.Checked ? true : false, CongKhaiBatch = false, Truong_005 = txt_Truong_005.Text, Truong_006 = txt_Truong_006.Text, Truong_016 = txt_Truong_016.Text, Truong_017 = txt_Truong_017.Text, }; Global.Db.tbl_Batches.InsertOnSubmit(fBatch); Global.Db.SubmitChanges(); progressBar1.Step = 1; progressBar1.Value = 1; progressBar1.Maximum = pathImageLocation.Length; progressBar1.Minimum = 0; ModifyProgressBarColor.SetState(progressBar1, 1); for (int i = 0; i < pathImageLocation.Count(); i++) { FileInfo fi = new FileInfo(pathImageLocation[i]); dt.Rows.Add(fi.Name); } string ConnectionString = Global.Db.Connection.ConnectionString; SqlConnection con = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand("Insert_Image", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@BatchID", batchName); cmd.Parameters.AddWithValue("@City", txt_LoaiPhieu.Text + ""); cmd.Parameters.AddWithValue("@FileNameTXT", cbb_FileTXT.Text + ""); cmd.Parameters.AddWithValue("@ListIdImage", dt); cmd.Parameters.AddWithValue("@ChiaUser", chk_ChiaUser.Checked ? 1 : 0); con.Open(); cmd.ExecuteNonQuery(); string temp = Global.StrPath + "\\" + batchName; if (!Directory.Exists(temp)) { Directory.CreateDirectory(temp); } else { MessageBox.Show("Bị trùng tên batch!"); return; } for (int i = 0; i < pathImageLocation.Count(); i++) { File.Copy(pathImageLocation[i], temp + @"\" + new FileInfo(pathImageLocation[i]).Name); progressBar1.PerformStep(); lb_SoImageDaHoanThanh.Text = (i + 1) + @"\" + pathImageLocation.Count(); m += 1; } lb_SoImageDaHoanThanh.Text = m + @"/" + pathImageLocation.Length; progressBar1.PerformStep(); } MessageBox.Show(@"Tạo batch mới thành công!"); txt_BatchName.Text = ""; txt_ImagePath.Text = ""; lb_SoLuongHinh.Text = ""; txt_PathFolder.Text = ""; txt_LoaiPhieu.SelectedIndex = 0; //btn_CreateBatch.Enabled = true; btn_Browser.Enabled = true; txt_PathFolder.Enabled = true; txt_Location.Enabled = true; }
public void TableToExcel(string strfilename) { try { lb_SoLuong.Text = ""; progressBar1.Step = 1; progressBar1.Value = 1; progressBar1.Maximum = dataGridView1.RowCount + dataGridView2.RowCount + dataGridView3.RowCount + dataGridView4.RowCount + dataGridView5.RowCount + dataGridView6.RowCount; progressBar1.Minimum = 0; progressBar1.Visible = true; ModifyProgressBarColor.SetState(progressBar1, 1); app = new Microsoft.Office.Interop.Excel.Application(); book = app.Workbooks.Open(strfilename, 0, true, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); wrksheet = (Microsoft.Office.Interop.Excel.Worksheet)book.Sheets["Loại 1 CityN"]; int h = 1, n = 0; wrksheet.Cells[1, 1] = "BÁO CÁO HIỆU SUẤT DỰ ÁN BÁO CÁO LƯƠNG 2018 LOẠI 1 - CityN"; wrksheet.Cells[2, 10] = "Thời gian:" + timeFisrt.Text + "/" + dtp_FirstDay.Value.Day + "/" + dtp_FirstDay.Value.Month + "/" + dtp_FirstDay.Value.Year + " đến " + timeEnd.Text + "/" + dtp_EndDay.Value.Day + "/" + dtp_EndDay.Value.Month + "/" + dtp_EndDay.Value.Year; for (int i = 0; i < dataGridView1.RowCount; i++) { wrksheet.Cells[h + 2, 1] = h; wrksheet.Cells[h + 2, 2] = dataGridView1.Rows[i].Cells[0].Value + ""; //username wrksheet.Cells[h + 2, 3] = dataGridView1.Rows[i].Cells[1].Value + ""; //fullname wrksheet.Cells[h + 2, 4] = dataGridView1.Rows[i].Cells[2].Value + ""; //tong wrksheet.Cells[h + 2, 5] = dataGridView1.Rows[i].Cells[3].Value + ""; //phieudung wrksheet.Cells[h + 2, 6] = dataGridView1.Rows[i].Cells[4].Value + ""; //phieusai wrksheet.Cells[h + 2, 7] = dataGridView1.Rows[i].Cells[5].Value + ""; //thoigian wrksheet.Cells[h + 2, 8] = dataGridView1.Rows[i].Cells[6].Value + ""; //hieusuat h++; progressBar1.PerformStep(); lb_SoLuong.Text = ++n + @"\" + progressBar1.Maximum; } wrksheet = (Microsoft.Office.Interop.Excel.Worksheet)book.Sheets["Loại 3 CityN"]; h = 1; wrksheet.Cells[1, 1] = "BÁO CÁO HIỆU SUẤT DỰ ÁN BÁO CÁO LƯƠNG 2018 LOẠI 3 - CityN"; wrksheet.Cells[2, 10] = "Thời gian:" + timeFisrt.Text + "/" + dtp_FirstDay.Value.Day + "/" + dtp_FirstDay.Value.Month + "/" + dtp_FirstDay.Value.Year + " đến " + timeEnd.Text + "/" + dtp_EndDay.Value.Day + "/" + dtp_EndDay.Value.Month + "/" + dtp_EndDay.Value.Year; for (int i = 0; i < dataGridView2.RowCount; i++) { wrksheet.Cells[h + 2, 1] = h; wrksheet.Cells[h + 2, 2] = dataGridView2.Rows[i].Cells[0].Value + ""; //username wrksheet.Cells[h + 2, 3] = dataGridView2.Rows[i].Cells[1].Value + ""; //fullname wrksheet.Cells[h + 2, 4] = dataGridView2.Rows[i].Cells[2].Value + ""; //tong wrksheet.Cells[h + 2, 5] = dataGridView2.Rows[i].Cells[3].Value + ""; //phieudung wrksheet.Cells[h + 2, 6] = dataGridView2.Rows[i].Cells[4].Value + ""; //phieusai wrksheet.Cells[h + 2, 7] = dataGridView2.Rows[i].Cells[5].Value + ""; //thoigian wrksheet.Cells[h + 2, 8] = dataGridView2.Rows[i].Cells[6].Value + ""; //hieusuat h++; progressBar1.PerformStep(); lb_SoLuong.Text = ++n + @"\" + progressBar1.Maximum; } wrksheet = (Microsoft.Office.Interop.Excel.Worksheet)book.Sheets["Loại JP CityN"]; h = 1; wrksheet.Cells[1, 1] = "BÁO CÁO HIỆU SUẤT DỰ ÁN BÁO CÁO LƯƠNG 2018 DEJP - CityN"; wrksheet.Cells[2, 10] = "Thời gian:" + timeFisrt.Text + "/" + dtp_FirstDay.Value.Day + "/" + dtp_FirstDay.Value.Month + "/" + dtp_FirstDay.Value.Year + " đến " + timeEnd.Text + "/" + dtp_EndDay.Value.Day + "/" + dtp_EndDay.Value.Month + "/" + dtp_EndDay.Value.Year; for (int i = 0; i < dataGridView3.RowCount; i++) { wrksheet.Cells[h + 2, 1] = h; wrksheet.Cells[h + 2, 2] = dataGridView3.Rows[i].Cells[0].Value + ""; //username wrksheet.Cells[h + 2, 3] = dataGridView3.Rows[i].Cells[1].Value + ""; //fullname wrksheet.Cells[h + 2, 4] = dataGridView3.Rows[i].Cells[2].Value + ""; //tong wrksheet.Cells[h + 2, 5] = dataGridView3.Rows[i].Cells[3].Value + ""; //phieudung wrksheet.Cells[h + 2, 6] = dataGridView3.Rows[i].Cells[4].Value + ""; //phieusai wrksheet.Cells[h + 2, 7] = dataGridView3.Rows[i].Cells[5].Value + ""; //thoigian wrksheet.Cells[h + 2, 8] = dataGridView3.Rows[i].Cells[6].Value + ""; //hieusuat h++; progressBar1.PerformStep(); lb_SoLuong.Text = ++n + @"\" + progressBar1.Maximum; } wrksheet = (Microsoft.Office.Interop.Excel.Worksheet)book.Sheets["Loại 1 CityO"]; h = 1; wrksheet.Cells[1, 1] = "BÁO CÁO HIỆU SUẤT DỰ ÁN BÁO CÁO LƯƠNG 2018 LOẠI 1 - CityO"; wrksheet.Cells[2, 10] = "Thời gian:" + timeFisrt.Text + "/" + dtp_FirstDay.Value.Day + "/" + dtp_FirstDay.Value.Month + "/" + dtp_FirstDay.Value.Year + " đến " + timeEnd.Text + "/" + dtp_EndDay.Value.Day + "/" + dtp_EndDay.Value.Month + "/" + dtp_EndDay.Value.Year; for (int i = 0; i < dataGridView4.RowCount; i++) { wrksheet.Cells[h + 2, 1] = h; wrksheet.Cells[h + 2, 2] = dataGridView4.Rows[i].Cells[0].Value + ""; //username wrksheet.Cells[h + 2, 3] = dataGridView4.Rows[i].Cells[1].Value + ""; //fullname wrksheet.Cells[h + 2, 4] = dataGridView4.Rows[i].Cells[2].Value + ""; //tong wrksheet.Cells[h + 2, 5] = dataGridView4.Rows[i].Cells[3].Value + ""; //phieudung wrksheet.Cells[h + 2, 6] = dataGridView4.Rows[i].Cells[4].Value + ""; //phieusai wrksheet.Cells[h + 2, 7] = dataGridView4.Rows[i].Cells[5].Value + ""; //thoigian wrksheet.Cells[h + 2, 8] = dataGridView4.Rows[i].Cells[6].Value + ""; //hieusuat h++; progressBar1.PerformStep(); lb_SoLuong.Text = ++n + @"\" + progressBar1.Maximum; } wrksheet = (Microsoft.Office.Interop.Excel.Worksheet)book.Sheets["Loại 3 CityO"]; h = 1; wrksheet.Cells[1, 1] = "BÁO CÁO HIỆU SUẤT DỰ ÁN BÁO CÁO LƯƠNG 2018 LOẠI 3 - CityO"; wrksheet.Cells[2, 10] = "Thời gian:" + timeFisrt.Text + "/" + dtp_FirstDay.Value.Day + "/" + dtp_FirstDay.Value.Month + "/" + dtp_FirstDay.Value.Year + " đến " + timeEnd.Text + "/" + dtp_EndDay.Value.Day + "/" + dtp_EndDay.Value.Month + "/" + dtp_EndDay.Value.Year; for (int i = 0; i < dataGridView5.RowCount; i++) { wrksheet.Cells[h + 2, 1] = h; wrksheet.Cells[h + 2, 2] = dataGridView5.Rows[i].Cells[0].Value + ""; //username wrksheet.Cells[h + 2, 3] = dataGridView5.Rows[i].Cells[1].Value + ""; //fullname wrksheet.Cells[h + 2, 4] = dataGridView5.Rows[i].Cells[2].Value + ""; //tong wrksheet.Cells[h + 2, 5] = dataGridView5.Rows[i].Cells[3].Value + ""; //phieudung wrksheet.Cells[h + 2, 6] = dataGridView5.Rows[i].Cells[4].Value + ""; //phieusai wrksheet.Cells[h + 2, 7] = dataGridView5.Rows[i].Cells[5].Value + ""; //thoigian wrksheet.Cells[h + 2, 8] = dataGridView5.Rows[i].Cells[6].Value + ""; //hieusuat h++; progressBar1.PerformStep(); lb_SoLuong.Text = ++n + @"\" + progressBar1.Maximum; } wrksheet = (Microsoft.Office.Interop.Excel.Worksheet)book.Sheets["Loại JP CityO"]; h = 1; wrksheet.Cells[1, 1] = "BÁO CÁO HIỆU SUẤT DỰ ÁN BÁO CÁO LƯƠNG 2018 DEJP - CityO"; wrksheet.Cells[2, 10] = "Thời gian:" + timeFisrt.Text + "/" + dtp_FirstDay.Value.Day + "/" + dtp_FirstDay.Value.Month + "/" + dtp_FirstDay.Value.Year + " đến " + timeEnd.Text + "/" + dtp_EndDay.Value.Day + "/" + dtp_EndDay.Value.Month + "/" + dtp_EndDay.Value.Year; for (int i = 0; i < dataGridView6.RowCount; i++) { wrksheet.Cells[h + 2, 1] = h; wrksheet.Cells[h + 2, 2] = dataGridView6.Rows[i].Cells[0].Value + ""; //username wrksheet.Cells[h + 2, 3] = dataGridView6.Rows[i].Cells[1].Value + ""; //fullname wrksheet.Cells[h + 2, 4] = dataGridView6.Rows[i].Cells[2].Value + ""; //tong wrksheet.Cells[h + 2, 5] = dataGridView6.Rows[i].Cells[3].Value + ""; //phieudung wrksheet.Cells[h + 2, 6] = dataGridView6.Rows[i].Cells[4].Value + ""; //phieusai wrksheet.Cells[h + 2, 7] = dataGridView6.Rows[i].Cells[5].Value + ""; //thoigian wrksheet.Cells[h + 2, 8] = dataGridView6.Rows[i].Cells[6].Value + ""; //hieusuat h++; progressBar1.PerformStep(); lb_SoLuong.Text = ++n + @"\" + progressBar1.Maximum; } string savePath; saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Title = @"Save Excel Files"; saveFileDialog1.Filter = @"Excel files (*.xlsx)|*.xlsx"; saveFileDialog1.FileName = "NangSuat_BaoCaoLuong2018_" + dtp_FirstDay.Value.Day + "-" + dtp_EndDay.Value.Day; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { book.SaveCopyAs(saveFileDialog1.FileName); book.Saved = true; savePath = Path.GetDirectoryName(saveFileDialog1.FileName); } else { MessageBox.Show(@"Error exporting excel!"); return; } if (savePath != null) { Process.Start(savePath); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } finally { progressBar1.Visible = false; lb_SoLuong.Text = ""; if (book != null) { book.Close(false); } if (app != null) { app.Quit(); } if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Productivity.xlsx")) { File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Productivity.xlsx"); } if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + saveFileDialog1.FileName)) { File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + saveFileDialog1.FileName); } } }