html代码实例:使用Spread制作报表的代码实例



.前台代码

<tr>
<td>
<br />
<asp:Button ID=\"btnSave\" runat=\"server\" CssClass=\"standard-text\" Text=\"保存为EXCEL\" _disibledevent=> <asp:Button ID=\"btnJSGZ\" runat=\"SERVER\" CssClass=\"standard-text\" Text=\"计算规则\" _disibledevent=> <br />
<FarPo:FpSpread ID=\"FpSpread1\" runat=\"server\" BorderColor=\"Black\" BorderStyle=\"Solid\"
BorderWidth=\"1px\" Height=\"400\" Style=\"position: absolute;\" Width=\"97%\" Visible=\"false\">
<CommandBar BackColor=\"Control\" ButtonFaceColor=\"Control\" ButtonHighlightColor=\"ControlLightLight\"
ButtonShadowColor=\"ControlDark\" />
<Sheets>
<FarPo:SheetView SheetName=\"Sheet1\">
</FarPo:SheetView>
</Sheets>
</FarPo:FpSpread>
</td> [Page]
</tr>



2.后台代码

/// <summary>
/// 加载存在文件
/// </summary>
private void LoadFile
{
//this.panel1.Visible = true;
try
{
this.FpSpread1.OpenExcel(Server.MapPath(\"Table/\"+filename));
this.FpSpread1.Sheets[0].AllowPage = false;
this.FpSpread1.Sheets[0].OperationMode = FarPo.Web.Spread.OperationMode.SingleSelect;
}
catch(Exception ex)
{
LhTools.ShowMessageNew(this, ex.Message);
}
}

/// <summary>
/// 绑定服务项目列表
/// </summary>
/// <param name=\"dt\"></param>
private void ReportBindDataOffwxmLB(DataTable dt)
{
R = 2;
I;
H = 0;
H=this.FpSpread1.Sheets[0].GetRowHeight(R + 1);//得到有数据
try
{
//this.FpSpread1.Sheets[0].Cells[0, 5].Text = ((C_User)ViewState[\"UserInfo\"]).HospitalName.;
(dt != null)
{
(ddlfwxm.SelectedIndex 0) { this.FpSpread1.Sheets[0].Cells[0, 5].Text = \"全部服务\"; }


{ this.FpSpread1.Sheets[0].Cells[0, 5].Text = ddlfwxm.SelectedItem.Text; }[Page]
foreach (DataRow dr in dt.Rows)
{
R;
this.FpSpread1.Sheets[0].AddRows(R, 1);
this.FpSpread1.Sheets[0].SetRowHeight(R, H);
this.FpSpread1.Sheets[0].Cells[R, 0].Text = dr[\"aa\"].;
this.FpSpread1.Sheets[0].Cells[R, 1].Text = dr[\"bb\"].;
this.FpSpread1.Sheets[0].Cells[R, 2].Text = dr[\"cc\"].;
this.FpSpread1.Sheets[0].Cells[R, 3].Text = dr[\"dd\"].;
this.FpSpread1.Sheets[0].Cells[R, 4].Text = dr[\"ff\"].;
this.FpSpread1.Sheets[0].Cells[R, 5].Text = dr[\"jj\"].;
this.FpSpread1.Sheets[0].Cells[R, 6].Text = dr[\"kk\"].;
this.FpSpread1.Sheets[0].Cells[R, 7].Text = dr[\"ss\"].;
this.FpSpread1.Sheets[0].Cells[R, 8].Text = dr[\"yy\"].;
for (I = 0; I < 9; I)
{[Page]
this.FpSpread1.Sheets[0].Cells[R, I].Font.Size = 10;
this.FpSpread1.Sheets[0].Cells[R, I].Border.BorderStyle = .Web.UI.WebControls.BorderStyle.Solid;
this.FpSpread1.Sheets[0].Cells[R, I].Border.BorderColor = .Drawing.Color.Black;
this.FpSpread1.Sheets[0].Cells[R, I].Border.BorderSize = 2;
this.FpSpread1.Sheets[0].Cells[R, I].HorizontalAlign = .Web.UI.WebControls.HorizontalAlign.Left;
}
}
}

{
this.FpSpread1.Sheets[0].Cells[3, 0, 3, 8].Border.BorderSize = 1;
this.FpSpread1.Sheets[0].Cells[3, 0, 3, 3].Text = \"暂时无服务记录\";
}
}
catch(Exception ex)
{
throw Exception(ex.Message);
}


}



/// <summary>
/// 保存为excel
/// </summary>
/// <param name=\"sender\"></param>
/// <param name=\"e\"></param>
protected void btnSave_Click(object sender, EventArgs e)[Page]
{
try
{
fileName = Guid.NewGuid. + \".xls\";
path = Server.MapPath(\"tempExcel\") + \"\\\\\" + fileName;
bool retvalue = FpSpread1.SaveExcel(path);//写临时文件
//FpSpread1.Sheets[0].
(retvalue)
{
//success
HttpResponse response = HttpContext.Current.Response;
response.Clear;
response.WriteFile(path);
httpHeader = \"attachment;filename=book1.xls\";
response.AppendHeader(\"Content-Disposition\", httpHeader);
response.Flush;
.IO.File.Delete(path);//删除临时文件
response.End;
}
}
catch (Exception ex)
{
LhTools.ShowMessageNew(this, ex.Message);
}
}

Tags:  asp实例代码 合并会计报表实例 报表实例 html代码实例

延伸阅读

最新评论

发表评论