修改导入excel

This commit is contained in:
2024-04-15 11:28:07 +08:00
parent 6af70591bc
commit d826a6369a
3 changed files with 126 additions and 14 deletions
@@ -202,7 +202,18 @@ namespace FineUIPro.Web.CQMS.ManageReportNew
Model.SGGLDB db = Funs.DB;
initTemplatePath = Const.MonthReportNewTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
newUrl = uploadfilepath.Replace(".doc", "(" + Funs.GetNewFileName() + ")" + ".doc");
//newUrl = uploadfilepath.Replace(".doc", "(" + Funs.GetNewFileName() + ")" + ".doc");
//名称XX项目质量月报第几期
//根据id获取质量月报主表数据
var weekModel = db.Report_WeekAndMonthReport_New.FirstOrDefault(x => x.Id == Id);
var startDate = Convert.ToDateTime(weekModel.StartDate);
var endDate = Convert.ToDateTime(weekModel.EndDate);
//获取project
var pModel = db.Base_Project.FirstOrDefault(x => x.ProjectId == weekModel.ProjectId);
newUrl = uploadfilepath.Replace("项目质量月报", pModel.ShortName + "项目质量月报(第"+ weekModel.SortId + "期)");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
@@ -212,21 +223,29 @@ namespace FineUIPro.Web.CQMS.ManageReportNew
Document doc = new Aspose.Words.Document(newUrl);
DocumentBuilder builder = new DocumentBuilder(doc);
//根据id获取质量月报主表数据
var weekModel= db.Report_WeekAndMonthReport_New.FirstOrDefault(x => x.Id == Id);
var startDate = Convert.ToDateTime(weekModel.StartDate);
var endDate = Convert.ToDateTime(weekModel.EndDate);
//获取project
var pModel = db.Base_Project.FirstOrDefault(x => x.ProjectId == weekModel.ProjectId);
#region
//业主单位
var unitsYz = (from x in db.Base_Unit
join y in db.Project_ProjectUnit
on x.UnitId equals y.UnitId
where y.ProjectId == this.CurrUser.LoginProjectId && y.UnitType == BLL.Const.ProjectUnitType_4
orderby x.UnitName
select x).FirstOrDefault();
Bookmark bkmark = doc.Range.Bookmarks["username"];
if (bkmark != null) {
var uModel = db.Sys_User.FirstOrDefault(x => x.UserId == weekModel.CreateMan);
if (uModel!=null)
if (unitsYz != null)
{
bkmark.Text = uModel.UserName;
bkmark.Text = unitsYz.UnitName;
}
//var uModel = db.Sys_User.FirstOrDefault(x => x.UserId == weekModel.CreateMan);
//if (uModel!=null)
//{
// bkmark.Text = uModel.UserName;
//}
}
bkmark= doc.Range.Bookmarks["projectNo"];
@@ -244,7 +263,7 @@ namespace FineUIPro.Web.CQMS.ManageReportNew
bkmark = doc.Range.Bookmarks["projectname"];
if (bkmark != null)
{
bkmark.Text = pModel.ProjectName+"("+ pModel.ProjectCode + ")";
bkmark.Text = pModel.ProjectName;
}
bkmark = doc.Range.Bookmarks["quamanagername"];
@@ -341,6 +360,13 @@ namespace FineUIPro.Web.CQMS.ManageReportNew
{
bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "2").ContentText;
}
bkmark = doc.Range.Bookmarks["Content8"];
if (bkmark != null)
{
bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "8").ContentText;
}
#endregion
var ContuructionAllList = db.Report_Construction_Plan.Where(x => x.ReportId == Id).OrderBy(x=>x.UnitOrMajor).ToList();
@@ -1140,6 +1166,66 @@ namespace FineUIPro.Web.CQMS.ManageReportNew
//自动设置表格样式
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
}
else {
whileIndex += 1;
}
#endregion
#region 8.
var sbclbyList = ContuructionAllList.Where(x => x.ReType == "6").ToList();
if (pqrList.Count > 0)
{
isYm = true;
whileIndex += 1;
table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true);
//跳过页眉的表头
while (isYm)
{
//获取到第一列是序号的列
if (table.Range.Text.Substring(0, 2) != "序号")
{
whileIndex += 1;
table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true);
}
else
{
isYm = false;
}
}
numberIndex = 1;
int? num1 = 0, num2 = 0;
foreach (var item in sbclbyList)
{
//创建行
Row row = new Row(doc);
row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width));
row.Cells.Add(CreateCell(item.UnitOrMajor, doc, table.FirstRow.Cells[1].CellFormat.Width));
row.Cells.Add(CreateCell(item.Quantity1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width));
row.Cells.Add(CreateCell(item.Quantity2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width));
row.Cells.Add(CreateCell(item.QuaRate.ToString(), doc, table.FirstRow.Cells[4].CellFormat.Width));
row.Cells.Add(CreateCell(item.Remarks, doc, table.FirstRow.Cells[5].CellFormat.Width));
table.Rows.Insert(numberIndex, row);
num1 += item.Quantity1;
num2 += item.Quantity2;
numberIndex += 1;
}
//自动设置表格样式
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
//创建合计
//创建行
Row rowhj = new Row(doc);
rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[0].CellFormat.Width));
rowhj.Cells.Add(CreateCell("合计", doc, table.FirstRow.Cells[1].CellFormat.Width));
rowhj.Cells.Add(CreateCell(num1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width));
rowhj.Cells.Add(CreateCell(num2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width));
rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[4].CellFormat.Width));
rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[5].CellFormat.Width));
table.Rows.Insert(numberIndex, rowhj);
//自动设置表格样式
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
}
#endregion
@@ -2892,6 +2978,31 @@ namespace FineUIPro.Web.CQMS.ManageReportNew
}
#endregion
#region
whileIndex = 1;
table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 1, true);
//业主名称
table.Rows[0].Cells[2].FirstParagraph.Runs[0].Text = unitsYz.UnitName;
//项目号
table.Rows[0].Cells[4].FirstParagraph.Runs[0].Text = pModel.ProjectCode;
//项目名称
table.Rows[2].Cells[2].FirstParagraph.Runs[0].Text = pModel.ProjectName;
table.Rows[2].Cells[3].FirstParagraph.Runs[0].Text = pModel.ProjectCode + "-RM-PQM-" + weekModel.SortId;
//总页数
table.Rows[4].Cells[5].FirstParagraph.Runs[0].Text = doc.PageCount.ToString();
//页眉是第二个表
//tableIndex—要移动的表的索引。
//rowIndex - 表中行的索引。
//columnIndex—表中列的索引。
//字符在单元格中的索引。目前只能指定0移动到单元格的开头,或指定 - 1移动到单元格的结尾。
//builder.MoveToCell(1,0,2,0);
//builder.Write(unitsYz.UnitName);
#endregion
doc.Save(newUrl);
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);