关于导出数据到Excel时,单元格数据类型的控制
1.用流导出excel :<% response.ContentType ="application/vnd.ms-excel" Response.AddHeader "content-Disposition","filename=导出后的文件名称.xls;attachment;" Response.Flush %> <table> <tr> <td style="mso-number-format:'\@';">0001</tr> <td>0002</td> </tr> <table>
2:在DataGird中显示时:
在ItemDataBound事件中写
'modi by mingfei 20070712防止身份证号导出时变换成科学计数cell(4)为字符型数字
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
e.Item.Cells(4).Attributes.Add("style", "vnd.ms-excel.numberformat:@")
End If
3. xSt.get_Range(excel.Cells[index_y + 6, 2], excel.Cells[index_y + 6, 2]).NumberFormatLocal = "@";
浙公网安备 33010602011771号