protected void btnExport_Click(object sender, EventArgs e)
{
this.LoadData();
if (this.mStatTable.Rows.Count == 0)
{
base.Alert("没有统计数据");
}
else
{
XlsDocument xlsDoc = new XlsDocument();
xlsDoc.FileName = "area_report.xls";
Worksheet sheet = xlsDoc.Workbook.Worksheets.Add("sheet1");
Cell cell = sheet.Cells.Add(1, 1, "从" + mBeginTime.ToString("yyyy-MM-dd") + "到" + mEndTime.ToString("yyyy-MM-dd") + "市场分析报表");
sheet.Cells.Add(1, 2, "");
sheet.Cells.Add(1, 3, "");
sheet.Cells.Add(1, 4, "");
sheet.Cells.Merge(1, 1, 1, 4);
Cell cell21 = sheet.Cells.Add(2, 1, "地区");
cell21.HorizontalAlignment = HorizontalAlignments.Centered;
Cell cell22 = sheet.Cells.Add(2, 2, "单量");
cell22.HorizontalAlignment = HorizontalAlignments.Centered;
Cell cell23 = sheet.Cells.Add(2, 3, "单额");
cell23.HorizontalAlignment = HorizontalAlignments.Centered;
Cell cell24 = sheet.Cells.Add(2, 4, "单量比重");
cell24.HorizontalAlignment = HorizontalAlignments.Centered;
int rows = this.mStatTable.Rows.Count;
//int cols = 4;
for (int i = 0; i < rows; i++)
{
int itemCount = (int)this.mStatTable.Rows[i]["OrderCount"];
Cell cell1 = sheet.Cells.Add(i + 3, 1, this.mStatTable.Rows[i]["Province"].ToString());
Cell cell2 = sheet.Cells.Add(i + 3, 2, itemCount);
//cell2.Type = CellTypes.Integer;
Cell cell3 = sheet.Cells.Add(i + 3, 3, ((decimal)this.mStatTable.Rows[i]["TotalAmount"]).ToString("N2"));
cell3.HorizontalAlignment = HorizontalAlignments.Right;
//cell3.Type = CellTpes.Float;
Cell cell4 = sheet.Cells.Add(i + 3, 4, ((decimal)(itemCount * 100 / this.mOrderCount)).ToString("0.00") + "%");
cell4.HorizontalAlignment = HorizontalAlignments.Right;
}
int rowsIndex = rows + 2 + 1;
sheet.Cells.Add(rowsIndex, 1, "");
sheet.Cells.Add(rowsIndex, 2, "");
sheet.Cells.Add(rowsIndex, 3, "");
sheet.Cells.Add(rowsIndex, 4, "");
rowsIndex++;
sheet.Cells.Add(rowsIndex, 1, "小计:");
sheet.Cells.Add(rowsIndex, 2, this.mOrderCount);
sheet.Cells.Add(rowsIndex, 3, mTotalAmount);
sheet.Cells.Add(rowsIndex, 4, "");
xlsDoc.Send();
Response.Flush();
Response.End();
}
}