电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

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


发布日期:2018/3/23
 

一.前台代码

<tr>

<td>

<br />

<asp:Button ID=btnSave runat=server CssClass=standardtext Text=保存为EXCEL OnClick=btnSave_Click Visible=false />

<asp:Button ID=btnJSGZ runat=SERVER CssClass=standardtext Text=计算规则 OnClick=btnJSGZ_Click/>

<br />

<FarPoint:FpSpread ID=FpSpread runat=server BorderColor=Black BorderStyle=Solid

BorderWidth=px Height= Style=position: absolute; Width=% Visible=false>

<CommandBar BackColor=Control ButtonFaceColor=Control ButtonHighlightColor=ControlLightLight

ButtonShadowColor=ControlDark />

<Sheets>

<FarPoint:SheetView SheetName=Sheet>

</FarPoint:SheetView>

</Sheets>

</FarPoint:FpSpread>

</td>

</tr>

二.后台代码

/// <summary>

/// 加载存在的文件

/// </summary>

private void LoadFile()

{

//thispanelVisible = true;

try

{

thisFpSpreadOpenExcel(ServerMapPath(Table/+filename));

thisFpSpreadSheets[]AllowPage = false;

thisFpSpreadSheets[]OperationMode = FarPointWebSpreadOperationModeSingleSelect;

}

catch(Exception ex)

{

LhToolsShowMessageNew(this exMessage);

}

}

/// <summary>

/// 绑定服务项目列表

/// </summary>

/// <param name=dt></param>

private void ReportBindDataOffwxmLB(DataTable dt)

{

int intR = ;

int intI;

int intH = ;

intH=thisFpSpreadSheets[]GetRowHeight(intR + );//得到有数据一行的高

try

{

//thisFpSpreadSheets[]Cells[ ]Text = ((C_User)ViewState[UserInfo])HospitalNameToString();

if (dt != null)

{

if (ddlfwxmSelectedIndex == ) { thisFpSpreadSheets[]Cells[ ]Text = 全部服务; }

else { thisFpSpreadSheets[]Cells[ ]Text = ddlfwxmSelectedItemText; }

foreach (DataRow dr in dtRows)

{

intR++;

thisFpSpreadSheets[]AddRows(intR );

thisFpSpreadSheets[]SetRowHeight(intR intH);

thisFpSpreadSheets[]Cells[intR ]Text = dr[aa]ToString();

thisFpSpreadSheets[]Cells[intR ]Text = dr[bb]ToString();

thisFpSpreadSheets[]Cells[intR ]Text = dr[cc]ToString();

thisFpSpreadSheets[]Cells[intR ]Text = dr[dd]ToString();

thisFpSpreadSheets[]Cells[intR ]Text = dr[ff]ToString();

thisFpSpreadSheets[]Cells[intR ]Text = dr[jj]ToString();

thisFpSpreadSheets[]Cells[intR ]Text = dr[kk]ToString();

thisFpSpreadSheets[]Cells[intR ]Text = dr[ss]ToString();

thisFpSpreadSheets[]Cells[intR ]Text = dr[yy]ToString();

for (intI = ; intI < ; intI++)

{thisFpSpreadSheets[]Cells[intR intI]FontSize = ;

thisFpSpreadSheets[]Cells[intR intI]BorderBorderStyle = SystemWebUIWebControlsBorderStyleSolid;

thisFpSpreadSheets[]Cells[intR intI]BorderBorderColor = SystemDrawingColorBlack;

thisFpSpreadSheets[]Cells[intR intI]BorderBorderSize = ;

thisFpSpreadSheets[]Cells[intR intI]HorizontalAlign = SystemWebUIWebControlsHorizontalAlignLeft;

}

}

}

else

{

thisFpSpreadSheets[]Cells[ ]BorderBorderSize = ;

thisFpSpreadSheets[]Cells[ ]Text = 暂时无服务记录;

}

}

catch(Exception ex)

{

throw new Exception(exMessage);

}

}

/// <summary>

/// 保存为excel

/// </summary>

/// <param name=sender></param>

/// <param name=e></param>

protected void btnSave_Click(object sender EventArgs e)

{

try

{

string fileName = GuidNewGuid()ToString() + xls;

string path = ServerMapPath(tempExcel) + \ + fileName;

bool retvalue = FpSpreadSaveExcel(path);//写临时文件

//FpSpreadSheets[]

if (retvalue)

{

//success

HttpResponse response = HttpContextCurrentResponse;

responseClear();

responseWriteFile(path);

string httpHeader = attachment;filename=bookxls;

responseAppendHeader(ContentDisposition httpHeader);

responseFlush();

SystemIOFileDelete(path);//删除临时文件

responseEnd();

}

}

catch (Exception ex)

{

LhToolsShowMessageNew(this exMessage);

}

}

上一篇:多核编程的四层境界

下一篇:sohu邮箱的联系人获取