注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Bioinformatics home

 
 
 

日志

 
 

asp.net excel 四  

2008-06-02 00:15:44|  分类: 编程 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

先循环填充数据,如下:

 1  int index = 0, rownum = 0;

 2                             string ProjNo = "";

 3                             for (i = 0; i < table.Rows.Count; i++)

 4                             {

 5                                 ProjNo = table.Rows[index]["PROJNO"].ToString();

 6                                 if (table.Rows[i]["PROJNO"].ToString() == ProjNo)

 7                                 {

 8                                     wksheet.Cells[3 + i, 1] = rownum + 1;

 9                                     wksheet.Cells[3 + i, 2] = "'" + table.Rows[i]["PROJNO"];   //加上单引号保证以0开头的字符原样输出

10                                     wksheet.Cells[3 + i, 3] = "'" + table.Rows[i]["PROJNAME"];

11                                     wksheet.Cells[3 + i, 4] = "'" + table.Rows[i]["PA_NAME"];

12                                     wksheet.Cells[3 + i, 5] = "'" + table.Rows[i]["BIDER_NAME"];

13                                     wksheet.Cells[3 + i, 6] = table.Rows[i]["BAIL_AMOUNT"];

14                                     wksheet.Cells[3 + i, 7] = table.Rows[i]["NOT_BACK"];

15                                     wksheet.get_Range(wksheet.Cells[3 + i, 1], wksheet.Cells[3 + i, 7]).Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);

16                                     continue;

17                                 }

18 

19                                 index = i;

20                                 rownum++;

21                                 i--;

22 

23                             }

下面合并前三列相同内容的单元:

 1  //合并前三列操作

 2                             int m = 1, rowid = 3, k;

 3                             string projName = "";

 4                             for (k = 3; k <= i + 2; k++)

 5                             {

 6                                 if (Convert.ToInt32(wksheet.get_Range(wksheet.Cells[k, 1], wksheet.Cells[k, 1]).Value2) == m)

 7                                 {

 8                                     ProjNo = wksheet.get_Range(wksheet.Cells[k, 2], wksheet.Cells[k, 2]).Value2.ToString();

 9                                     projName = wksheet.get_Range(wksheet.Cells[k, 3], wksheet.Cells[k, 3]).Value2.ToString();

10                                     wksheet.get_Range(wksheet.Cells[k, 1], wksheet.Cells[k, 1]).Value2 = "";

11                                     wksheet.get_Range(wksheet.Cells[k, 2], wksheet.Cells[k, 2]).Value2 = "";

12                                     wksheet.get_Range(wksheet.Cells[k, 3], wksheet.Cells[k, 3]).Value2 = "";

13                                     continue;

14                                 }

15                                 wksheet.get_Range(wksheet.Cells[rowid, 1], wksheet.Cells[k - 1, 1]).Merge(Missing.Value);

16                                 wksheet.get_Range(wksheet.Cells[rowid, 1], wksheet.Cells[rowid, 1]).Value2 = m;

17 

18                                 wksheet.get_Range(wksheet.Cells[rowid, 2], wksheet.Cells[k - 1, 2]).Merge(Missing.Value);

19                                 wksheet.get_Range(wksheet.Cells[rowid, 2], wksheet.Cells[rowid, 2]).Value2 = "'" + ProjNo;

20 

21                                 wksheet.get_Range(wksheet.Cells[rowid, 3], wksheet.Cells[k - 1, 3]).Merge(Missing.Value);

22                                 wksheet.get_Range(wksheet.Cells[rowid, 3], wksheet.Cells[rowid, 3]).Value2 = "'" + projName;

23 

24                                 m++;

25                                 rowid = k;

26                                 k--;

27                             }

28                             //跳出循环后合并最后一个招标项目

29 

30                             wksheet.get_Range(wksheet.Cells[rowid, 1], wksheet.Cells[k - 1, 1]).Merge(Missing.Value);

31                             wksheet.get_Range(wksheet.Cells[rowid, 1], wksheet.Cells[rowid, 1]).Value2 = m;

32 

33                             wksheet.get_Range(wksheet.Cells[rowid, 2], wksheet.Cells[k - 1, 2]).Merge(Missing.Value);

34                             wksheet.get_Range(wksheet.Cells[rowid, 2], wksheet.Cells[rowid, 2]).Value2 = "'" + ProjNo;

35 

36                             wksheet.get_Range(wksheet.Cells[rowid, 3], wksheet.Cells[k - 1, 3]).Merge(Missing.Value);

37                             wksheet.get_Range(wksheet.Cells[rowid, 3], wksheet.Cells[rowid, 3]).Value2 = "'" + projName;

  评论这张
 
阅读(473)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017