DataGrid 匯出 EXCEL
附上一些常用的格式
- 文本: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方法
Private Sub toExcel()
export("BIG5", "Excel_Fill.xls", "application/vnd.ms-excel")
End Sub
'匯出Word方法
Private Sub toWord()
export("BIG5", "Word_Fill.doc", "application/vnd.ms-word")
End Sub
而Excel會無法判別中文的原因時...中文版Excel預設是big5...(也就是說用big5去讀utf-8...一定看不到字的...)
要嘛就是把ASP.NET的頁面設成big5
在web.config裡面可以設定...
把
改成
要嘛就是匯出成Excel時,自己加上html的標籤
(這裡是你原本匯出的內容)
Response.Clear()
Response.Buffer = True
Response.Charset = "utf-8"
Response.AddHeader("content-disposition", "attachment; filename=" & txt_req_no.Text.ToUpper.Trim & ".xls")
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8") ' BIG5 or utf-8
Response.ContentType = "application/vnd.ms-excel"
Me.EnableViewState = False
Dim tw As StringWriter = New System.IO.StringWriter
Dim hw As HtmlTextWriter = New HtmlTextWriter(tw)
MyDataGrid.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
沒有留言:
張貼留言