Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共15 条记录, 每页显示 10 条, 页签: [1] [2]
[浏览完整版]

标题:求教,有关设置表格样式

1楼
baoxyang 发表于:2010/3/5 9:24:00
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim
S1 As XLS.Style = Book.NewStyle()
Dim S2 As XLS.Style = Book.NewStyle()

希望这两种样式都可生效,先执行S1样式,再按S2样式.可否实现?
2楼
yangming 发表于:2010/3/5 9:38:00

是可执行二次,但是你看到的结果仍是第二次的

3楼
baoxyang 发表于:2010/3/5 9:53:00
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim
S1 As XLS.Style = Book.NewStyle()
s1.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
s1.Style.TextAlignVert = prt.AlignVertEnum.Center
'
 
Dim s2 As XLS.Style = Book.NewStyle
S2.Format = "yyyy-MM-dd"
其实目的是,想在s1样式设置完成后,再对判断字段为日期列进行转换成日期格式。目前遇到问题是,先设置好基本样式(s1样式),再设置S2样式无法实现,请杨版帮忙,谢了!
4楼
yangming 发表于:2010/3/5 14:00:00
可以先执行S1,然后单独对日期列进行S2,下列中假设日期列是第三列
For r As Integer = 0 to dt.rows.Count -1+2
            Sheet(r,2).Style = S2  
    Next


也可以写成:Sheet.Cols(2).Style=S2
5楼
baoxyang 发表于:2010/3/5 14:06:00
我是这样的设计的,S1样式设置成功,s2样式不成功。Sheet(r,2).Style = S2  和Sheet.Cols(2).Style=S2 两种都试过,都不成功。不知何原因?是否你试过可以吗?
6楼
mr725 发表于:2010/3/5 15:18:00
分开来定义Sheet试一试:
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim
S1 As XLS.Style = Book.NewStyle()
......

Dim Sheet2 As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim S2 As XLS.Style = Book2.NewStyle()

最好把代码都贴出来,一节子代码真是难为大家了。
7楼
baoxyang 发表于:2010/3/5 15:26:00

Dim s1 as XLS.LineStyleEnum
Dim s2 as XLS.LineStyleEnum
Dim s3 as XLS.LineStyleEnum
Dim s4 as XLS.LineStyleEnum
Dim s5 as XLS.AlignHorzEnum
Dim s6 as XLS.AlignVertEnum
select case e.form.controls("Combobox1").value
       case "无"
            s1 = XLS.LineStyleEnum.None
       case "粗线"
            s1 = XLS.LineStyleEnum.Thick
       case "细线"
            s1 = XLS.LineStyleEnum.Thin
       case "点线"
            s1 = XLS.LineStyleEnum.Dotted
       case "双实线"
            s1 = XLS.LineStyleEnum.Double
       case "虚线"
            s1 = XLS.LineStyleEnum.Dashed
       case "中等实线"
            s1 = XLS.LineStyleEnum.Medium
       case "中等的(短线+点+点)"
            s1 = XLS.LineStyleEnum.ThinDashDotDotted
       case "中等的(短线+点)"
            s1 = XLS.LineStyleEnum.ThinDashDotted
       case "中等虚线"
            s1 = XLS.LineStyleEnum.MediumDashed
end select
select case e.form.controls("Combobox3").value
       case "无"
            s2 = XLS.LineStyleEnum.None
       case "粗线"
            s2 = XLS.LineStyleEnum.Thick
       case "细线"
            s2 = XLS.LineStyleEnum.Thin
       case "点线"
            s2 = XLS.LineStyleEnum.Dotted
       case "双实线"
            s2 = XLS.LineStyleEnum.Double
       case "虚线"
            s2 = XLS.LineStyleEnum.Dashed
       case "中等实线"
            s2 = XLS.LineStyleEnum.Medium
       case "中等的(短线+点+点)"
            s2 = XLS.LineStyleEnum.ThinDashDotDotted
       case "中等的(短线+点)"
            s2 = XLS.LineStyleEnum.ThinDashDotted
       case "中等虚线"
            s2 = XLS.LineStyleEnum.MediumDashed
end select
select case e.form.controls("Combobox4").value
       case "无"
            s3 = XLS.LineStyleEnum.None
       case "粗线"
            s3 = XLS.LineStyleEnum.Thick
       case "细线"
            s3 = XLS.LineStyleEnum.Thin
       case "点线"
            s3 = XLS.LineStyleEnum.Dotted
       case "双实线"
            s3 = XLS.LineStyleEnum.Double
       case "虚线"
            s3 = XLS.LineStyleEnum.Dashed
       case "中等实线"
            s3 = XLS.LineStyleEnum.Medium
       case "中等的(短线+点+点)"
            s3 = XLS.LineStyleEnum.ThinDashDotDotted
       case "中等的(短线+点)"
            s3 = XLS.LineStyleEnum.ThinDashDotted
       case "中等虚线"
            s3 = XLS.LineStyleEnum.MediumDashed
end select
select case e.form.controls("Combobox5").value
       case "无"
            s4 = XLS.LineStyleEnum.None
       case "粗线"
            s4 = XLS.LineStyleEnum.Thick
       case "细线"
            s4 = XLS.LineStyleEnum.Thin
       case "点线"
            s4 = XLS.LineStyleEnum.Dotted
       case "双实线"
            s4 = XLS.LineStyleEnum.Double
       case "虚线"
            s4 = XLS.LineStyleEnum.Dashed
       case "中等实线"
            s4 = XLS.LineStyleEnum.Medium
       case "中等的(短线+点+点)"
            s4 = XLS.LineStyleEnum.ThinDashDotDotted
       case "中等的(短线+点)"
            s4 = XLS.LineStyleEnum.ThinDashDotted
       case "中等虚线"
            s4 = XLS.LineStyleEnum.MediumDashed
end select
select case e.form.controls("Combobox6").value
       case "居中"
            s5 = XLS.AlignHorzEnum.Center
       case "靠左"
            s5 = XLS.AlignHorzEnum.Left
       case "靠右"
            s5 = XLS.AlignHorzEnum.Right
       case "默认"
            s5 = XLS.AlignHorzEnum.General
     end select
select case e.form.controls("Combobox7").value
       case "居中"
            s6 = XLS.AlignVertEnum.Center
       case "靠底"
            s6 = XLS.AlignVertEnum.Bottom
       case "靠上"
            s6 = XLS.AlignVertEnum.Top
       case "默认"
            s6 = XLS.AlignVertEnum.Undefined
     end select
Dim chk1 As WinForm.CheckBox
chk1 = e.form.Controls("CheckBox1")
Dim chk2 As WinForm.CheckBox
chk2 = e.form.Controls("CheckBox2")


Dim dlg As New SaveFileDialog '定一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
dim ss as string
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    ss = dlg.FileName
   If FileSys.FileExists("& ss &") = true Then
      FileSys.DeleteFile("& ss &",2,2) '则彻底删
   End if

Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim Style As Xls.Style = Book.NewStyle '新建一个样式
Style.BorderTop = s1
Style.BorderBottom = s2
Style.BorderLeft = s3
Style.BorderRight = s4
Style.AlignHorz = s5
Style.AlignVert = s6
 

dim tt1 as integer = e.form.controls("NumericComboBox2").value
dim tt2 as string = e.form.controls("Combobox2").value
if chk1.checked then
   Book.DefaultFont = New Font(tt2,tt1,FontStyle.Bold)
else
   Book.DefaultFont = New Font(tt2,tt1)
end if

if chk2.checked then
   style.wordwrap = true
else
   style.wordwrap = false
end if

'Style.BackColor = Color.Red '样式的背景颜色设为红色
Dim lst As WinForm.CheckedListBox
lst = e.Form.Controls("CheckedListBox1")
Dim k As Integer = 0
Dim f as integer

For Each Index As Integer In lst.CheckedIndices
      f = index + 1
      dim gg as string = "Textbox" & f
      Sheet(0, k).Value = lst.Items(Index)
      Sheet(0, k).Style = Style
      dim t as string
      if e.form.controls(gg).value Is nothing or e.form.controls(gg).value <= 60 then
         Sheet.Cols(k).Width = 80
      else
         Sheet.Cols(k).Width = e.form.controls(gg).value
      end if
      k = k + 1
Next
sheet.Rows(0).Height = 32
dim DataT as string = Vars("活动窗口1") & "_Table1"
Dim dt As Table = Tables(DataT)
Dim Multi As String = lst.value
Dim Values() as String
Values = Multi.split(",")


For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
    dim h as integer = 0
    For Each Index2 As Integer In lst.CheckedIndices
      dim name as string =  lst.Items(Index2)
    
      Sheet(r+1, h).Value = dt.rows(r)(name)
      Sheet(r+1, h).Style = Style 
      h = h + 1
    Next
    sheet.Rows(r+1).Height = e.form.controls("NumericComboBox1").value   
Next
'新增加的样式,目前怎样改下面的代码都无法实现。

Dim Style1 As XLS.Style = Book.NewStyle
Style1.Format = "yyyy-MM-dd"
For p1 as integer = 0 to Sheet.Cols.count -1
     if Sheet(0, p).Value Like "*日期*" then
        Sheet.Cols(p).Style = Style1
     end if
Next

   Book.Save(ss)
end if

8楼
baoxyang 发表于:2010/3/9 10:08:00
新增加的样式,目前怎样改下面的代码都无法实现。

Dim Style1 As XLS.Style = Book.NewStyle
Style1.Format = "yyyy-MM-dd"
For p1 as integer = 0 to Sheet.Cols.count -1
     if Sheet(0, p).Value Like "*日期*" then
        Sheet.Cols(p).Style = Style1
     end if
Next
如果把Style.Format = "yyyy-MM-dd" 放在第一个样式就可以,为什么先执行样式1再设置样式2时,样式2不起效果呢?请老大指点呀,谢谢!!

9楼
mr725 发表于:2010/3/9 11:16:00

估计你的Excel数据还没有生成之前,  if Sheet(0, p).Value Like "*日期*" then 这个条件永远都不会成立的!~

10楼
czy 发表于:2010/3/9 13:08:00
我看不出端倪,只看出第二个样式引用的变量名称是错误的。
共15 条记录, 每页显示 10 条, 页签: [1] [2]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03906 s, 2 queries.