以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]能否请高手帮助精简代码?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=26383)

--  作者:samica
--  发布时间: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这个软件,觉得很实用。但是不会编程,请高手帮忙,万分感谢!


--  作者:sloyy
--  发布时间:2012/12/2 12:49:00
--  
直接用excel 做好报表模板
--  作者:samica
--  发布时间:2012/12/2 13:27:00
--  
我的意思是在一张报表模版上,灵活实现各年份、月份的数据统计。
--  作者:sgs
--  发布时间:2012/12/2 15:45:00
--  
楼主传文件上来吧,这样有点抽象
--  作者:lin_hailun
--  发布时间:2012/12/3 9:58:00
--  
 做一张excel模板,报告日期换成特殊的字符。然后再生产报表前,遍历excel表格的单元格,遇到特殊字符的话,就替换成你的日期。

 这样比较好。

 http://www.foxtable.com/help/topics/1507.htm

------------------------------

 还有一种,就是使用标记,那样就不必算是第几行第几列了。

 http://www.foxtable.com/help/topics/1953.htm
--  作者:samica
--  发布时间:2012/12/4 20:11:00
--  
最近比较忙,没回来看,感谢几位老师的帮助,在一张模版上灵活实现的方法已经找到。再次对三位老师的帮助表示感谢!
--  作者:zerov
--  发布时间:2012/12/4 21:19:00
--  

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


--  作者:samica
--  发布时间: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)