日期:2014-05-17 浏览次数:20490 次
#region 将数据写入到服务器上面的Excel模板 /// <summary> /// 将数据写入到服务器上面的Excel模板 /// </summary> public void WriteToExcel() { string filepath = Server.MapPath(@"~/Samples/week_product_yield.xls"); Excel.Application xApp = new Excel.ApplicationClass(); Excel.Workbook xBook = xApp.Workbooks._Open(filepath, Missing.Value, Missing.Value, Missing.Value, Missing.Value , Missing.Value, Missing.Value, Missing.Value, Missing.Value , Missing.Value, Missing.Value, Missing.Value, Missing.Value); Excel.Worksheet xSheet = (Excel.Worksheet)xBook.Sheets[1]; //////////////////////////////////////////////////// if (this.txtStartTime.Text.Trim() != "" && this.txtEndTime.Text.Trim() != "") { _TheStartTime = this.txtStartTime.Text.Trim().Substring(0, 10); _TheEndTime = this.txtEndTime.Text.Trim().Substring(0, 10); DateTime stStart = Convert.ToDateTime(_TheStartTime); DateTime stEnd = Convert.ToDateTime(_TheEndTime); if (DateTime.Compare(stStart, stEnd) > 0) { this.lblMessage.Text = "警告:结束时间必须大于开始时间!"; this.lblMessage.ForeColor = Color.Red; return; } if (dt.Rows.Count > 0) { dt.Clear(); } DateTime TheStartTime = Convert.ToDateTime(_TheStartTime); DateTime TheEndTime = Convert.ToDateTime(_TheEndTime); if (this.ddlModelList.Text == "80-A368-00W00") { dt = rm.GetWeekProductYidldReportData(_TheStartTime, _TheEndTime); } else if (this.ddlModelList.Text == "80-A368-10W00") { dt = rm.GetWeekProductYidldReportData2(_TheStartTime, _TheEndTime); } else { dt = rm.GetWeekProductYidldReportData3(TheStartTime, TheEndTime); } } ////////////////////////////////////////////////// Excel.Range rng4 = xSheet.get_Range("B9", Missing.Value); rng4.Value2 = dt.Rows[0]["FTOTQTY"].ToString(); Excel.Range rng5 = xSheet.get_Range("B10", Missing.Value); rng5.Value2 = dt.Rows[0]["FFQTY"].ToString(); Excel.Range rng6 = xSheet.get_Range("B11", Missing.Value); if (Convert.ToInt32(rng5.Value2) == 0 && Convert.ToInt32(rng4.Value2) != 0) { rng6.Value2 = "0.00%"; } else if (Convert.ToInt32(rng5.Value2) == 0 && Convert.ToInt32(rng4.Value2) == 0) { rng6.Value2 = "0.00%"; } else { rng6.Value2 = (Convert.ToDouble(rng5.Value2) / Convert.ToInt32(rng4.Value2)) * 100 + "%"; } Excel.Range rng10 = xSheet.get_Range("D9", Missing.Value); rng10.Value2 = dt.Rows[2]["FTOTQTY"].ToString(); Excel.Range rng11 = xSheet.get_Range("D10", Missing.Value); rng11.Value2 = dt.Rows[2]["FFQTY"].ToString(); Excel.Range rng12 = xSheet.get_Range("D11", Missing.Value); if (Convert.ToInt32(rng11.Value2) == 0 && Convert.ToInt32(r