本帖最后由 hessen 于 2020-3-6 08:20 编辑
明细表聚光灯
功能说明:
点击明细表单元格时,高亮显示当前单元格所在的明细表区域内的行列。
支持版本:
企业版7.0以上
效果:
VBA: - <font color="rgb(68,68,68)">Imports SpreadsheetGear
- Imports C1.Silverlight
- Imports C1.Silverlight.C1MessageBoxButton
- Imports C1.Silverlight.C1MessageBoxIcon
- Imports Newtonsoft.Json
- Imports Newtonsoft.Json.Linq
- 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 TN As String = "T_44"'设置明细表名
- Dim srbc As String = "",srbd As String = ""'记录选择行列的地址及颜色值便于还原
- 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()
- End Sub'打开时执行事件
- Public Sub RangeSelection(sender As Object,e As SpreadsheetGear.Windows.Controls.RangeSelectionChangedEventArgs)
- ev.GetLock()
- '分隔记录的地址及颜色
- Dim srbcs() As String = srbc.Split(",".ToCharArray())
- Dim srbds() As String = srbd.Split(",".ToCharArray())
- Dim i As Integer = 0
- '遍历还原单元格颜色
- For i = 0 To srbcs.Length - 1
- Dim ra As String = srbcs(i)
- Dim rc As String = srbds(i)
- If String.Equals(ra,"") = False Then
- Dim rgb() As String = rc.Split(".".ToCharArray())
- range(ra).Interior.Color = Color.FromArgb(Integer.Parse(rgb(0)),Integer.Parse(rgb(1)),Integer.Parse(rgb(2)))
- End If
- Next
- '判断选择的是明细表
- If Range(TN).Intersect(e.RangeSelection) IsNot Nothing Then
- Dim SR As Integer = range(TN).row
- Dim CR As Integer = range(TN).column
- Dim SI As Integer = e.RangeSelection.Row - SR
- Dim CI As Integer = e.RangeSelection.Column - CR
- Dim RC As Integer = range(TN).RowCount - 1
- Dim CC As Integer = range(TN).ColumnCount - 1
- Dim SA As String = Range(TN).Cells(SI,0).Address + ":" + Range(TN).Cells(SI,CC).Address
- Dim CA As String = Range(TN).Cells(0,CI).Address + ":" + Range(TN).Cells(RC,CI).Address
- srbc = ""
- srbd = ""
- '设置聚光灯前先记录原行列所有单元格的颜色
- For Each cell As IRange In Range(SA)
- srbc += cell.Address+","
- srbd += cell.Interior.Color.R.ToString() + "." + cell.Interior.Color.g.ToString() + "." +cell.Interior.Color.b .ToString + ","
- Next
- For Each cell As IRange In Range(CA)
- srbc += cell.Address+","
- srbd += cell.Interior.Color.R.ToString() + "." + cell.Interior.Color.g.ToString() + "." +cell.Interior.Color.b.ToString +","
- Next
- '设置聚光灯行颜色
- range(SA).Interior.Color = Color.FromArgb(255,255,204)
- '设置聚光灯列颜色
- range(CA).Interior.Color = Color.FromArgb(255,255,204)
- End If
- ev.ReleaseLock()
- 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)
- End Sub'按钮/标签点击事件
- Public Sub FollowHyperlink(sender As Object)
- End Sub '暂不支持
- End Class
- ' 注:除事件字眼下可以自定义代码外的所有代码不允许改动,否则编译将有可能失败。
- End Namespace
- </font>
复制代码
|
hessen