c#写入Excel表格的数据不完整是什么原因 如果是文本数据使用oledb写入,或者使用三方组件都行。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 将数据导出到Excel并进行格式化希望对您有所帮助SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bind(); } } protected void Button1_Click(object sender, EventArgs e) { Export("application/ms-excel", "商品信息表.xls"); } private void Export(string FileType, string FileName) { Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF7; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString()); Response.ContentType = FileType; this.EnableViewState = false; StringWriter tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); GridView1.RenderControl(hw); Response.Write(tw.ToString()); Response.End(); } private void bind() { SqlDataAdapter myda = new SqlDataAdapter("select top 10 GoodsID as 商品ID,GoodsName as 商品名称,GoodsIntroduce as 商品介绍,GoodsPrice as 商品价格 from tb_GoodsInfo", sqlcon); DataSet myds = new DataSet(); sqlcon.Open(); myda.Fill(myds); sqlcon.Close(); GridView1.DataSource = myds; GridView1.DataBind(); } public override void VerifyRenderingInServerForm(Control control) { } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[3].Attributes.Add("style", "vnd.ms-excel.numberformat:¥#,###.00"); } } 先检查到底是数据来源有问题还是写入EXCEL有问题。盲目怀疑只能是在瞎忙叨。如果数据来源本身就是没有B的信息,你代码再怎么改,也不可能凭空生成B的信息啊 DllImport的使用 2张图中的point啥子回事嘛?麻烦大虾告知一下撒 缓存应该放在哪一层比较好一点?数据处理层?业务逻辑层?表现层?好像放在那一层都有道理,又好像放在那一层都不是很好。大家讨论! 问一个mail得正则表达式 能指定winform使用的配置文件吗? 求复制数据表记录的嵌套算法 关于C#视频的问题?高手请进,大哥、大姐进来帮小弟看看呀?急呀???? 某类获取主窗体中的public变量 "C#"怎么读呀??? 求教大神关于C++转C#的问题 求教,为什么这个程序更新和删除不了数据? WPF 数据绑定问题
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "商品信息表.xls");
}
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
private void bind()
{
SqlDataAdapter myda = new SqlDataAdapter("select top 10 GoodsID as 商品ID,GoodsName as 商品名称,GoodsIntroduce as 商品介绍,GoodsPrice as 商品价格 from tb_GoodsInfo", sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds);
sqlcon.Close();
GridView1.DataSource = myds;
GridView1.DataBind();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[3].Attributes.Add("style", "vnd.ms-excel.numberformat:¥#,###.00");
}
}