public void ExportToExcel(string SaveFileName) { Excel mexportExcel = new Excel(SaveFileName, false); string datetime = DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString() + " " + DateTime.Now.Hour.ToString() + "'" + DateTime.Now.Minute.ToString() + "'" + DateTime.Now.Second.ToString(); string sheetname = "计算转正天数" + datetime; mexportExcel.AddWorksheet(sheetname); mexportExcel.SetCurrentWorksheet(sheetname); for (int i = 0; i < AssessSourcecollection.Count; i++) { if (AssessSourcecollection[i].TimePercent == "无") { continue; } mexportExcel.SetCell(i + 1, 1, AssessSourcecollection[i].OrderNumber.ToString()); mexportExcel.SetCell(i + 1, 2, AssessSourcecollection[i].StaffName); mexportExcel.SetCell(i + 1, 3, AssessSourcecollection[i].StaffDep); mexportExcel.SetCell(i + 1, 4, AssessSourcecollection[i].StaffPostion); mexportExcel.SetSelFormatText(i + 1, 5); mexportExcel.SetCell(i + 1, 5, AssessSourcecollection[i].TimePercent); mexportExcel.SetCell(i + 1, 6, AssessSourcecollection[i].mNewStaffSalary.ProbationSalary); mexportExcel.SetCell(i + 1, 7, AssessSourcecollection[i].mNewStaffSalary.FullSalary); mexportExcel.SetCell(i + 1, 8, AssessSourcecollection[i].mNewStaffSalary.balance); mexportExcel.SetCell(i + 1, 9, AssessSourcecollection[i].CompanyInfo); } for (int i = 1; i < 10; i++) { mexportExcel.ColumnAutoFit(1, i); } mexportExcel.SaveAs2003(SaveFileName); mexportExcel.Save(); mexportExcel.Visible = true; }
public void SetInMemory(Action <int> percent) { int ProcessPos = 0; mExcel = new Excel(ExportFile, false); int sheetnums = WaitQuerySheets.Count; float proc = (float)0.0; foreach (string SheetName in WaitQuerySheets) { proc = (float)ProcessPos / (float)sheetnums * (float)100; mExcel.SetCurrentWorksheet(SheetName); //mExcel.SetCurrentWorksheet("Test"); #region start import excel for (int i = 1; i <= mExcel.RowCount; i++) { string LineInfo = mExcel.GetCell(i, 1); if (LineInfo.IndexOf(splitchar) != -1) { string[] ProjectLineInfos = LineInfo.Split(splitchar); ProjectInfo mtempProjectInfo = new ProjectInfo(); mtempProjectInfo.ProjectName = ProjectLineInfos[0]; mtempProjectInfo.ProjectId = ProjectLineInfos[1].Equals("") ? mtempProjectInfo.ProjectName : ProjectLineInfos[1]; LineInfo = mExcel.GetCell(++i, 1); //读取姓名,部门,加班费 while (!LineInfo.Equals("")) { ProjectStruct mtempProjectStruct = new ProjectStruct(); i++; LineInfo = mExcel.GetCell(i, 1); //读取姓名,部门,加班费 if (LineInfo.Equals("")) { break; } for (int j = 1; j <= ProjectInfoNumbers; j++) { float money; if (j == 1) { mtempProjectStruct.ProjectStaffName = mExcel.GetCell(i, j); } else if (j == 2) { mtempProjectStruct.ProjectStaffDep = mExcel.GetCell(i, j); } else if (j == 3) { float.TryParse(mExcel.GetCell(i, j), out money); mtempProjectStruct.ProjectStaffMoney = money; } } mtempProjectInfo.MyProjectDetailCollection.Add(mtempProjectStruct); } mProjectInfoArray.Add(mtempProjectInfo); } else { continue; } } #endregion start import excel ProcessPos++; percent((int)proc); // break;test } GetTargetResult(); percent((int)proc); }
public void SetInMemory(Action <int> percent) { int ProcessPos = 0; mExcel = new Excel(ExportFile, false); int sheetnums = WaitQuerySheets.Count; float proc = (float)0.0; foreach (string SheetName in WaitQuerySheets) { proc = (float)ProcessPos / (float)sheetnums * (float)100; mExcel.SetCurrentWorksheet(SheetName); //mExcel.SetCurrentWorksheet("Test"); #region start import excel for (int i = 1; i <= mExcel.RowCount; i++) { string LineInfo = mExcel.GetCell(i, 1); if (LineInfo.IndexOf("项目名称") != -1 && LineInfo.IndexOf(splitchar) == -1) { MessageBox.Show("Sheet " + SheetName + "第" + i + "行 格式不正确(缺少" + splitchar + ")"); mExcel.SetCellSelect(i, 1, i, 1); mExcel.Visible = true; System.Environment.Exit(0); } if (LineInfo.IndexOf(splitchar) != -1) { string[] ProjectLineInfos = LineInfo.Split(splitchar); ProjectInfo mtempProjectInfo = new ProjectInfo(); mtempProjectInfo.ProjectName = ProjectLineInfos[0].Trim(); mtempProjectInfo.ProjectId = ProjectLineInfos[1].Trim().Equals("") ? mtempProjectInfo.ProjectName : ProjectLineInfos[1].Trim(); LineInfo = mExcel.GetCell(++i, 1); //读取姓名,部门,加班费 while (!LineInfo.Equals("")) { ProjectStruct mtempProjectStruct = new ProjectStruct(); i++; LineInfo = mExcel.GetCell(i, 1); //读取姓名,部门,加班费 real value if (LineInfo.Equals("")) { break; } for (int j = 1; j <= ProjectInfoNumbers; j++) { float money; if (j == 1) { mtempProjectStruct.ProjectStaffName = mExcel.GetCell(i, j); } else if (j == 2) { mtempProjectStruct.ProjectStaffDep = mExcel.GetCell(i, j); } else if (j == 3) { float.TryParse(mExcel.GetCell(i, j), out money); mtempProjectStruct.ProjectStaffMoney = money; } } mtempProjectInfo.MyProjectDetailCollection.Add(mtempProjectStruct); } mProjectInfoArray.Add(mtempProjectInfo); } else { continue; } } #endregion start import excel ProcessPos++; percent((int)proc); // break;test } GetTargetResult(); percent((int)proc); ExcelOutResult(); ProcessPos++; percent(100); // MessageBox.Show("合并完成!"); mExcel.Visible = true; }
public void DoWorkCalThread(Action <int> percent) { mExcel = new Excel(SalaryFile, false); mExcel.SetCurrentWorksheet(SalaryDate); percent(10); float proc = (float)0.0000; for (int i = 2; i <= mExcel.RowCount; i++) { NewStaffSalary mAssessSource = new NewStaffSalary(); mAssessSource.StaffName = mExcel.GetCell(i, 2); mAssessSource.ProbationSalary = mExcel.GetCell(i, 8); mAssessSource.FullSalary = mExcel.GetCell(i, 9); NewStaffSalaryList.Add(mAssessSource); proc = (float)i / (float)mExcel.RowCount * (float)100; percent((int)proc); } int ProcessPos = 0; AssessSourcecollection.Clear(); mExcel = new Excel(ExportFile, false); mExcel.SetCurrentWorksheet(Date); percent(10); for (int i = 2; i <= mExcel.RowCount; i++) { AssessSource mAssessSource = new AssessSource(); mAssessSource.OrderNumber = i - 1; mAssessSource.StaffName = mExcel.GetCell(i, 1); mAssessSource.StaffDep = mExcel.GetCell(i, 2); mAssessSource.StaffPostion = mExcel.GetCell(i, 3); mAssessSource.EntryTime = mExcel.GetCell(i, 4); mAssessSource.EndTime = mExcel.GetCell(i, 5); mAssessSource.PositiveTime = mExcel.GetCell(i, 6); mAssessSource.CompanyInfo = mExcel.GetCell(i, 10); FillmAssessSourceSalary(ref mAssessSource); string tempre = mAssessSource.GetTimePercent(DateXiuxiRi, Date); if (tempre != "") { mExcel.SetCellComment(i, 6, tempre); } AssessSourcecollection.Add(mAssessSource); } percent(70); SortByCompanyAndPercent(); string tempzhuanzheng = ""; mExcel.Save(); mExcel.Visible = true; tempzhuanzheng = mIniFile.IniReadValue("AssessFile", "转正导出文件", tempzhuanzheng); ExportToExcel(AppDomain.CurrentDomain.BaseDirectory + tempzhuanzheng); percent(100); mExcel.Clean(); mExcel.Dispose(); }
public void SetInMemory(Action <int> percent) { int ProcessPos = 0; mExcel = new Excel(ExportFile, false); int sheetnums = WaitQuerySheets.Count; float proc = (float)0.0; string SheetName = "vbx"; mExcel.SetCurrentWorksheet(SheetName); //mExcel.SetCurrentWorksheet("Test"); #region start import excel for (int i = 3; i <= mExcel.RowCount; i++) { string LineInfo = mExcel.GetCell(i, 1); if (!String.IsNullOrEmpty(LineInfo)) { string[] ProjectLineInfos = LineInfo.Split(splitchar); ProjectInfo mtempProjectInfo = new ProjectInfo(); mtempProjectInfo.ProID = mExcel.GetCell(i, 1); mtempProjectInfo.ProSeriesID = mExcel.GetCell(i, 2); LineInfo = mExcel.GetCell(i + 1, 1); //读取姓名,部门,加班费 int j = i; int times = 0; while (String.IsNullOrEmpty(LineInfo)) { if (times == 0) { mtempProjectInfo.ProductDescription = mExcel.GetCell(j, 3); times++; j++; continue; } else if (times == 1) { mtempProjectInfo.SubProductDescription = mExcel.GetCell(j, 3); times++; j++; continue; } ProductDescriptionDetail tt = new ProductDescriptionDetail(); int outint = -1; int.TryParse(mExcel.GetCell(j, 3), out outint); if (outint == -1) { j++; LineInfo = mExcel.GetCell(j, 1); continue; } tt.count = outint; tt.ProductDetail = mExcel.GetCell(j, 4); if (tt.ProductDetail == "") { LineInfo = mExcel.GetCell(j, 2); j++; continue; } mtempProjectInfo.ProductDescriptionDetail.Add(tt); LineInfo = mExcel.GetCell(j, 1); j++; } mProjectInfoArray.Add(mtempProjectInfo); } else { continue; } } #endregion start import excel ProcessPos++; percent((int)proc); // break;test GetTargetResult(); percent((int)proc); ExcelOutResult(); ProcessPos++; percent(100); // MessageBox.Show("合并完成!"); mExcel.Visible = true; }