Foxtable(狐表)用户栏目专家坐堂 → [求助]能否请高手帮助精简代码?


  共有10585人关注过本帖树形打印复制链接

主题:[求助]能否请高手帮助精简代码?

帅哥哟,离线,有人找我吗?
samica
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:148 积分:1036 威望:0 精华:0 注册:2012/11/26 13:05:00
[求助]能否请高手帮助精简代码?  发帖心情 Post By:2012/12/2 12:26:00 [显示全部帖子]

If e.Form.Controls("ComboBox2").value= "10月报表" Then
Dim dt As DataTable = DataTables("表名")
Dim rq_b As Date = e.Form.Controls("datetimepicker2").value
Dim rq_e As Date = e.Form.Controls("datetimepicker3").value
Dim Book As New XLS.Book(ProjectPath & "Attachments\报表.xls") '打开模板
Dim fl As String = ProjectPath & "Reports\报表.xls"
Dim Sheet As XLS.Sheet = Book.Sheets("1")

Sheet(0,17).Value = rq_e

Sheet(7,1).Value = "aa"
Sheet(8,1).Value = "bb"
Sheet(9,1).Value = "cc"
Sheet(10,1).Value = "dd"
Sheet(11,1).Value = "ee"
Sheet(12,1).Value = "ff"

Sheet(6,2).Value =dt.Compute("Sum(登记人数)"," [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(7,2).Value =dt.Compute("Sum(登记人数)","[站名]='aa' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(8,2).Value =dt.Compute("Sum(登记人数)","[站名]='bb' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(9,2).Value =dt.Compute("Sum(登记人数)","[站名]='cc' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(10,2).Value =dt.Compute("Sum(登记人数)","[站名]='dd' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(11,2).Value =dt.Compute("Sum(登记人数)","[站名]='ee' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(12,2).Value =dt.Compute("Sum(登记人数)","[站名]='ff' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(14,2).Value =dt.Compute("Sum(登记人数)","[报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(15,2).Value =dt.Compute("Sum(登记人数)","[报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")

Sheet(6,3).Value =dt.Compute("Sum(测血压人数)"," [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(7,3).Value =dt.Compute("Sum(测血压人数)","[站名]='aa' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(8,3).Value =dt.Compute("Sum(测血压人数)","[站名]='bb' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(9,3).Value =dt.Compute("Sum(测血压人数)","[站名]='cc' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(10,3).Value =dt.Compute("Sum(测血压人数)","[站名]='dd' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(11,3).Value =dt.Compute("Sum(测血压人数)","[站名]='ee' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(12,3).Value =dt.Compute("Sum(测血压人数)","[站名]='ff' and [报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(14,3).Value =dt.Compute("Sum(测血压人数)","[报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
Sheet(15,3).Value =dt.Compute("Sum(测血压人数)","[报告日期]>='" & rq_b & "' And [报告日期]<='" & rq_e & "'")
……

……

有很多条这样的代码,用于构建excel报表。请高手帮助一下,有没有什么方法精简一下?或者有没有其他的思路,更正确实现?

本人刚接触foxtable这个软件,觉得很实用。但是不会编程,请高手帮忙,万分感谢!


 回到顶部
帅哥哟,离线,有人找我吗?
samica
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:148 积分:1036 威望:0 精华:0 注册:2012/11/26 13:05:00
  发帖心情 Post By:2012/12/2 13:27:00 [显示全部帖子]

我的意思是在一张报表模版上,灵活实现各年份、月份的数据统计。

 回到顶部
帅哥哟,离线,有人找我吗?
samica
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:148 积分:1036 威望:0 精华:0 注册:2012/11/26 13:05:00
  发帖心情 Post By:2012/12/4 20:11:00 [显示全部帖子]

最近比较忙,没回来看,感谢几位老师的帮助,在一张模版上灵活实现的方法已经找到。再次对三位老师的帮助表示感谢!

 回到顶部
帅哥哟,离线,有人找我吗?
samica
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:148 积分:1036 威望:0 精华:0 注册:2012/11/26 13:05:00
  发帖心情 Post By:2012/12/7 21:44:00 [显示全部帖子]

以下是引用zerov在2012-12-4 21:19:00的发言:

  既然找到好方法了,就拿来分享一下吧?

也不是啥好方法,就是增加了两个日期控件

Dim rq_b As Date = e.Form.Controls("datetimepicker2").value
Dim rq_e As Date = e.Form.Controls("datetimepicker3").value
Dim rq_d As Date = rq_e.AddMonths(-1)


 回到顶部