如何使用dataformtstring propery将文本格式化为excel [英] How to format at text into excel using dataformtstring propery

查看:257
本文介绍了如何使用dataformtstring propery将文本格式化为excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



需要帮助才能解决一个问题。

我正在研究现有的asp.net应用程序从表中提取数据并存储在excel中。

这是通过将结果放入网格然后将网格数据写入excel来完成的。



我们从数据集中获取数据并添加到网格中;



 foreach(dsReports.Tables中的DataColumn cCol [0 ] .Columns)
{
dgReport.Columns.Add(CreateBoundColumn(cCol));
}



 private BoundColumn CreateBoundColumn(DataColumn dcol)
{
BoundColumn bcol = new BoundColumn();
bcol.DataField = dcol.ColumnName;
bcol.HeaderText = resource.GetString(dcol.ColumnName);
bcol.DataFormatString ={0};

返回bcol;
}







但我的其中一列的值如下:

 1-4 
5-10
11-20





显示为:

 4-Jan 
10-May
20-Nov





文本在解压缩为excel时自动转换为日期格式。



请帮忙。在此先感谢。



问候,

Swati

解决方案

Add'价值开头像



'1-4

'5-10

'11 -20

Hello All,

Need help to solve one issue.
I am working on existing asp.net application where in I have to extract data from the table and stored in an excel.
This is done by putting the result into grid and then grid data is written to the excel.

We are getting data from dataset and adding to the grid like;

foreach (DataColumn cCol in dsReports.Tables[0].Columns)
{
	dgReport.Columns.Add(CreateBoundColumn(cCol));                            
}


private BoundColumn CreateBoundColumn(DataColumn dcol)
 {
            BoundColumn bcol = new BoundColumn(); 
            bcol.DataField = dcol.ColumnName;
            bcol.HeaderText = resource.GetString(dcol.ColumnName); 
            bcol.DataFormatString = "{0}";
              
            return bcol;
 }




But my one of the columns has values like:

1-4
5-10
11-20



Which are getting displayed as:

4-Jan
10-May
20-Nov



The text automatically converted into date format when extracted to excel.

Please help. Thanks in advance.

Regards,
Swati

解决方案

Add ' at the value beginning like

'1-4
'5-10
'11-20


这篇关于如何使用dataformtstring propery将文本格式化为excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆