Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
由于在生成excel时,需要定义各种不同的数据样式,如:
Dim Style1 As XLS.Style = Book.NewStyle() '双精度样式
Style1.BorderTop = XLS.LineStyleEnum.Thin
Style1.BorderBottom = XLS.LineStyleEnum.Thin
Style1.BorderLeft = XLS.LineStyleEnum.Thin
Style1.BorderRight = XLS.LineStyleEnum.Thin
Style1.BorderColorTop = Color.Gray
Style1.BorderColorBottom = Color.Gray
Style1.BorderColorLeft = Color.Gray
Style1.BorderColorRight = Color.Gray
Style1.Format = Format("0.00")
Dim Style2 As XLS.Style = Book.NewStyle() '百分比样式
Style2.BorderTop = XLS.LineStyleEnum.Thin
Style2.BorderBottom = XLS.LineStyleEnum.Thin
Style2.BorderLeft = XLS.LineStyleEnum.Thin
Style2.BorderRight = XLS.LineStyleEnum.Thin
Style2.BorderColorTop = Color.Gray
Style2.BorderColorBottom = Color.Gray
Style2.BorderColorLeft = Color.Gray
Style2.BorderColorRight = Color.Gray
Style2.Format = Format("0.00%")
Dim Style3 As XLS.Style = Book.NewStyle() '日期样式
Style3.BorderTop = XLS.LineStyleEnum.Thin
Style3.BorderBottom = XLS.LineStyleEnum.Thin
Style3.BorderLeft = XLS.LineStyleEnum.Thin
Style3.BorderRight = XLS.LineStyleEnum.Thin
Style3.BorderColorTop = Color.Gray
Style3.BorderColorBottom = Color.Gray
Style3.BorderColorLeft = Color.Gray
Style3.BorderColorRight = Color.Gray
Style3.Format = Format("yyyy-MM-dd")
。。。
通过上面的代码可以看出,每个样式的Border类设置都是一样的,只有format不一样。怎样简化这样的代码呢?我想一次性定义多个样式,然后用循环的方式把每个样式的Border类属性统一设置。这样的话,代码就很精简了。但测试了多次,都不成功。请指教!
Dim s(2) As XLS.Style
For i As Integer = 0 To 2
S(i) = Book.NewStyle
S(i).BorderTop = XLS.LineStyleEnum.Thin
S(i).BorderBottom = XLS.LineStyleEnum.Thin
S(i).BorderLeft = XLS.LineStyleEnum.Thin
S(i).BorderRight = XLS.LineStyleEnum.Thin
S(i).BorderColorTop = Color.Gray
S(i).BorderColorBottom = Color.Gray
S(i).BorderColorLeft = Color.Gray
S(i).BorderColorRight = Color.Gray
Next
S(0).Format = Format("0.00")
S(1).Format = Format("0.00%")
S(2).Format = Format("yyyy-MM-dd")
收藏学习了!