以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何将excel模板里的颜色通过代码来修改  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=123217)

--  作者:rjh4078
--  发布时间:2018/8/10 9:09:00
--  如何将excel模板里的颜色通过代码来修改
If e.Book.TempLate="生产单" Then
    
    Dim Book As New XLS.Book \'定义一个Excel工作簿
    book=e.book
    Dim Style As XLS.Style=e.Book.NewStyle
    Style.ForeColor = Color.Red
    
    \'Dim Sheet As XLS.Sheet = Book.Sheets(0)
    \'For i As Integer = 0 To Sheet.Rows.count-1
        \'Sheet(i,0).Style =Style \'设置单元格样式
        \'
    \'Next
    \'
End If

不启用引号部分,没有任何作用,启用了模板里排版样式全没了

--  作者:有点甜
--  发布时间:2018/8/10 9:57:00
--  

参考

 

Dim Book As New XLS.Book("d:\\test.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)
For i As Integer = 0 To Sheet.Rows.count-1
    Dim style2 As XLS.style = Sheet(i,0).Style  
    try
        \'Dim Style1 As XLS.Style = book.NewStyle
        \'Dim propertys = style2.Gettype.GetProperties
        \'For Each p As object In propertys
        \'Dim val = p.getValue(style2, Nothing)
        \'p.SetValue(style1, val, Nothing)
        \'Next
        style2.Forecolor = Color.red
    catch ex As exception
        style2 = book.NewStyle
        style2.ForeColor = Color.red
        Sheet(i,0).Style = style2
    End try
Next

book.Save("d:\\abc.xls")
Dim proc As new Process
proc.File = "d:\\abc.xls"
proc.Start