导出DataGrid数据为Excel让用户下载(转载)
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;