導出EXCEL設置單元格格式


怎么設置導出的EXCEL文件的列格式 

如何設置導出的EXCEL文件的列格式
在office的EXCEL中我們可以在一個EXCEL文件中,選中一列再點擊鼠標右鍵,選擇設置單元格格式,可以將這一列設為文本格式等;
請問各位,如果我想在導出EXCEL時在代碼中實現這個將列的格式設置為文本格式的功能,要怎樣做呢?
那位能否幫下忙,

------解決方案--------------------
用excel組件導出 
------解決方案--------------------

C# code
//文本:vnd.ms-excel.numberformat:@
//日期:vnd.ms-excel.numberformat:yyyy/mm/dd
//數字:vnd.ms-excel.numberformat::#,##0.00
//貨幣:vnd.ms-excel.numberformat¥#,##0.00
//百分比:vnd.ms-excel.numberformat:#0.00%

//在excel中數字位數大於11位,都會默認以科學技術法出現,所以有E+.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
  for(int i=0;i<e.Row.Cells.Count;i++)
  {
    if(e.Row.RowType==DataControlRowType.DataRow)
    {
      //表示對每一行以字符串的形式輸出
      e.Row.Cells[i].Attributes.Add("style","vnd.ms-excel.numberformat:@");
    }
  }
}
//如果你想對導出的execl的某一行進行以字符串輸出,而不想用科學計數法出現,則需要上面方法,最好對某一列以字符串輸出,excel也是從0列開始的.

------解決方案--------------------
設置單元格的文本 Excel.Application.get_Range(excelApp.Cells[x1, y1], excelApp.Cells[x2, y2]).NumberFormatLocal="@"
------解決方案--------------------
mySheet.Cells(1,9).NumberFormatLocal = "@"
Excel.Range r = mySheet.get_Range(mySheet.Cells[1, 1], mySheet.Cells[1,3]);
r.NumberFormat = "@"; 
r.NumberForma = "0.00_ "
r.NumberForma = "¥#,##0.00;¥-#,##0.00"
r.NumberForma = _"_ ¥* #,##0.00_ ;_ ¥* -#,##0.00_ ;_ ¥* ""-""??_ ;_ @_ "
r.NumberForma = "yyyy-m-d"
r.NumberForma = "[$-F400]h:mm:ss AM/PM"
r.NumberForma = "000000"
myExcel.get_Range(myExcel.Cells[1, 1], myExcel.Cells[1, 1]).Font.Bold = true;
 myExcel.get_Range(myExcel.Cells[1,1],myExcel.Cells[1,1]).Font.Size = 16;
------解決方案--------------------
dataTable 導出
------解決方案--------------------
//文本:vnd.ms-excel.numberformat:@
//日期:vnd.ms-excel.numberformat:yyyy/mm/dd
//數字:vnd.ms-excel.numberformat::#,##0.00
//貨幣:vnd.ms-excel.numberformat¥#,##0.00
//百分比:vnd.ms-excel.numberformat:#0.00%


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM