增加日志及工效导出功能

This commit is contained in:
高飞 2023-11-06 16:28:02 +08:00
parent 431c62a9a5
commit 9600736804
26 changed files with 4070 additions and 19 deletions

View File

@ -3427,7 +3427,26 @@ namespace BLL
/// 合同价格信息导入模板
/// </summary>
public const string TemContractTrackTemplateUrl = "File\\Excel\\DataIn\\合同价格信息导入模板.xlsx";
/// <summary>
/// 施工日志模板文件原始虚拟路径
/// </summary>
public const string ConstructionLogTemplateUrl = "File\\Excel\\ConstructionLog\\施工日志.xlsx";
/// <summary>
/// 日工效汇总表模板文件原始虚拟路径
/// </summary>
public const string DayConstructionLogWorkEfficiencyTemplateUrl = "File\\Excel\\ConstructionLog\\日工效汇总表.xlsx";
/// <summary>
/// 月工效汇总表模板文件原始虚拟路径
/// </summary>
public const string MonthConstructionLogWorkEfficiencyTemplateUrl = "File\\Excel\\ConstructionLog\\月工效汇总表.xlsx";
/// <summary>
/// 项目平均工效模板文件原始虚拟路径
/// </summary>
public const string ProjectConstructionLogWorkEfficiencyTemplateUrl = "File\\Excel\\ConstructionLog\\项目平均工效.xlsx";
/// <summary>
/// 公司平均工效统计模板文件原始虚拟路径
/// </summary>
public const string CompanyConstructionLogWorkEfficiencyTemplateUrl = "File\\Excel\\ConstructionLog\\公司平均工效统计.xlsx";
#endregion
#region

View File

@ -339,6 +339,29 @@ namespace BLL
return list;
}
public static string GetMajorName(string majorIds)
{
string majorName = string.Empty;
if (!string.IsNullOrEmpty(majorIds))
{
string[] strs = majorIds.Split(',');
var items = GetMajorItems2();
foreach (var item in strs)
{
var un = items.FirstOrDefault(x => x.Text == item);
if (un != null)
{
majorName += un.Value + ",";
}
}
if (!string.IsNullOrEmpty(majorName))
{
majorName = majorName.Substring(0, majorName.LastIndexOf(","));
}
}
return majorName;
}
#region
/// <summary>

View File

@ -205,5 +205,26 @@ namespace BLL
}
}
public static string GetContractName(string contractIds)
{
string contractName = string.Empty;
if (!string.IsNullOrEmpty(contractIds))
{
string[] strs = contractIds.Split(',');
foreach (var item in strs)
{
var cn = GetContractById(item);
if (cn != null)
{
contractName += cn.ContractName + ",";
}
}
if (!string.IsNullOrEmpty(contractName))
{
contractName = contractName.Substring(0, contractName.LastIndexOf(","));
}
}
return contractName;
}
}
}

View File

@ -35,6 +35,9 @@
<f:Button ID="btnSave" Icon="SystemSave" runat="server" ToolTip="保存" Text="保存"
OnClick="btnSave_Click">
</f:Button>
<f:Button ID="btnOut" OnClick="btnOut_Click" runat="server" Text="导出" Icon="FolderUp"
EnableAjax="false" DisableControlBeforePostBack="false">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>

View File

@ -1,8 +1,10 @@
using BLL;
using Newtonsoft.Json.Linq;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web.UI.WebControls;
@ -270,5 +272,170 @@ namespace FineUIPro.Web.PZHGL.InformationProject
}
}
#endregion
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
if (this.Grid1.Rows.Count == 0)
{
Alert.ShowInTop("无数据可导出!", MessageBoxIcon.Warning);
return;
}
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
string filePath = string.Empty;
initTemplatePath = Const.CompanyConstructionLogWorkEfficiencyTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
Model.SGGLDB db = Funs.DB;
var projects = (from x in db.Base_Project
where x.ProjectState == null || x.ProjectState == BLL.Const.ProjectState_1
select x).ToList();
newUrl = uploadfilepath.Replace(".xlsx", "(" + string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ")" + ".xlsx");
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle0.WrapText = true;
var font = workbook.CreateFont();
font.FontHeightInPoints = 16;
font.IsBold = true;
cellStyle0.SetFont(font);
NPOI.SS.UserModel.ICellStyle cellStyle1 = workbook.CreateCellStyle();
cellStyle1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle1.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle1.WrapText = true;
var font1 = workbook.CreateFont();
font1.FontHeightInPoints = 11;
font1.IsBold = true;
cellStyle1.SetFont(font1);
NPOI.SS.UserModel.ICellStyle cellStyle2 = workbook.CreateCellStyle();
cellStyle2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle2.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle2.WrapText = true;
var font0 = workbook.CreateFont();
font0.FontHeightInPoints = 11;
font0.IsBold = false;
cellStyle2.SetFont(font0);
NPOI.SS.UserModel.ICellStyle cellStyle3 = workbook.CreateCellStyle();
cellStyle3.BorderTop = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderLeft = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
cellStyle3.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
//cellStyle3.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
//cellStyle3.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
cellStyle3.WrapText = true;
var font3 = workbook.CreateFont();
font3.FontHeightInPoints = 11;
font3.IsBold = true;
cellStyle3.SetFont(font3);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row1 = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell3;
cell3 = row1.CreateCell(0);
cell3.CellStyle = cellStyle0;
cell3.SetCellValue("公司平均工效统计");
cell3 = row1.CreateCell(4 + projects.Count);
cell3.CellStyle = cellStyle0;
sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 4 + projects.Count));
row1 = sheet.GetRow(1);
cell3 = row1.CreateCell(5);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("工效统计");
for (int i = 1; i < projects.Count; i++)
{
cell3 = row1.CreateCell(5 + i);
cell3.CellStyle = cellStyle1;
}
sheet.AddMergedRegion(new CellRangeAddress(1, 1, 5, 4 + projects.Count));
row1 = sheet.GetRow(2);
for (int i = 0; i < projects.Count; i++)
{
cell3 = row1.CreateCell(5 + i);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue(projects[i].ShortName);
}
int rowCount = 3;
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
int a = mergedRow.Value<int>("index");
string Code = values.Value<string>("Code");
string Name = values.Value<string>("Name");
string UnitOfMeasurement = values.Value<string>("UnitOfMeasurement");
string BaseWorkEfficiency = values.Value<string>("BaseWorkEfficiency");
string AvgWorkEfficiency = values.Value<string>("AvgWorkEfficiency");
row1 = sheet.GetRow(rowCount);
cell3 = row1.CreateCell(0);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(Code);
cell3 = row1.CreateCell(1);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(Name);
cell3 = row1.CreateCell(2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(UnitOfMeasurement);
cell3 = row1.CreateCell(3);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(BaseWorkEfficiency);
cell3 = row1.CreateCell(4);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(AvgWorkEfficiency);
for (int i = 0; i < projects.Count; i++)
{
cell3 = row1.CreateCell(5 + i);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(values.Value<string>("Project" + i.ToString()));
}
rowCount++;
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
#endregion
}
}

View File

@ -75,6 +75,15 @@ namespace FineUIPro.Web.PZHGL.InformationProject {
/// </remarks>
protected global::FineUIPro.Button btnSave;
/// <summary>
/// btnOut 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnOut;
/// <summary>
/// nbBaseWorkEfficiency 控件。
/// </summary>

View File

@ -370,7 +370,7 @@
<f:MenuButton ID="btnMenuEdit" OnClick="btnMenuEdit_Click" EnablePostBack="true" Icon="Pencil" Hidden="true"
runat="server" Text="编辑">
</f:MenuButton>
<f:MenuButton ID="btnMenuDown" OnClick="btnMenuDown_Click" EnablePostBack="true" runat="server" Icon="FolderUp" Hidden="true"
<f:MenuButton ID="btnMenuDown" OnClick="btnMenuDown_Click" EnablePostBack="true" runat="server" Icon="FolderUp" Hidden="true" EnableAjax="false"
Text="导出">
</f:MenuButton>
<f:MenuButton ID="btnMenuDelete" OnClick="btnMenuDelete_Click" EnablePostBack="true" Icon="Delete" Hidden="true"

View File

@ -315,7 +315,7 @@
Height="500px">
</f:Window>
<f:Menu ID="Menu1" runat="server">
<f:MenuButton ID="btnMenuDown" OnClick="btnMenuDown_Click" EnablePostBack="true" runat="server" Icon="FolderUp" Hidden="true"
<f:MenuButton ID="btnMenuDown" OnClick="btnMenuDown_Click" EnablePostBack="true" runat="server" Icon="FolderUp" Hidden="true" EnableAjax="false"
Text="导出">
</f:MenuButton>
</f:Menu>

View File

@ -33,6 +33,9 @@
<f:DropDownList ID="drpContractNo" runat="server" Label="合同编号" LabelAlign="Right" EnableEdit="true" LabelWidth="120px" AutoPostBack="true" OnSelectedIndexChanged="drpContractNo_SelectedIndexChanged"></f:DropDownList>
<f:Label runat="server" Label="施工分包商" ID="lblUnitName" LabelWidth="150px" LabelAlign="Right"></f:Label>
<f:ToolbarFill runat="server"></f:ToolbarFill>
<f:Button ID="btnOut" OnClick="btnOut_Click" runat="server" Text="导出" Icon="FolderUp"
EnableAjax="false" DisableControlBeforePostBack="false">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>

View File

@ -1,8 +1,10 @@
using BLL;
using Newtonsoft.Json.Linq;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web.UI.WebControls;
@ -190,5 +192,270 @@ namespace FineUIPro.Web.PZHGL.InformationProject
Alert.ShowInTop("请选择日期!", MessageBoxIcon.Warning);
}
}
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
if (this.Grid1.Rows.Count == 0)
{
Alert.ShowInTop("无数据可导出!", MessageBoxIcon.Warning);
return;
}
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
string filePath = string.Empty;
initTemplatePath = Const.DayConstructionLogWorkEfficiencyTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
Model.SGGLDB db = Funs.DB;
var workEfficiencys = from x in db.ZHGL_ConstructionLogWorkEfficiency
join y in db.ZHGL_ConstructionLog on x.ConstructionLogId equals y.ConstructionLogId
where y.ProjectId == this.CurrUser.LoginProjectId
select x;
List<string> workPostIds = (from x in workEfficiencys
where x.Type == "Person"
select x.TypeId).Distinct().ToList();
List<string> machineIds = (from x in workEfficiencys
where x.Type == "Machine"
select x.TypeId).Distinct().ToList();
string projectName = BLL.ProjectService.GetProjectNameByProjectId(this.CurrUser.LoginProjectId);
string unitName = this.lblUnitName.Text.Trim();
string contractNo = string.Empty;
if (this.drpContractNo.SelectedValue != BLL.Const._Null)
{
contractNo = this.drpContractNo.SelectedItem.Text;
}
newUrl = uploadfilepath.Replace(".xlsx", "(" + this.txtCompileDate.Text.Trim() + ")" + ".xlsx");
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle0.WrapText = true;
var font = workbook.CreateFont();
font.FontHeightInPoints = 16;
font.IsBold = true;
cellStyle0.SetFont(font);
NPOI.SS.UserModel.ICellStyle cellStyle1 = workbook.CreateCellStyle();
cellStyle1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle1.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle1.WrapText = true;
var font1 = workbook.CreateFont();
font1.FontHeightInPoints = 11;
font1.IsBold = true;
cellStyle1.SetFont(font1);
NPOI.SS.UserModel.ICellStyle cellStyle2 = workbook.CreateCellStyle();
cellStyle2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle2.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle2.WrapText = true;
var font0 = workbook.CreateFont();
font0.FontHeightInPoints = 11;
font0.IsBold = false;
cellStyle2.SetFont(font0);
NPOI.SS.UserModel.ICellStyle cellStyle3 = workbook.CreateCellStyle();
cellStyle3.BorderTop = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderLeft = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
cellStyle3.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
//cellStyle3.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
//cellStyle3.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
cellStyle3.WrapText = true;
var font3 = workbook.CreateFont();
font3.FontHeightInPoints = 11;
font3.IsBold = true;
cellStyle3.SetFont(font3);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row1 = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell3;
cell3 = row1.CreateCell(0);
cell3.CellStyle = cellStyle0;
cell3.SetCellValue("日工效汇总表");
cell3 = row1.CreateCell(9 + workPostIds.Count * 2 + machineIds.Count * 2);
cell3.CellStyle = cellStyle0;
sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 9 + workPostIds.Count * 2 + machineIds.Count * 2));
row1 = sheet.GetRow(1);
cell3 = row1.CreateCell(1);
cell3.CellStyle = cellStyle3;
cell3.SetCellValue(projectName);
cell3 = row1.CreateCell(12);
cell3.CellStyle = cellStyle3;
cell3.SetCellValue(unitName);
cell3 = row1.CreateCell(19);
cell3.CellStyle = cellStyle3;
cell3.SetCellValue(contractNo);
row1 = sheet.GetRow(2);
cell3 = row1.CreateCell(12);
cell3.CellStyle = cellStyle3;
cell3.SetCellValue(this.txtCompileDate.Text.Trim());
row1 = sheet.GetRow(3);
cell3 = row1.CreateCell(10);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("人工消耗工·h");
for (int i = 1; i < workPostIds.Count * 2; i++)
{
cell3 = row1.CreateCell(10 + i);
cell3.CellStyle = cellStyle1;
}
sheet.AddMergedRegion(new CellRangeAddress(3, 3, 10, 9 + workPostIds.Count * 2));
cell3 = row1.CreateCell(10 + workPostIds.Count * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("机械消耗台·h");
for (int i = 1; i < machineIds.Count * 2; i++)
{
cell3 = row1.CreateCell(10 + workPostIds.Count * 2 + i);
cell3.CellStyle = cellStyle1;
}
sheet.AddMergedRegion(new CellRangeAddress(3, 3, 10 + workPostIds.Count * 2, 9 + workPostIds.Count * 2 + machineIds.Count * 2));
row1 = sheet.GetRow(4);
for (int i = 0; i < workPostIds.Count; i++)
{
cell3 = row1.CreateCell(10 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue(BLL.WorkPostService.getWorkPostNameById(workPostIds[i]));
cell3 = row1.CreateCell(11 + i * 2);
cell3.CellStyle = cellStyle1;
sheet.AddMergedRegion(new CellRangeAddress(4, 4, 10 + i * 2, 11 + i * 2));
}
for (int i = 0; i < machineIds.Count; i++)
{
cell3 = row1.CreateCell(10 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue(BLL.SpecialEquipmentService.GetSpecialEquipmentNameById(machineIds[i]));
cell3 = row1.CreateCell(11 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle1;
sheet.AddMergedRegion(new CellRangeAddress(4, 4, 10 + workPostIds.Count * 2 + i * 2, 11 + workPostIds.Count * 2 + i * 2));
}
row1 = sheet.GetRow(5);
for (int i = 0; i < workPostIds.Count; i++)
{
cell3 = row1.CreateCell(10 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("消耗工时");
cell3 = row1.CreateCell(11 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("工效");
}
for (int i = 0; i < machineIds.Count; i++)
{
cell3 = row1.CreateCell(10 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("消耗台时");
cell3 = row1.CreateCell(11 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("工效");
}
int rowCount = 6;
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
int a = mergedRow.Value<int>("index");
string Code = values.Value<string>("Code");
string MainItemCode = values.Value<string>("MainItemCode");
string MainItemName = values.Value<string>("MainItemName");
string MajorCode = values.Value<string>("MajorCode");
string MajorName = values.Value<string>("MajorName");
string ProjectCode = values.Value<string>("ProjectCode");
string ProjectName = values.Value<string>("ProjectName");
string UnitOfMeasurement = values.Value<string>("UnitOfMeasurement");
string PhysicalCompletionQuantity = values.Value<string>("PhysicalCompletionQuantity");
string MaterialConsumption = values.Value<string>("MaterialConsumption");
row1 = sheet.GetRow(rowCount);
cell3 = row1.CreateCell(0);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(Code);
cell3 = row1.CreateCell(1);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(MainItemCode);
cell3 = row1.CreateCell(2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(MainItemName);
cell3 = row1.CreateCell(3);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(MajorCode);
cell3 = row1.CreateCell(4);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(MajorName);
cell3 = row1.CreateCell(5);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(ProjectCode);
cell3 = row1.CreateCell(6);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(ProjectName);
cell3 = row1.CreateCell(7);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(UnitOfMeasurement);
cell3 = row1.CreateCell(8);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(PhysicalCompletionQuantity);
cell3 = row1.CreateCell(9);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(MaterialConsumption);
for (int i = 0; i < workPostIds.Count; i++)
{
cell3 = row1.CreateCell(10 + i * 2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(values.Value<string>("PersonConsumeHours" + i.ToString()));
cell3 = row1.CreateCell(11 + i * 2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(values.Value<string>("PersonWorkEfficiency" + i.ToString()));
}
for (int i = 0; i < machineIds.Count; i++)
{
cell3 = row1.CreateCell(10 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(values.Value<string>("MachineConsumeHours" + i.ToString()));
cell3 = row1.CreateCell(11 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(values.Value<string>("MachineWorkEfficiency" + i.ToString()));
}
rowCount++;
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
#endregion
}
}

View File

@ -92,5 +92,14 @@ namespace FineUIPro.Web.PZHGL.InformationProject {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Label lblUnitName;
/// <summary>
/// btnOut 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnOut;
}
}

View File

@ -39,6 +39,9 @@
<f:Button ID="btnSave" Icon="SystemSave" runat="server" ToolTip="保存" Text="保存"
OnClick="btnSave_Click">
</f:Button>
<f:Button ID="btnOut" OnClick="btnOut_Click" runat="server" Text="导出" Icon="FolderUp"
EnableAjax="false" DisableControlBeforePostBack="false">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>

View File

@ -1,8 +1,10 @@
using BLL;
using Newtonsoft.Json.Linq;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web.UI.WebControls;
@ -289,5 +291,270 @@ namespace FineUIPro.Web.PZHGL.InformationProject
Grid1.DataSource = null;
Grid1.DataBind();
}
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
if (this.Grid1.Rows.Count == 0)
{
Alert.ShowInTop("无数据可导出!", MessageBoxIcon.Warning);
return;
}
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
string filePath = string.Empty;
initTemplatePath = Const.MonthConstructionLogWorkEfficiencyTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
Model.SGGLDB db = Funs.DB;
var workEfficiencys = from x in db.ZHGL_ConstructionLogWorkEfficiency
join y in db.ZHGL_ConstructionLog on x.ConstructionLogId equals y.ConstructionLogId
where y.ProjectId == this.CurrUser.LoginProjectId
select x;
List<string> workPostIds = (from x in workEfficiencys
where x.Type == "Person"
select x.TypeId).Distinct().ToList();
List<string> machineIds = (from x in workEfficiencys
where x.Type == "Machine"
select x.TypeId).Distinct().ToList();
string projectName = BLL.ProjectService.GetProjectNameByProjectId(this.CurrUser.LoginProjectId);
string unitName = this.lblUnitName.Text.Trim();
string contractNo = string.Empty;
if (this.drpContractNo.SelectedValue != BLL.Const._Null)
{
contractNo = this.drpContractNo.SelectedItem.Text;
}
newUrl = uploadfilepath.Replace(".xlsx", "(" + this.txtMonth.Text.Trim() + ")" + ".xlsx");
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle0.WrapText = true;
var font = workbook.CreateFont();
font.FontHeightInPoints = 16;
font.IsBold = true;
cellStyle0.SetFont(font);
NPOI.SS.UserModel.ICellStyle cellStyle1 = workbook.CreateCellStyle();
cellStyle1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle1.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle1.WrapText = true;
var font1 = workbook.CreateFont();
font1.FontHeightInPoints = 11;
font1.IsBold = true;
cellStyle1.SetFont(font1);
NPOI.SS.UserModel.ICellStyle cellStyle2 = workbook.CreateCellStyle();
cellStyle2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle2.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle2.WrapText = true;
var font0 = workbook.CreateFont();
font0.FontHeightInPoints = 11;
font0.IsBold = false;
cellStyle2.SetFont(font0);
NPOI.SS.UserModel.ICellStyle cellStyle3 = workbook.CreateCellStyle();
cellStyle3.BorderTop = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderLeft = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
cellStyle3.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
//cellStyle3.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
//cellStyle3.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
cellStyle3.WrapText = true;
var font3 = workbook.CreateFont();
font3.FontHeightInPoints = 11;
font3.IsBold = true;
cellStyle3.SetFont(font3);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row1 = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell3;
cell3 = row1.CreateCell(0);
cell3.CellStyle = cellStyle0;
cell3.SetCellValue("月工效汇总表");
cell3 = row1.CreateCell(9 + workPostIds.Count * 2 + machineIds.Count * 2);
cell3.CellStyle = cellStyle0;
sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 9 + workPostIds.Count * 2 + machineIds.Count * 2));
row1 = sheet.GetRow(1);
cell3 = row1.CreateCell(1);
cell3.CellStyle = cellStyle3;
cell3.SetCellValue(projectName);
cell3 = row1.CreateCell(12);
cell3.CellStyle = cellStyle3;
cell3.SetCellValue(unitName);
cell3 = row1.CreateCell(19);
cell3.CellStyle = cellStyle3;
cell3.SetCellValue(contractNo);
row1 = sheet.GetRow(2);
cell3 = row1.CreateCell(12);
cell3.CellStyle = cellStyle3;
cell3.SetCellValue(this.txtMonth.Text.Trim());
row1 = sheet.GetRow(3);
cell3 = row1.CreateCell(10);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("人工消耗工·h");
for (int i = 1; i < workPostIds.Count * 2; i++)
{
cell3 = row1.CreateCell(10 + i);
cell3.CellStyle = cellStyle1;
}
sheet.AddMergedRegion(new CellRangeAddress(3, 3, 10, 9 + workPostIds.Count * 2));
cell3 = row1.CreateCell(10 + workPostIds.Count * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("机械消耗台·h");
for (int i = 1; i < machineIds.Count * 2; i++)
{
cell3 = row1.CreateCell(10 + workPostIds.Count * 2 + i);
cell3.CellStyle = cellStyle1;
}
sheet.AddMergedRegion(new CellRangeAddress(3, 3, 10 + workPostIds.Count * 2, 9 + workPostIds.Count * 2 + machineIds.Count * 2));
row1 = sheet.GetRow(4);
for (int i = 0; i < workPostIds.Count; i++)
{
cell3 = row1.CreateCell(10 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue(BLL.WorkPostService.getWorkPostNameById(workPostIds[i]));
cell3 = row1.CreateCell(11 + i * 2);
cell3.CellStyle = cellStyle1;
sheet.AddMergedRegion(new CellRangeAddress(4, 4, 10 + i * 2, 11 + i * 2));
}
for (int i = 0; i < machineIds.Count; i++)
{
cell3 = row1.CreateCell(10 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue(BLL.SpecialEquipmentService.GetSpecialEquipmentNameById(machineIds[i]));
cell3 = row1.CreateCell(11 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle1;
sheet.AddMergedRegion(new CellRangeAddress(4, 4, 10 + workPostIds.Count * 2 + i * 2, 11 + workPostIds.Count * 2 + i * 2));
}
row1 = sheet.GetRow(5);
for (int i = 0; i < workPostIds.Count; i++)
{
cell3 = row1.CreateCell(10 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("消耗工时");
cell3 = row1.CreateCell(11 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("工效");
}
for (int i = 0; i < machineIds.Count; i++)
{
cell3 = row1.CreateCell(10 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("消耗台时");
cell3 = row1.CreateCell(11 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("工效");
}
int rowCount = 6;
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
int a = mergedRow.Value<int>("index");
string Code = values.Value<string>("Code");
string MainItemCode = values.Value<string>("MainItemCode");
string MainItemName = values.Value<string>("MainItemName");
string MajorCode = values.Value<string>("MajorCode");
string MajorName = values.Value<string>("MajorName");
string ProjectCode = values.Value<string>("ProjectCode");
string ProjectName = values.Value<string>("ProjectName");
string UnitOfMeasurement = values.Value<string>("UnitOfMeasurement");
string PhysicalCompletionQuantity = values.Value<string>("PhysicalCompletionQuantity");
string MaterialConsumption = values.Value<string>("MaterialConsumption");
row1 = sheet.GetRow(rowCount);
cell3 = row1.CreateCell(0);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(Code);
cell3 = row1.CreateCell(1);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(MainItemCode);
cell3 = row1.CreateCell(2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(MainItemName);
cell3 = row1.CreateCell(3);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(MajorCode);
cell3 = row1.CreateCell(4);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(MajorName);
cell3 = row1.CreateCell(5);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(ProjectCode);
cell3 = row1.CreateCell(6);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(ProjectName);
cell3 = row1.CreateCell(7);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(UnitOfMeasurement);
cell3 = row1.CreateCell(8);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(PhysicalCompletionQuantity);
cell3 = row1.CreateCell(9);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(MaterialConsumption);
for (int i = 0; i < workPostIds.Count; i++)
{
cell3 = row1.CreateCell(10 + i * 2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(values.Value<string>("PersonConsumeHours" + i.ToString()));
cell3 = row1.CreateCell(11 + i * 2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(values.Value<string>("PersonWorkEfficiency" + i.ToString()));
}
for (int i = 0; i < machineIds.Count; i++)
{
cell3 = row1.CreateCell(10 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(values.Value<string>("MachineConsumeHours" + i.ToString()));
cell3 = row1.CreateCell(11 + workPostIds.Count * 2 + i * 2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(values.Value<string>("MachineWorkEfficiency" + i.ToString()));
}
rowCount++;
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
#endregion
}
}

View File

@ -110,5 +110,14 @@ namespace FineUIPro.Web.PZHGL.InformationProject {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnSave;
/// <summary>
/// btnOut 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnOut;
}
}

View File

@ -403,7 +403,7 @@
<f:MenuButton ID="btnMenuEdit" OnClick="btnMenuEdit_Click" EnablePostBack="true" Icon="Pencil" Hidden="true"
runat="server" Text="编辑">
</f:MenuButton>
<f:MenuButton ID="btnMenuDown" OnClick="btnMenuDown_Click" EnablePostBack="true" runat="server" Icon="FolderUp" Hidden="true"
<f:MenuButton ID="btnMenuDown" OnClick="btnMenuDown_Click" EnablePostBack="true" runat="server" Icon="FolderUp" Hidden="true" EnableAjax="false"
Text="导出">
</f:MenuButton>
<f:MenuButton ID="btnMenuDelete" OnClick="btnMenuDelete_Click" EnablePostBack="true" Icon="Delete" Hidden="true"

View File

@ -35,6 +35,9 @@
<f:Button ID="btnSave" Icon="SystemSave" runat="server" ToolTip="保存" Text="保存"
OnClick="btnSave_Click">
</f:Button>
<f:Button ID="btnOut" OnClick="btnOut_Click" runat="server" Text="导出" Icon="FolderUp"
EnableAjax="false" DisableControlBeforePostBack="false">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>

View File

@ -1,8 +1,10 @@
using BLL;
using Newtonsoft.Json.Linq;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web.UI.WebControls;
@ -83,8 +85,8 @@ namespace FineUIPro.Web.PZHGL.InformationProject
orderby x.ContractNum
select x).ToList();
var workEfficiencyProjects = from x in db.ZHGL_ConstructionLogWorkEfficiencyProject
where x.ProjectId == this.CurrUser.LoginProjectId
select x;
where x.ProjectId == this.CurrUser.LoginProjectId
select x;
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Id", typeof(String)));
table.Columns.Add(new DataColumn("Code", typeof(String)));
@ -149,7 +151,7 @@ namespace FineUIPro.Web.PZHGL.InformationProject
row[1] = a;
row[2] = person.WorkPostName;
row[3] = person.UnitOfMeasurement;
var workEfficiencyProject = workEfficiencyProjects.FirstOrDefault(x=> x.TypeId == person.TypeId && x.UnitOfMeasurement == person.UnitOfMeasurement);
var workEfficiencyProject = workEfficiencyProjects.FirstOrDefault(x => x.TypeId == person.TypeId && x.UnitOfMeasurement == person.UnitOfMeasurement);
if (workEfficiencyProject != null)
{
row[4] = workEfficiencyProject.BaseWorkEfficiency;
@ -279,5 +281,176 @@ namespace FineUIPro.Web.PZHGL.InformationProject
}
}
#endregion
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
if (this.Grid1.Rows.Count == 0)
{
Alert.ShowInTop("无数据可导出!", MessageBoxIcon.Warning);
return;
}
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
string filePath = string.Empty;
initTemplatePath = Const.ProjectConstructionLogWorkEfficiencyTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
Model.SGGLDB db = Funs.DB;
var contracts = (from x in db.PHTGL_Contract
where x.ProjectId == this.CurrUser.LoginProjectId
orderby x.ContractNum
select x).ToList();
string projectName = BLL.ProjectService.GetProjectNameByProjectId(this.CurrUser.LoginProjectId);
newUrl = uploadfilepath.Replace(".xlsx", "(" + string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ")" + ".xlsx");
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle0.WrapText = true;
var font = workbook.CreateFont();
font.FontHeightInPoints = 16;
font.IsBold = true;
cellStyle0.SetFont(font);
NPOI.SS.UserModel.ICellStyle cellStyle1 = workbook.CreateCellStyle();
cellStyle1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle1.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle1.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle1.WrapText = true;
var font1 = workbook.CreateFont();
font1.FontHeightInPoints = 11;
font1.IsBold = true;
cellStyle1.SetFont(font1);
NPOI.SS.UserModel.ICellStyle cellStyle2 = workbook.CreateCellStyle();
cellStyle2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle2.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle2.WrapText = true;
var font0 = workbook.CreateFont();
font0.FontHeightInPoints = 11;
font0.IsBold = false;
cellStyle2.SetFont(font0);
NPOI.SS.UserModel.ICellStyle cellStyle3 = workbook.CreateCellStyle();
cellStyle3.BorderTop = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.BorderLeft = NPOI.SS.UserModel.BorderStyle.None;
cellStyle3.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
cellStyle3.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
//cellStyle3.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
//cellStyle3.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
cellStyle3.WrapText = true;
var font3 = workbook.CreateFont();
font3.FontHeightInPoints = 11;
font3.IsBold = true;
cellStyle3.SetFont(font3);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row1 = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell3;
cell3 = row1.CreateCell(0);
cell3.CellStyle = cellStyle0;
cell3.SetCellValue("项目平均工效统计");
cell3 = row1.CreateCell(4 + contracts.Count);
cell3.CellStyle = cellStyle0;
sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 4 + contracts.Count));
row1 = sheet.GetRow(1);
cell3 = row1.CreateCell(1);
cell3.CellStyle = cellStyle3;
cell3.SetCellValue(projectName);
row1 = sheet.GetRow(2);
cell3 = row1.CreateCell(5);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue("工效统计");
for (int i = 1; i < contracts.Count; i++)
{
cell3 = row1.CreateCell(5 + i);
cell3.CellStyle = cellStyle1;
}
sheet.AddMergedRegion(new CellRangeAddress(2, 2, 5, 4 + contracts.Count));
row1 = sheet.GetRow(3);
for (int i = 0; i < contracts.Count; i++)
{
cell3 = row1.CreateCell(5 + i);
cell3.CellStyle = cellStyle1;
cell3.SetCellValue(contracts[i].ContractNum);
}
int rowCount = 4;
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
int a = mergedRow.Value<int>("index");
string Code = values.Value<string>("Code");
string Name = values.Value<string>("Name");
string UnitOfMeasurement = values.Value<string>("UnitOfMeasurement");
string BaseWorkEfficiency = values.Value<string>("BaseWorkEfficiency");
string AvgWorkEfficiency = values.Value<string>("AvgWorkEfficiency");
row1 = sheet.GetRow(rowCount);
cell3 = row1.CreateCell(0);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(Code);
cell3 = row1.CreateCell(1);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(Name);
cell3 = row1.CreateCell(2);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(UnitOfMeasurement);
cell3 = row1.CreateCell(3);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(BaseWorkEfficiency);
cell3 = row1.CreateCell(4);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(AvgWorkEfficiency);
for (int i = 0; i < contracts.Count; i++)
{
cell3 = row1.CreateCell(5 + i);
cell3.CellStyle = cellStyle2;
cell3.SetCellValue(values.Value<string>("Contract" + i.ToString()));
}
rowCount++;
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
#endregion
}
}

View File

@ -75,6 +75,15 @@ namespace FineUIPro.Web.PZHGL.InformationProject {
/// </remarks>
protected global::FineUIPro.Button btnSave;
/// <summary>
/// btnOut 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnOut;
/// <summary>
/// nbBaseWorkEfficiency 控件。
/// </summary>