提交代码
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using BLL;
|
||||
using NPOI.SS.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
@@ -15,6 +17,14 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
|
||||
/// </summary>
|
||||
protected void Page_Init(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Request.Params["Date"]))
|
||||
{
|
||||
this.txtMonths.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.txtMonths.Text = string.Format(Request.Params["Date"]);
|
||||
}
|
||||
InitGrid();
|
||||
}
|
||||
|
||||
@@ -26,26 +36,55 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
|
||||
{
|
||||
DateTime startDate, endDate;
|
||||
List<DateTime> days = new List<DateTime>();
|
||||
int year = DateTime.Now.Year;
|
||||
int month = DateTime.Now.Month;
|
||||
DateTime now = Convert.ToDateTime(txtMonths.Text + "-01");
|
||||
int year = now.Year;
|
||||
int month = now.Month;
|
||||
int day = DateTime.Now.Day;
|
||||
if (day >= 26)
|
||||
if (now.AddMonths(1) <= DateTime.Now) //选择的是当前月之前的月份
|
||||
{
|
||||
startDate = Convert.ToDateTime(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + "26");
|
||||
endDate = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime lastMonth = DateTime.Now.AddMonths(-1);
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = DateTime.Now;
|
||||
endDate = now.AddDays(24);
|
||||
}
|
||||
else //选择的是当前月
|
||||
{
|
||||
if (now <= DateTime.Now)
|
||||
{
|
||||
if (now.Month == DateTime.Now.Month)
|
||||
{
|
||||
if (day >= 26)
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = now.AddDays(24);
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
do
|
||||
{
|
||||
days.Add(startDate);
|
||||
startDate = startDate.AddDays(1);
|
||||
} while (startDate <= endDate);
|
||||
GroupField gd = Grid1.Columns[11] as GroupField;
|
||||
GroupField gd = Grid1.Columns[12] as GroupField;
|
||||
for (int i = 0; i < days.Count; i++)
|
||||
{
|
||||
RenderField d = new RenderField();
|
||||
@@ -71,6 +110,29 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Request.Params["DrawingNo"]))
|
||||
{
|
||||
this.txtDrawingNo.Text = Request.Params["DrawingNo"];
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request.Params["Part"]))
|
||||
{
|
||||
this.txtPart.Text = Request.Params["Part"];
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request.Params["ProjectContent"]))
|
||||
{
|
||||
this.txtProjectContent.Text = Request.Params["ProjectContent"];
|
||||
}
|
||||
ProjectService.InitAllProjectDropDownList(this.drpProject, false);
|
||||
if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
|
||||
{
|
||||
this.drpProject.SelectedValue = this.CurrUser.LoginProjectId;
|
||||
this.drpProject.Enabled = false;
|
||||
this.drpProject.Hidden = true;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request.Params["ProjectId"]))
|
||||
{
|
||||
this.drpProject.SelectedValue = Request.Params["ProjectId"];
|
||||
}
|
||||
GetButtonPower();
|
||||
BindGrid();
|
||||
}
|
||||
@@ -81,14 +143,10 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
|
||||
/// </summary>
|
||||
public void BindGrid()
|
||||
{
|
||||
string strSql = @"select BaseId,C.ProjectId,a.WorkSection,DrawingNo,DrawingName,Part,ProjectContent,Unit,Amount,WorkTeam,
|
||||
isnull((select sum(DayAmount) from QuantityManagement_DayInput d where d.BaseId=C.BaseId),0) as TotalComplete,
|
||||
Amount-isnull((select sum(DayAmount) from QuantityManagement_DayInput d where d.BaseId=C.BaseId),0) as Remain
|
||||
from QuantityManagement_Base C
|
||||
left join QuantityManagement_Drawing a on a.DrawingId=C.DrawingId
|
||||
string strSql = @"select newid() as Id,C.* from View_QuantityManagement_DayInput C
|
||||
where C.ProjectId = @ProjectId";
|
||||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||||
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
|
||||
listStr.Add(new SqlParameter("@ProjectId", this.drpProject.SelectedValue));
|
||||
if (!string.IsNullOrEmpty(this.txtDrawingNo.Text.Trim()))
|
||||
{
|
||||
strSql += " AND DrawingNo like @DrawingNo";
|
||||
@@ -113,49 +171,125 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
|
||||
//绑定数据
|
||||
DateTime startDate, endDate, startDate1, endDate1;
|
||||
List<DateTime> days = new List<DateTime>();
|
||||
int year = DateTime.Now.Year;
|
||||
int month = DateTime.Now.Month;
|
||||
//int year = DateTime.Now.Year;
|
||||
//int month = DateTime.Now.Month;
|
||||
//int day = DateTime.Now.Day;
|
||||
//if (day >= 26)
|
||||
//{
|
||||
// startDate = Convert.ToDateTime(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + "26");
|
||||
// startDate1 = startDate;
|
||||
// endDate = DateTime.Now;
|
||||
// endDate1 = endDate;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// DateTime lastMonth = DateTime.Now.AddMonths(-1);
|
||||
// startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
// startDate1 = startDate;
|
||||
// endDate = DateTime.Now;
|
||||
// endDate1 = endDate;
|
||||
//}
|
||||
//var dayInputs = from x in Funs.DB.QuantityManagement_DayInput
|
||||
// where x.ProjectId == this.CurrUser.LoginProjectId && x.Date >= startDate && x.Date <= endDate
|
||||
// orderby x.Date
|
||||
// select x;
|
||||
//do
|
||||
//{
|
||||
// days.Add(startDate1);
|
||||
// startDate1 = startDate1.AddDays(1);
|
||||
//} while (startDate1 <= endDate1);
|
||||
DateTime now = Convert.ToDateTime(txtMonths.Text + "-01");
|
||||
int year = now.Year;
|
||||
int month = now.Month;
|
||||
int day = DateTime.Now.Day;
|
||||
if (day >= 26)
|
||||
if (now.AddMonths(1) <= DateTime.Now) //选择的是当前月之前的月份
|
||||
{
|
||||
startDate = Convert.ToDateTime(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + "26");
|
||||
startDate1 = startDate;
|
||||
endDate = DateTime.Now;
|
||||
endDate1 = endDate;
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime lastMonth = DateTime.Now.AddMonths(-1);
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = now.AddDays(24);
|
||||
startDate1 = startDate;
|
||||
endDate = DateTime.Now;
|
||||
endDate1 = endDate;
|
||||
}
|
||||
var dayInputs = from x in Funs.DB.QuantityManagement_DayInput
|
||||
where x.ProjectId == this.CurrUser.LoginProjectId && x.Date >= startDate && x.Date <= endDate
|
||||
orderby x.Date
|
||||
select x;
|
||||
else //选择的是当前月
|
||||
{
|
||||
if (now <= DateTime.Now)
|
||||
{
|
||||
if (now.Month == DateTime.Now.Month)
|
||||
{
|
||||
if (day >= 26)
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = now.AddDays(24);
|
||||
startDate1 = startDate;
|
||||
endDate1 = endDate;
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = DateTime.Now;
|
||||
startDate1 = startDate;
|
||||
endDate1 = endDate;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = DateTime.Now;
|
||||
startDate1 = startDate;
|
||||
endDate1 = endDate;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = DateTime.Now;
|
||||
startDate1 = startDate;
|
||||
endDate1 = endDate;
|
||||
}
|
||||
}
|
||||
do
|
||||
{
|
||||
days.Add(startDate1);
|
||||
startDate1 = startDate1.AddDays(1);
|
||||
} while (startDate1 <= endDate1);
|
||||
var dayInputs = from x in Funs.DB.QuantityManagement_DayInput
|
||||
where x.ProjectId == this.drpProject.SelectedValue && x.Date <= endDate
|
||||
orderby x.Date
|
||||
select x;
|
||||
var bases = from x in Funs.DB.QuantityManagement_Base
|
||||
where x.ProjectId == this.drpProject.SelectedValue
|
||||
select x;
|
||||
for (int i = 0; i < this.Grid1.Rows.Count; i++)
|
||||
{
|
||||
string baseId = this.Grid1.Rows[i].RowID;
|
||||
string baseId = this.Grid1.Rows[i].DataKeys[0].ToString();
|
||||
string workTeamId = this.Grid1.Rows[i].DataKeys[1].ToString();
|
||||
int j = 0;
|
||||
decimal monthComplete = 0;
|
||||
foreach (var d in days)
|
||||
{
|
||||
var dayInput = dayInputs.FirstOrDefault(x => x.BaseId == baseId && x.Date == d);
|
||||
var dayInput = dayInputs.FirstOrDefault(x => x.BaseId == baseId && x.Date == d && x.WorkTeam == workTeamId);
|
||||
if (dayInput != null)
|
||||
{
|
||||
this.Grid1.Rows[i].Values[12 + j] = dayInput.DayAmount.Value.ToString("0.##");
|
||||
this.Grid1.Rows[i].Values[13 + j] = dayInput.DayAmount.Value.ToString("0.##");
|
||||
monthComplete += dayInput.DayAmount.Value;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
this.Grid1.Rows[i].Values[12+days.Count]= monthComplete.ToString("0.##");
|
||||
var b = bases.FirstOrDefault(x => x.BaseId == baseId);
|
||||
decimal totalAmount = 0;
|
||||
if (b != null)
|
||||
{
|
||||
totalAmount = b.Amount ?? 0;
|
||||
}
|
||||
decimal completedAmount = dayInputs.Where(x => x.BaseId == baseId && x.WorkTeam == workTeamId).ToList().Sum(x => x.DayAmount ?? 0);
|
||||
decimal totalCompletedAmount = dayInputs.Where(x => x.BaseId == baseId).ToList().Sum(x => x.DayAmount ?? 0);
|
||||
this.Grid1.Rows[i].Values[9] = completedAmount.ToString("0.##");
|
||||
this.Grid1.Rows[i].Values[10] = (totalAmount - totalCompletedAmount).ToString("0.##");
|
||||
this.Grid1.Rows[i].Values[11] = monthComplete.ToString("0.##");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -203,7 +337,9 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
|
||||
/// <param name="e"></param>
|
||||
protected void btnSearch_Click(object sender, EventArgs e)
|
||||
{
|
||||
BindGrid();
|
||||
string url = "~/CQMS/QuantityManagement/DayInputStatistics.aspx?Date=" + this.txtMonths.Text.Trim() + "&DrawingNo=" + this.txtDrawingNo.Text.Trim()
|
||||
+ "&Part=" + this.txtPart.Text.Trim() + "&ProjectContent=" + this.txtProjectContent.Text.Trim() + "&ProjectId=" + this.drpProject.SelectedValue;
|
||||
PageContext.Redirect(url, "_self");
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -262,5 +398,217 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 导出按钮
|
||||
/// 导出按钮
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnOut_Click(object sender, EventArgs e)
|
||||
{
|
||||
string rootPath = Server.MapPath("~/");
|
||||
string initTemplatePath = string.Empty;
|
||||
string uploadfilepath = string.Empty;
|
||||
string newUrl = string.Empty;
|
||||
string filePath = string.Empty;
|
||||
initTemplatePath = Const.DayInputStatisticsTemplateUrl;
|
||||
uploadfilepath = rootPath + initTemplatePath;
|
||||
if (this.Grid1.Rows.Count > 0)
|
||||
{
|
||||
newUrl = uploadfilepath.Replace(".xlsx", "(" + this.txtMonths.Text.Trim() + ")" + ".xlsx");
|
||||
File.Copy(uploadfilepath, newUrl);
|
||||
|
||||
DateTime startDate, endDate;
|
||||
List<DateTime> days = new List<DateTime>();
|
||||
DateTime now = Convert.ToDateTime(txtMonths.Text + "-01");
|
||||
int year = now.Year;
|
||||
int month = now.Month;
|
||||
int day = DateTime.Now.Day;
|
||||
if (now.AddMonths(1) <= DateTime.Now) //选择的是当前月之前的月份
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = now.AddDays(24);
|
||||
}
|
||||
else //选择的是当前月
|
||||
{
|
||||
if (now <= DateTime.Now)
|
||||
{
|
||||
if (now.Month == DateTime.Now.Month)
|
||||
{
|
||||
if (day >= 26)
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = now.AddDays(24);
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
|
||||
endDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
do
|
||||
{
|
||||
days.Add(startDate);
|
||||
startDate = startDate.AddDays(1);
|
||||
} while (startDate <= endDate);
|
||||
|
||||
// 第一步:读取文件流
|
||||
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;
|
||||
var font = workbook.CreateFont();
|
||||
font.FontHeightInPoints = 12;
|
||||
font.IsBold = true;
|
||||
//font.FontHeightInPoints = (short)8.5;字号为小数时要转为short
|
||||
cellStyle0.SetFont(font);
|
||||
// 第二步:创建新数据行
|
||||
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
|
||||
var font2 = workbook.CreateFont();
|
||||
font2.FontHeightInPoints = 10;
|
||||
// 创建单元格样式
|
||||
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
|
||||
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
|
||||
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
|
||||
cellStyle.WrapText = true;
|
||||
cellStyle.SetFont(font2);
|
||||
// 创建单元格样式
|
||||
NPOI.SS.UserModel.ICellStyle cellStyleYellow = workbook.CreateCellStyle();
|
||||
cellStyleYellow.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyleYellow.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyleYellow.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyleYellow.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyleYellow.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
|
||||
cellStyleYellow.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
|
||||
//NPOI.SS.UserModel.IRow row5 = sheet.GetRow(5);
|
||||
//NPOI.SS.UserModel.ICell cell5;
|
||||
//cell5 = row5.GetCell(4);
|
||||
cellStyleYellow.FillBackgroundColor = 120;
|
||||
cellStyleYellow.SetFont(font2);
|
||||
int r0 = 0;
|
||||
int r = 1;
|
||||
NPOI.SS.UserModel.IRow row;
|
||||
NPOI.SS.UserModel.ICell cell;
|
||||
row = sheet.GetRow(r0);
|
||||
for (int i = 0; i < days.Count; i++)
|
||||
{
|
||||
cell = row.CreateCell(12 + i);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue("完成工程量");
|
||||
}
|
||||
row = sheet.GetRow(r);
|
||||
for (int i = 0; i < days.Count; i++)
|
||||
{
|
||||
cell = row.CreateCell(12 + i);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(string.Format("{0:MM-dd}", days[i]));
|
||||
}
|
||||
sheet.AddMergedRegion(new CellRangeAddress(0, 0, 12, 11 + days.Count));
|
||||
r++;
|
||||
for (int i = 0; i < Grid1.Rows.Count; i++)
|
||||
{
|
||||
row = sheet.CreateRow(r + i);
|
||||
cell = row.CreateCell(0);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue((i + 1).ToString());
|
||||
cell = row.CreateCell(1);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[1].ToString());
|
||||
cell = row.CreateCell(2);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[2].ToString());
|
||||
cell = row.CreateCell(3);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[3].ToString());
|
||||
cell = row.CreateCell(4);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[4].ToString());
|
||||
cell = row.CreateCell(5);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[5].ToString());
|
||||
cell = row.CreateCell(6);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[6].ToString());
|
||||
cell = row.CreateCell(7);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[7].ToString());
|
||||
cell = row.CreateCell(8);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[8].ToString());
|
||||
cell = row.CreateCell(9);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[9].ToString());
|
||||
cell = row.CreateCell(10);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[10].ToString());
|
||||
cell = row.CreateCell(11);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[11].ToString());
|
||||
for (int j = 0; j < days.Count; j++)
|
||||
{
|
||||
cell = row.CreateCell(12 + j);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(Grid1.Rows[i].Values[13 + j].ToString());
|
||||
}
|
||||
}
|
||||
// 第三步:写入文件流
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert.ShowInTop("当期无记录,无法导出!", MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user