5,139
社区成员
发帖
与我相关
我的任务
分享
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div class="barContent_big">
<asp:Button ID="btnPrintExcel" runat="server" ClientIDMode="Static" Text="保存Excel" OnClick="btnPrintExcel_Click" />
<asp:Button ID="btnQueryCaseNum" runat="server" ClientIDMode="Static" Text="查询" OnClick="btnQueryCaseNum_Click" OnClientClick="return CaseNumCheck();" />
</div>
<div class="mainbox">
<asp:UpdatePanel ID="UpPalQueryCaseNum" runat="server" UpdateMode="Always" RenderMode="Block">
<ContentTemplate>
<FarPoint:FpSpread ID="FpSpdCaseNum" runat="server" BorderColor="Black" CssClass="queryFpSpread">
<CommandBar BackColor="Control" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight" ButtonShadowColor="ControlDark"></CommandBar>
<Sheets>
<FarPoint:SheetView SheetName="Sheet1"></FarPoint:SheetView>
</Sheets>
</FarPoint:FpSpread>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnQueryCaseNum" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
protected void Page_Load(object sender, EventArgs e)
{
this.FpSpdCaseNum.SaveViewStateToSession = false;
this.FpSpdCaseNum.Sheets[0].AllowPage = false;
MergeSchedule(true);
}
/// <summary>
/// 设置报表的默认样式值
/// </summary>
public void SetFpSpdCaseNumDefaultValues()
{
// 默认行数
this.FpSpdCaseNum.Sheets[0].RowCount = StartRowIndex;
// 添加列数
this.FpSpdCaseNum.Sheets[0].ColumnCount = CellsCount;
//设置默认行高度
this.FpSpdCaseNum.Sheets[0].DefaultRowHeight = 25;
//设置默认列宽度
this.FpSpdCaseNum.Sheets[0].DefaultColumnWidth = 95;
//设置默认居中显示
this.FpSpdCaseNum.Sheets[0].DefaultStyle.HorizontalAlign = HorizontalAlign.Center;
this.FpSpdCaseNum.Sheets[0].DefaultStyle.VerticalAlign = VerticalAlign.Middle;
}
/// <summary>
/// 设置报表表头信息和显示样式
/// </summary>
public void SetFpSpdCaseNumRowHeaderValues()
{
this.FpSpdCaseNum.Sheets[0].Cells[0, 0, 0, CellsCount - 1].Text = this.ddlFactory.SelectedItem.ToString();
this.FpSpdCaseNum.Sheets[0].Rows[0].Height = 45;
this.FpSpdCaseNum.Sheets[0].Rows[0].Font.Size = FontUnit.XLarge;
this.FpSpdCaseNum.Sheets[0].Rows[0].Font.Bold = true;
this.FpSpdCaseNum.Sheets[0].Rows[0].HorizontalAlign = HorizontalAlign.Left;
this.FpSpdCaseNum.Sheets[0].Rows[0].VerticalAlign = VerticalAlign.Middle;
this.FpSpdCaseNum.Sheets[0].Cells[1, 0, 1, 1].Text = "年份:" + this.datepicker.Text;
this.FpSpdCaseNum.Sheets[0].Cells[1, 2, 1, CellsCount - 1].Text = "成品代码:" + this.ddlProduct.SelectedItem.ToString();
this.FpSpdCaseNum.Sheets[0].Rows[1].Height = 36;
this.FpSpdCaseNum.Sheets[0].Rows[1].Font.Size = FontUnit.Larger;
this.FpSpdCaseNum.Sheets[0].Rows[1].Font.Bold = true;
this.FpSpdCaseNum.Sheets[0].Rows[1].HorizontalAlign = HorizontalAlign.Left;
this.FpSpdCaseNum.Sheets[0].Rows[1].VerticalAlign = VerticalAlign.Middle;
this.FpSpdCaseNum.Sheets[0].Rows[2].BackColor = System.Drawing.Color.FromArgb(0, 176, 80);
this.FpSpdCaseNum.Sheets[0].Rows[2].VerticalAlign = VerticalAlign.Middle;
this.FpSpdCaseNum.Sheets[0].Rows[2].HorizontalAlign = HorizontalAlign.Center;
}
protected void btnPrintExcel_Click(object sender, EventArgs e)
{
string FileName = this.ddlFactory.SelectedItem.ToString() + "-" + this.ddlProduct.SelectedItem.ToString() + ".xlsx";
this.FpSpdCaseNum.ActiveSheetView.Protect = false; //设置导出来之后是否只读
this.FpSpdCaseNum.SaveExcelToResponse(Server.UrlEncode(FileName), FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat);
}
/// <summary>
/// 允许合并所有行
/// </summary>
/// <param name="fpMerge"></param>
private void MergeSchedule(bool fpMerge)
{
if (fpMerge)
{
//Merge
this.FpSpdCaseNum.Sheets[0].SetRowMerge(-1, FarPoint.Web.Spread.Model.MergePolicy.Always);
}
else
{
//Un-Merge
this.FpSpdCaseNum.Sheets[0].SetRowMerge(-1, FarPoint.Web.Spread.Model.MergePolicy.None);
}
}