怎样把repeater所有数据导出到excel中?
怎样把repeater所有数据导出到excel中?一下方法只能导出当前页的数据,而不是所有页的数据?
C# code
public override void VerifyRenderingInServerForm(System .Web .UI .Control control)
{
}
protected void btnPrint_Click(object sender, EventArgs e)
{
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
this.Productlists.RenderControl(hw);
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Productlists.Page.EnableViewState = true;
Response.AppendHeader("Content-Disposition", "attachment;filename=Teacher.xls");
Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=GB2312\"><title> Copyright by SDU</title></head><body><center>");
Response.Write(sw.ToString());
Response.Write("</center></body></html>");
Response.End();
}
------解决方案--------------------Workbook workbook = new Workbook();
workbook.Open(Server.MapPath("~/temp/ReportSaler.xls"));
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;
int RowNo = 2;
DataTable dt =
oProductItem.SalerList(Convert.ToInt32(ViewState["SupplierId"]), ViewState["OrderField"].ToString(),
ViewState["IsAsc"].ToString(), dtpStart.Value, dtpEnd.Value);
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = oProductItem.ShoppingCartProductInfo(Convert.ToInt32(dt.Rows[i]["ProductItemId"]));
string ProductNo = "";
string ProductName = "";
string CreateTime = "";
string Type = "";
string Inventory = "";
string ListPrice = "";
string DiscountPrice = "";
if (dr != null)
{
ProductNo = dr["ProductNo"].ToString();
ProductName = dr["Name"].ToString();
CreateTime = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(dr["StartTime"].ToString()));
Type = showType(dr["ProductTypeId"].ToString().Trim());
Inventory = dr["Inventory"].ToString();
ListPrice = dr["ListPrice"].ToString();
DiscountPrice = dr["DiscountPrice"].ToString();
}
cells["A" + RowNo].PutValue(i+1);
cells["B" + RowNo].PutValue(dt.Rows[i]["Nums"].ToString());
cells["C" + RowNo].PutValue(ProductNo);
cells["D" + RowNo].PutValue(ProductName);
cells["E" + RowNo].PutValue(CreateTime);
cells["F" + RowNo].PutValue(Type);
cells["G" + RowNo].PutValue(Inventory);
cells["H" + RowNo].PutValue(ListPrice);
cells["I" + RowNo].PutValue(DiscountPrice);
RowNo++;
}