通过快表VBA功能,对明细表单元格的字体颜色进行标记红。
图示效果
红色=Button 1 ,全部取消=Button 2 ,选中取消=Button 3 ,保存=Button 4 ,F_9269为存储标记为红色字体的单元格地址
- Imports SpreadsheetGear
- Imports C1.Silverlight
- Imports C1.Silverlight.C1MessageBoxButton
- Imports C1.Silverlight.C1MessageBoxIcon
- Imports Newtonsoft.Json
- Imports Newtonsoft.Json.Linq
- Imports Microsoft.VisualBasic
- Imports System.IO
- Imports System.Text
- Imports System.Net
- Imports System.Windows.forms
- Namespace ExcelViewVBDotnet
- Public Class StandardInterface
- '预留位置1
- '预留位置2
- Dim EV As SpreadsheetGear.Windows.Controls.WorkbookView, AW As SpreadsheetGear.IWorkbook, Range As SpreadsheetGear.IRange
- Dim CF As TextBox
- Public Sub Workbook_Open(OldRoot As Object, NewRoot As Object, Excel As SpreadsheetGear.Windows.Controls.WorkbookView)
- EV = Excel
- Excel.GetLock()
- AW = Excel.ActiveWorkbook
- Range = AW.ActiveWorksheet.Range
- Excel.ReleaseLock()
- CF = CType(OldRoot.Children(1), TextBox)
- EV.getlock()
- ActiveWorkBook.Worksheets("sheet1").ProtectContents = False '查阅时解锁
-
- If App.Type= 3 Then
- '填写符合条件后执行的代码
- AW.ActiveWorksheet.Shapes("Button 4").Visible = False
- Else
- AW.ActiveWorksheet.Shapes("Button 4").Visible = True
- End If
-
- If Range("F_9269").Value <> "" Then '打开时遍历指定地址
- Dim bb As String = Range("F_9269").Value.ToString()
- Dim cc() As String = bb.split(",")
- Dim cell As String
- For Each cell In cc
- If cell <> "" Then
- AW.ActiveWorksheet.Range(cell).Font.ColorIndex = 2
- End If
- Next cell
- End If
- ActiveWorkBook.Worksheets("sheet1").ProtectContents = True '查阅时执行完成后锁定
- EV.ReleaseLock()
-
- End Sub'打开时执行事件
- Public Sub RangeSelection(sender As Object, e As SpreadsheetGear.Windows.Controls.RangeSelectionChangedEventArgs)
- End Sub'单元格选择后执行的事件
- Public Sub RangeChanged(sender As Object, e As SpreadsheetGear.Windows.Controls.RangeChangedEventArgs)
- End Sub'单元格编辑完成后执行事件
- Public Sub ButtunClick(sender As Object, e As SpreadsheetGear.Windows.Controls.ShapeActionEventArgs)
- EV.GetLock()
-
- If e.Shape.Name = "Button 1" Then '对选择单元格标记颜色
- Dim addr As String = EV.RangeSelection.Address
- Dim address As String
- Dim aa As String = Range("F_9269").Text
- AW.ActiveWorksheet.Range(addr).Font.ColorIndex = 2
- ' address =aa + addr +","
- ' Range("F_9269").Value = address
- End If
- If e.Shape.Name = "Button 2" Then '全部取消颜色
- range("T_855").Font.ColorIndex = 0
- End If
- If e.Shape.Name = "Button 3" Then '单个取消颜色
- Dim addr As String = EV.RangeSelection.Address
- Dim address As String
- Dim aa As String = Range("F_9269").Text
- AW.ActiveWorksheet.Range(addr).Font.ColorIndex = 0
- 'address = addr -aa +","
- 'Range("F_9269").Value = address
- End If
- ' ActiveWorkbook.WorkbookSet.GetLock()
- If e.Shape.Name = "Button 4" Then
- CF.Text = "#保存"
- '填写符合条件后执行的代码
- Dim address As String
- Dim cell As IRange
- For Each cell In AW.ActiveWorksheet.UsedRange
- If cell.Font.ColorIndex = 2 Then
- address = cell.Address + "," + address
- Range("F_9269").Value = address
- End If
- Next cell
- End If
-
- EV.ReleaseLock()
-
- End Sub'按钮/标签点击事件
- Public Sub FollowHyperlink(sender As Object)
- End Sub '暂不支持
- End Class
- ' 注:除事件字眼下可以自定义代码外的所有代码不允许改动,否则编译将有可能失败。
- End Namespace
复制代码
|
|
快表帝国客服05