Spread for ASP.NET 导出Excel问题

想去云南 2014-09-19 11:55:18
你好!!!
这边存在保存Excel的问题:
1:保存后的Excel显示不对,单元格没有合并。
2:我的前台保存按钮点击只能保存一次,点击第二次就没有反应了。
3:效果图请参考下图。
4:我这个项目很急,希望得到赶紧的解决。


代码如下:
1:前台代码如下:
<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>

2:后台代码如下:

----------------------------------------------------------------------------------------------------------
2.1:页面一开始的设置
  protected void Page_Load(object sender, EventArgs e)
{
this.FpSpdCaseNum.SaveViewStateToSession = false;
this.FpSpdCaseNum.Sheets[0].AllowPage = false;
MergeSchedule(true);
}

----------------------------------------------------------------------------------------------------------
2.2:点击查询的一些数据显示样式设置
/// <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;
}

----------------------------------------------------------------------------------------------------------
2.3:点击保存Excel按钮事件
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);
}
}
...全文
994 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我们查了一下最新版,发现Spread for ASP.NET 7.0 V3 中已经解决了这个问题。 请使用最新版。 下载链接

5,139

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧