问题现状:
在现有的功能中,导出的数据量较大(上万的数据量),导出至EXCEL后,打开EXCEL及在文档中相关的操作都很慢的说(删一个列就要五分钟,要不就卡在那里不动)。目的:
把导出的信息用选择性粘贴后选保存成数值形式后,对EXCEL文档进行操作的时候速度很快(大家可以试试)。 现在想把导出功能做成类似以上的效果,或者大家有没有什么好的方法可以让导出后的excel文档更容易操作。另外本人电脑配置不错,不存在说机子性能不好的问题。麻烦大家了代码如下: 页面代码:
<span visible="false"><asp:datagrid id="outDg" runat="server"
GridLines="Both" CellSpacing="1" BorderColor="#C0C0FF" BorderWidth="1px" HorizontalAlign="Center"
AutoGenerateColumns="False" CellPadding="2" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" ShowHeader="False">
<AlternatingItemStyle CssClass="AlterRow" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False"></AlternatingItemStyle>
<ItemStyle CssClass="NormalRow" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"></ItemStyle>
<HeaderStyle CssClass="HeaderRow" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="card_type" SortExpression="card_type" HeaderText="<%$ Resources:Resource, psi_CardsType %>">
<HeaderStyle Width="70px" Wrap="False" />
<ItemStyle Width="70px" HorizontalAlign="Left" />
</asp:BoundColumn>
<asp:BoundColumn DataField="DATA1" SortExpression="DATA1" HeaderText="<%$ Resources:Resource, psi_State %>">
<HeaderStyle Width="70px" Wrap="False" />
<ItemStyle Width="70px" CssClass="ItemWrap" HorizontalAlign="Left" />
</asp:BoundColumn>
<asp:BoundColumn DataField="CARDS_MEMO" SortExpression="CARDS_MEMO" HeaderText="<%$ Resources:Resource, psi_Memo %>">
<HeaderStyle Width="100px" Wrap="False" />
<ItemStyle Width="100px" CssClass="ItemWrap" HorizontalAlign="Left" />
</asp:BoundColumn>
</Columns>
<PagerStyle Font-Names="Webdings" Font-Overline="False" NextPageText="4" PrevPageText="3" HorizontalAlign="Center" />
</asp:datagrid></span> CS层导出功能代码:
protected void btnExport_Click(object sender, EventArgs e)
{
//检查按钮权限
if (Common.BLL.Role.IsFunPermissionAllow(((CommonIdentity)Context.User.Identity).intUserID, strmoduleOpt, 6) != true)
{
MessageBox(this, "alert", Resources.Resource.msg_00026); return;
} DataSet ds = (DataSet)Session["for_report"]; for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ds.Tables[0].Rows[i]["dl_cd"] = (Convert.ToString("<div style='mso-number-format:\"\\@\";'>") + ds.Tables[0].Rows[i]["dl_cd"].ToString() + Convert.ToString("</div>"));
ds.Tables[0].Rows[i]["adm_dl_cd"] = (Convert.ToString("<div style='mso-number-format:\"\\@\";'>") + ds.Tables[0].Rows[i]["adm_dl_cd"].ToString() + Convert.ToString("</div>"));
ds.Tables[0].Rows[i]["record_user"] = (Convert.ToString("<div style='mso-number-format:\"\\@\";'>") + ds.Tables[0].Rows[i]["record_user"].ToString() + Convert.ToString("</div>"));
} this.outDg.DataSource = ds.Tables[0].DefaultView;
this.outDg.DataBind(); Response.ContentType = "application/vnd.ms-excel";
string filename = Resources.Resource.psi_EndUserInfoSearch + ".xls";
Response.AddHeader("Content-Disposition", "inline;filename="
+ HttpUtility.UrlEncode(filename, Encoding.UTF8)); Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
//如果输出为Word,修改为以下代码
//Response.ContentType = "application/ms-word"
//Response.AddHeader("Content-Disposition", "inline;filename=test.doc")
StringBuilder sb = new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
sb.Append("<html><body>");
sb.Append("<html><body><table cellspacing='1' cellpadding='2' border=\"1\" style=\"font-family:宋体;\">"
//sb.Append("<table cellspacing='1' cellpadding='2' rules='all' width='100%' border='1'>"
+ " <tr>"
+ "<td align='center' style='width:100%; font-size:large; font-weight:bold;background-color:LightSkyBlue' colspan='40'>" + Resources.Resource.psi_EndUserInfoSearch + "</td>"
+ "</tr>"
+ "<tr>"
+ "<td align='center' style='width:70px; background-color:LightSkyBlue'>" + Resources.Resource.psi_CardsType + "</td>"
...
+ "<td align='center' style='width:100px; background-color:LightSkyBlue'>" + Resources.Resource.psi_Memo + "</td>"
+ "</tr>"
+ "</table>");
outDg.RenderControl(hw);
sb.Append("</body></html>");
Response.Write(sb.ToString());
Response.End();
}要麻烦大家帮我看看以上要怎么优化了。
在现有的功能中,导出的数据量较大(上万的数据量),导出至EXCEL后,打开EXCEL及在文档中相关的操作都很慢的说(删一个列就要五分钟,要不就卡在那里不动)。目的:
把导出的信息用选择性粘贴后选保存成数值形式后,对EXCEL文档进行操作的时候速度很快(大家可以试试)。 现在想把导出功能做成类似以上的效果,或者大家有没有什么好的方法可以让导出后的excel文档更容易操作。另外本人电脑配置不错,不存在说机子性能不好的问题。麻烦大家了代码如下: 页面代码:
<span visible="false"><asp:datagrid id="outDg" runat="server"
GridLines="Both" CellSpacing="1" BorderColor="#C0C0FF" BorderWidth="1px" HorizontalAlign="Center"
AutoGenerateColumns="False" CellPadding="2" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" ShowHeader="False">
<AlternatingItemStyle CssClass="AlterRow" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False"></AlternatingItemStyle>
<ItemStyle CssClass="NormalRow" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"></ItemStyle>
<HeaderStyle CssClass="HeaderRow" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="card_type" SortExpression="card_type" HeaderText="<%$ Resources:Resource, psi_CardsType %>">
<HeaderStyle Width="70px" Wrap="False" />
<ItemStyle Width="70px" HorizontalAlign="Left" />
</asp:BoundColumn>
<asp:BoundColumn DataField="DATA1" SortExpression="DATA1" HeaderText="<%$ Resources:Resource, psi_State %>">
<HeaderStyle Width="70px" Wrap="False" />
<ItemStyle Width="70px" CssClass="ItemWrap" HorizontalAlign="Left" />
</asp:BoundColumn>
<asp:BoundColumn DataField="CARDS_MEMO" SortExpression="CARDS_MEMO" HeaderText="<%$ Resources:Resource, psi_Memo %>">
<HeaderStyle Width="100px" Wrap="False" />
<ItemStyle Width="100px" CssClass="ItemWrap" HorizontalAlign="Left" />
</asp:BoundColumn>
</Columns>
<PagerStyle Font-Names="Webdings" Font-Overline="False" NextPageText="4" PrevPageText="3" HorizontalAlign="Center" />
</asp:datagrid></span> CS层导出功能代码:
protected void btnExport_Click(object sender, EventArgs e)
{
//检查按钮权限
if (Common.BLL.Role.IsFunPermissionAllow(((CommonIdentity)Context.User.Identity).intUserID, strmoduleOpt, 6) != true)
{
MessageBox(this, "alert", Resources.Resource.msg_00026); return;
} DataSet ds = (DataSet)Session["for_report"]; for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ds.Tables[0].Rows[i]["dl_cd"] = (Convert.ToString("<div style='mso-number-format:\"\\@\";'>") + ds.Tables[0].Rows[i]["dl_cd"].ToString() + Convert.ToString("</div>"));
ds.Tables[0].Rows[i]["adm_dl_cd"] = (Convert.ToString("<div style='mso-number-format:\"\\@\";'>") + ds.Tables[0].Rows[i]["adm_dl_cd"].ToString() + Convert.ToString("</div>"));
ds.Tables[0].Rows[i]["record_user"] = (Convert.ToString("<div style='mso-number-format:\"\\@\";'>") + ds.Tables[0].Rows[i]["record_user"].ToString() + Convert.ToString("</div>"));
} this.outDg.DataSource = ds.Tables[0].DefaultView;
this.outDg.DataBind(); Response.ContentType = "application/vnd.ms-excel";
string filename = Resources.Resource.psi_EndUserInfoSearch + ".xls";
Response.AddHeader("Content-Disposition", "inline;filename="
+ HttpUtility.UrlEncode(filename, Encoding.UTF8)); Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
//如果输出为Word,修改为以下代码
//Response.ContentType = "application/ms-word"
//Response.AddHeader("Content-Disposition", "inline;filename=test.doc")
StringBuilder sb = new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
sb.Append("<html><body>");
sb.Append("<html><body><table cellspacing='1' cellpadding='2' border=\"1\" style=\"font-family:宋体;\">"
//sb.Append("<table cellspacing='1' cellpadding='2' rules='all' width='100%' border='1'>"
+ " <tr>"
+ "<td align='center' style='width:100%; font-size:large; font-weight:bold;background-color:LightSkyBlue' colspan='40'>" + Resources.Resource.psi_EndUserInfoSearch + "</td>"
+ "</tr>"
+ "<tr>"
+ "<td align='center' style='width:70px; background-color:LightSkyBlue'>" + Resources.Resource.psi_CardsType + "</td>"
...
+ "<td align='center' style='width:100px; background-color:LightSkyBlue'>" + Resources.Resource.psi_Memo + "</td>"
+ "</tr>"
+ "</table>");
outDg.RenderControl(hw);
sb.Append("</body></html>");
Response.Write(sb.ToString());
Response.End();
}要麻烦大家帮我看看以上要怎么优化了。
导出功能是正常的。不兼容07的,只能适用于office2003的版本。就是想说怎么样才能让导出来的excel在操作的时候能不卡比如两万行的数据,删除某列的时候。