2012-12-28 2 views
0

GridView를 통해 DataSet의 데이터를 Excel로 내보내는 중입니다. 프레임 워크는 2.0입니다. 다음 코드 스 니펫을 사용하고 있습니다.DataSet/Gridview를 Excel로 내보내는 형식 열

Generate_Sequence_Data_BAL objAttBAL = new Generate_Sequence_Data_BAL(); 
    string PlanId = ""; 
    PlanId = Cryptography.Decrypt(Request.QueryString[0].ToString()); 
    //Get the data from database into datatable 
    Response.ClearHeaders(); 
    Response.Clear(); 
    Response.Buffer = true; 
    Response.AddHeader("content-disposition", "attachment;filename=SequenceData_" + Cryptography.Decrypt(Request.QueryString[0].ToString()) + ".xls"); 
    Response.Charset = ""; 
    Response.ContentType = "application/vnd.ms-excel"; 
    StringWriter sw = new StringWriter(); 
    HtmlTextWriter hw = new HtmlTextWriter(sw); 

    DataSet ds = objAttBAL.GetData(Convert.ToInt32(PlanId)); 
    GridView GridView1 = new GridView(); 
    GridView1.RowDataBound += GridView1_RowDataBound; 
    GridView1.DataSource = ds.Tables[0]; 
    GridView1.DataBind(); 

    for (int i = 0; i < GridView1.Rows.Count; i++) 
    { 
     //Apply text style to each Row 
     GridView1.Rows[i].Attributes.Add("class", "textmode"); 
    } 
    GridView1.RenderControl(hw); 
    //style to format numbers to string 
    string style = @"<style>.textmode{mso-number-format:'\@'}</style>"; 
    Response.Write(style); 
    Response.Write(sw.ToString()); 
    Response.Flush(); 
    GridView1.Dispose(); 
    Response.End(); 

'5E02'와 같은 데이터가있는 열이 있습니다. 위의 방법을 사용한 후에도 '5.00E + 02'로 내보내집니다.

SQL에서 검색하는 동안 (') 연결을 시도했지만 그 다음 (5E02) 대신 ('5E02)처럼 표시됩니다.

도와주세요. 또한 gridview 없이도 Excel로 바로 내보낼 수있는 다른 대안을 제안하십시오.

추 신 : 이미 언급했는데 this question & 그것은 작동하지 않으므로 중복되지 않습니다.

답변

0

열의 끝에 Alt + 0160 (Non-breaking Space)을 연결하여 문제를 해결했습니다.

Select <Column Name>+'<Alt+0160>'

는 이제 열은 '5E02'대신 '5.00E + 02'로 수출되고있다.

관련 문제