Foxtable(狐表)用户栏目专家坐堂 → 求教,有关设置表格样式


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

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

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


加好友 发短信
等级:狐精 帖子:3313 积分:23146 威望:0 精华:1 注册:2009/3/31 11:25:00
求教,有关设置表格样式  发帖心情 Post By: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样式.可否实现?

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


加好友 发短信
等级:狐精 帖子:3313 积分:23146 威望:0 精华:1 注册:2009/3/31 11:25:00
  发帖心情 Post By: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样式无法实现,请杨版帮忙,谢了!

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


加好友 发短信
等级:狐精 帖子:3313 积分:23146 威望:0 精华:1 注册:2009/3/31 11:25:00
  发帖心情 Post By:2010/3/5 14:06:00 [显示全部帖子]

我是这样的设计的,S1样式设置成功,s2样式不成功。Sheet(r,2).Style = S2  和Sheet.Cols(2).Style=S2 两种都试过,都不成功。不知何原因?是否你试过可以吗?

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


加好友 发短信
等级:狐精 帖子:3313 积分:23146 威望:0 精华:1 注册:2009/3/31 11:25:00
  发帖心情 Post By: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


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


加好友 发短信
等级:狐精 帖子:3313 积分:23146 威望:0 精华:1 注册:2009/3/31 11:25:00
  发帖心情 Post By: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不起效果呢?请老大指点呀,谢谢!!


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


加好友 发短信
等级:狐精 帖子:3313 积分:23146 威望:0 精华:1 注册:2009/3/31 11:25:00
  发帖心情 Post By:2010/3/9 14:14:00 [显示全部帖子]

以下是引用mr725在2010-3-9 11:16:00的发言:

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

是成立的,这个判断没有问题,使用messagebox.show可以得出结果。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
跟这段代码应没有问题。测试过。


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


加好友 发短信
等级:狐精 帖子:3313 积分:23146 威望:0 精华:1 注册:2009/3/31 11:25:00
  发帖心情 Post By:2010/3/9 14:56:00 [显示全部帖子]

以下是引用mr725在2010-3-9 14:42:00的发言:

那就看上面的红字部分有没问题?  还不行的话,就发个文件让大家帮你测试吧!~~~

p1,及P不对应是笔误,Sorry!其它原代码都是P1,执行是不生效的。


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


加好友 发短信
等级:狐精 帖子:3313 积分:23146 威望:0 精华:1 注册:2009/3/31 11:25:00
  发帖心情 Post By:2010/3/9 14:59:00 [显示全部帖子]

我来做个简单实例吧。

 回到顶部