DataGrid:
Asp.Net WebForm中DataGrid导出的时候,在ItemDataBound内
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Cells[0].Attributes.Add("style","vnd.ms-excel.numberformat:@");
}
如果在WinForm内则可以
Excel.Range range = (Excel.Range)worksheet.Cells[1,1];
range.NumberFormat = Excel.XlParameterDataType.xlParamTypeUnknown;
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Cells[0].Attributes.Add("style","vnd.ms-excel.numberformat:@");
}
如果在WinForm内则可以
Excel.Range range = (Excel.Range)worksheet.Cells[1,1];
range.NumberFormat = Excel.XlParameterDataType.xlParamTypeUnknown;
VB:
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Cells(1).Attributes.Add("style", "vnd.ms-excel.numberformat:@")
End If
e.Item.Cells(1).Attributes.Add("style", "vnd.ms-excel.numberformat:@")
End If
如果是Label,则在<td>的style中加上:
<td style="height: 22px; vnd.ms-excel.numberformat:@" bgcolor="#eff3fb">
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label></td>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label></td>
如果是Gridview,(07.12.13 Update)
则需要在后台打印click事件代码中加两句话:
// More Codes
string style = @"<style> .text { mso-number-format:\@; } </script> ";
Response.Write(style);
Response.Output.Write(oStringWriter.ToString());