Member 12962919 Ответов: 1

Как экспортировать таблицы данных с нуля?


Я экспортирую данные из Gridview в excel, но он оставил ноль там, где значение начинается с нуля.

Что я уже пробовал:

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();
    }

1 Ответов

Рейтинг:
7

Mr Bhanu Prasad

Это может помочь вашей проблеме.. Любые исправления принимаются.

этот класс представляет структуру данных содержимого lookup_client_name
публичный класс RowContent
{
public string SomeProperty{ get; set; }
public string PreserveValues{ get; set; }
}
гв.Источник данных = БД.lookup_client_name.
Выберите (i = & gt; new
{
SomeProperty = я.SomeProperty,
PreserveValues = "'" + i. PreserveValues +"'"
}).Список();


Member 12962919

я уже пробовал что-то подобное. если я добавлю "в значение", то оно сохранится как есть. например, "05"