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


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

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

帅哥哟,离线,有人找我吗?
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样式.可否实现?

 回到顶部
美女呀,离线,留言给我吧!
yangming
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:超级版主 帖子:4109 积分:23338 威望:0 精华:21 注册:2008/9/1 20:07:00
  发帖心情 Post By:2010/3/5 9:38:00 [只看该作者]

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


 回到顶部
帅哥哟,离线,有人找我吗?
baoxyang
  3楼 | 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样式无法实现,请杨版帮忙,谢了!

 回到顶部
美女呀,离线,留言给我吧!
yangming
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:超级版主 帖子:4109 积分:23338 威望:0 精华:21 注册:2008/9/1 20:07:00
  发帖心情 Post By: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

 回到顶部
帅哥哟,离线,有人找我吗?
baoxyang
  5楼 | 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 两种都试过,都不成功。不知何原因?是否你试过可以吗?

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


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:5154 积分:31434 威望:0 精华:8 注册:2008/9/8 12:27:00
  发帖心情 Post By: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()

最好把代码都贴出来,一节子代码真是难为大家了。

 回到顶部
帅哥哟,离线,有人找我吗?
baoxyang
  7楼 | 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
  8楼 | 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不起效果呢?请老大指点呀,谢谢!!


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


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:5154 积分:31434 威望:0 精华:8 注册:2008/9/8 12:27:00
  发帖心情 Post By:2010/3/9 11:16:00 [只看该作者]

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


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


加好友 发短信 一级勋章 三级勋章 二级勋章
等级:超级版主 帖子:6318 积分:33957 威望:0 精华:10 注册:2008/8/31 20:56:00
  发帖心情 Post By:2010/3/9 13:08:00 [只看该作者]

我看不出端倪,只看出第二个样式引用的变量名称是错误的。

 回到顶部
总数 15 1 2 下一页