private void ExportToExcel(string filePath) { if (dataLoad == null || dataLoad.Count == 0 || filepath == string.Empty) { return; } statusMain.Invoke(new MethodInvoker(delegate { progressBarImport.Value = 0; lbPercent.Text = "0%"; })); statusMain.Invoke(new MethodInvoker(delegate { lbOperation.Text = "Export to excel..."; })); int pos = filePath.LastIndexOf('.'); string x1 = filePath.Substring(0, pos); string x2 = filePath.Substring(pos + 1, filePath.Length - pos - 1); string[] file = new string[] { x1, x2 }; string path = string.Empty; string name = string.Empty; string extension = string.Empty; if (file != null && file.Length > 1) { extension = file[1]; int a = file[0].LastIndexOf("\\"); if (a > 2) { path = file[0].Substring(0, a); name = file[0].Substring(a + 1, file[0].Length - a - 1); } } if (path.Length > 0 && name.Length > 0 && extension.Length > 0) { int totalFile = 0; if (dataLoad.Count % Core.LimitDisplayExportExcel == 0) { totalFile = dataLoad.Count / Core.LimitDisplayExportExcel; } else { totalFile = dataLoad.Count / Core.LimitDisplayExportExcel + 1; } int serial = 0; int index = 0; while (index < dataLoad.Count) { serial++; var datax = dataLoad.Skip(index).Take(Core.LimitDisplayExportExcel).ToList(); index += Core.LimitDisplayExportExcel; string pathFull = $"{path}\\{name}-{serial.ToString().PadLeft(3, '0')}.{extension}"; bool check = WriteReportHelper.ExportPreClaimMatching(datax, pathFull); datax = null; GC.Collect(); statusMain.Invoke(new MethodInvoker(delegate { if (serial > totalFile) { serial = totalFile; } float values = (float)serial / (float)totalFile * 100; progressBarImport.Value = (int)values; lbPercent.Text = $"{((int)values).ToString()}%"; })); } } statusMain.Invoke(new MethodInvoker(delegate { lbOperation.Text = "Export to excel be finish"; })); toolMain.Invoke(new MethodInvoker(delegate { btnExport.Enabled = true; })); statusMain.Invoke(new MethodInvoker(delegate { progressBarImport.Value = 100; })); }