如何导出带有前导零的gridview数据? [英] How to export gridview data with leading zero?
本文介绍了如何导出带有前导零的gridview数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将数据从Gridview导出到excel但是它从0开始为零。
我尝试过:
Response.Clear();
Response.Buffer = true;
Response.AddHeader(content-disposition,attachment; filename = GridViewExport.xls);
Response.Charset =;
Response.ContentType =application / vnd.ms-excel;
using(StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
//导出所有页面
GridView1.AllowPaging = false;
GridView1.HeaderRow.BackColor = Color.White;
foreach(GridView1.HeaderRow.Cells中的TableCell单元格)
{
cell.BackColor = GridView1.HeaderStyle.BackColor;
}
foreach(GridView1.Rows中的GridViewRow行)
{
row.BackColor = Color.White;
foreach(TableCell cell in row.Cells)
{
if(row.RowIndex%2 == 0)
{
cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
}
其他
{
cell.BackColor = GridView1.RowStyle.BackColor;
}
cell.CssClass =textmode;
//cell.Style.Add(\"style,mso-number-format:\\ @);
}
}
GridView1.RenderControl(hw);
//样式将数字格式化为字符串
string style = @< style> .textmode {}< / style>;
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
解决方案
这可以帮助您解决问题..接受任何更正。
此类表示lookup_client_name内容数据的结构
公共类RowContent
{
public string SomeProperty {get;组; } $ / $
公共字符串PreserveValues {get;组; }
}
gv.DataSource = db.lookup_client_name。
选择(i => new
{
SomeProperty = i.SomeProperty,
PreserveValues ='+ i.PreserveValues +'
})。ToList();
I export data from Gridview to excel but it left zero where value start with zero.
What I have tried:
Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); //To Export all pages GridView1.AllowPaging = false; GridView1.HeaderRow.BackColor = Color.White; foreach (TableCell cell in GridView1.HeaderRow.Cells) { cell.BackColor = GridView1.HeaderStyle.BackColor; } foreach (GridViewRow row in GridView1.Rows) { row.BackColor = Color.White; foreach (TableCell cell in row.Cells) { if (row.RowIndex % 2 == 0) { cell.BackColor = GridView1.AlternatingRowStyle.BackColor; } else { cell.BackColor = GridView1.RowStyle.BackColor; } cell.CssClass = "textmode"; //cell.Style.Add("style", "mso-number-format:\\@"); } } GridView1.RenderControl(hw); //style to format numbers to string string style = @"<style> .textmode { } </style>"; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); }
解决方案
This could help your issue.. Any corrections accepted.
this class represents the structure of the data of the lookup_client_name content
public class RowContent
{
public string SomeProperty{ get; set; }
public string PreserveValues{ get; set; }
}
gv.DataSource = db.lookup_client_name.
Select(i => new
{
SomeProperty = i.SomeProperty,
PreserveValues = "'" + i.PreserveValues + "'"
}).ToList();
这篇关于如何导出带有前导零的gridview数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文