2011-09-13 21 views
1

私のコードは、この..エクスポートされたExcelファイルには、私の言語はペルシャ語であると私はペルシャ文字をエクスポート...

SqlConnection scn = new SqlConnection(clspublic.GetConnectionString()); 
      SqlCommand scm = new SqlCommand("SELECT  tblProduct.fName, tblCars.fCarType, tblProduct.fTechnicalNo, tblProduct.fProductionDate, tblProduct.fEngineType, tblProduct.fNoinStock, tblProduct.fNoforCar, tblProduct.fPrice, tblProduct.fImage, tblProduct.fDesc, tblParts.fPart, tblLevels.fLevel, tblProduct.fUnitType, tblProduct.fRatio, tblProduct.fDirham, tblProduct.fExtraMoney, tblProduct.fChanged FROM   tblProduct INNER JOIN tblCars ON tblProduct.fxCarType = tblCars.fId INNER JOIN tblParts ON tblProduct.fxPartType = tblParts.fId INNER JOIN tblLevels ON tblProduct.fxLevel = tblLevels.fId", scn); 
       scn.Open(); 
       GridView3.DataSource = scm.ExecuteReader(); 
       GridView3.DataBind(); 
       scn.Close(); 

       Response.Clear(); 
       Response.Buffer = true; 

       Response.AddHeader("content-disposition", "attachment;filename=OrderReport.xls"); 
       Response.Charset = ""; 
       Response.ContentType = "application/vnd.ms-excel"; 
       StringWriter sw = new StringWriter(); 
       HtmlTextWriter hw = new HtmlTextWriter(sw); 

       GridView3.AllowPaging = false; 

       //Change the Header Row back to white color 
       GridView3.HeaderRow.Style.Add("background-color", "#FFFFFF"); 

       //Apply style to Individual Cells 
       GridView3.HeaderRow.Cells[0].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[1].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[2].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[3].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[4].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[5].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[6].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[7].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[8].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[9].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[10].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[11].Style.Add("background-color", "green"); 
       GridView3.HeaderRow.Cells[12].Style.Add("background-color", "green"); 

       for (int i = 0; i < GridView3.Rows.Count; i++) 
       { 
        GridViewRow row = GridView3.Rows[i]; 

        //Change Color back to white 
        row.BackColor = System.Drawing.Color.White; 

        //Apply text style to each Row 
        row.Attributes.Add("class", "textmode"); 

        //Apply style to Individual Cells of Alternating Row 
        if (i % 2 != 0) 
        { 
         row.Cells[0].Style.Add("background-color", "#C2D69B"); 
         row.Cells[1].Style.Add("background-color", "#C2D69B"); 
         row.Cells[2].Style.Add("background-color", "#C2D69B"); 
         row.Cells[3].Style.Add("background-color", "#C2D69B"); 
         row.Cells[4].Style.Add("background-color", "#C2D69B"); 
         row.Cells[5].Style.Add("background-color", "#C2D69B"); 
         row.Cells[6].Style.Add("background-color", "#C2D69B"); 
         row.Cells[7].Style.Add("background-color", "#C2D69B"); 
         row.Cells[8].Style.Add("background-color", "#C2D69B"); 
         row.Cells[9].Style.Add("background-color", "#C2D69B"); 
         row.Cells[10].Style.Add("background-color", "#C2D69B"); 
         row.Cells[11].Style.Add("background-color", "#C2D69B"); 
         row.Cells[12].Style.Add("background-color", "#C2D69B"); 
        } 
       } 
       GridView3.RenderControl(hw); 

       //style to format numbers to string 
       string style = @"<style> .textmode { mso-number-format:\@; } </style>"; 
       Response.Write(style); 
       Response.Output.Write(sw.ToString()); 
       Response.Flush(); 
       Response.End(); 

をしかし、私は、エクスポートボタンをクリックしたとき、それは列にいくつかの未知の文字を生成し、未知の文字を生成しています。

ÙاØ'رکاÙ... U「カローラ04111から22360 1 1312000ÙابریÚ2007〜2005©1800 ccの1عدد:

は、それがこの示し1.27 303.8 0

どうすればこの問題を解決できますか?

+0

これは単なる推測ですが、何か他のものににResponse.Charsetを設定するかどうかを確認し、 'にResponse.Charsetは= "UTF-8";' – Oliver

+0

が、私はこれを使用して..しかし、それは動作していません.. –

+0

これはここで解決されました:http://stackoverflow.com/questions/1679656/asp-net-excel-export-encoding-problem – DanielCuadra

答えて

関連する問題