当前位置: 首页 > news >正文

北京城乡住房建设官方网站/培训心得体会800字

北京城乡住房建设官方网站,培训心得体会800字,58接网站建设,仪征做网站公司哪家好这是我第一次发Office开发相关的帖子。说到Office开发,我只能算新手。这次是碰巧开发了一个Excel智能文档项目,其中用到了这个小小的技巧,就发出来让大家看看。在Excel开发中,工作表上最基本也是最常用的元素就是Range&#xff0c…

这是我第一次发Office开发相关的帖子。说到Office开发,我只能算新手。这次是碰巧开发了一个Excel智能文档项目,其中用到了这个小小的技巧,就发出来让大家看看。
在Excel开发中,工作表上最基本也是最常用的元素就是Range,Range可以表达一个获任意多个单元格或者矩形区域的组合,其复杂程度相当高。如果我们的智能文档程序要与用户打交道的话,势必要编程控制文档中的单元格,或与用户选择的单元格交互。而Range的对象模型并不符合.NET开发人员的习惯,要想获取用户选中区域的形状或者操作特定形状的区域都十分繁琐。而MSDN和VSTO的推销人员们只关心诸如怎么把单元格和数据源或者XML绑定之类,这种“小事”只能靠我们自己动手了。我的任务就是编写一个Range的封装类,将Range中所有单元格和矩形区域转化为易于访问的对象模型。首先我们看看Range的组成,一个普通的Range可以是一个或多个矩形区域的集合,每个矩形区域都由一组连续的列和连续的行组成。其中行使用阿拉伯数字索引,而列采用字母索引。如图所示:

注意,多个矩形区域可以不连续,还可以交叠。每个Range都有一个描述其位置的字符串,称为Range的地址字符串。地址字符串不但包含所有位置信息,还可以被Excel用来直接快速定位,所以我们就以地址字符串为桥梁,编写我们的包装类。
ColumnWrapper类:主要用于吧表示列的字符串“A”,“B”,“AA”等转化为1开始的整数序列,或者相反。我这里用到的算法可以支持无限大的整数与列名字符串互转,但其实Excel只支持到256列。

ContractedBlock.gifExpandedBlockStart.gifColumnWrapper
ExpandedBlockStart.gifContractedBlock.gifPublic Class ColumnWrapperClass ColumnWrapper
InBlock.gif
InBlock.gif    
Private Const c_NameChar = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
InBlock.gif    
Private indexValue As Integer
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property Index()Property Index() As Integer
InBlock.gif        
Get
InBlock.gif            
Return indexValue
InBlock.gif        
End Get
InBlock.gif
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
InBlock.gif    
Private nameValue As String
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property Name()Property Name() As String
InBlock.gif        
Get
InBlock.gif            
Return nameValue
InBlock.gif        
End Get
InBlock.gif
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New(ByVal name As String)
InBlock.gif
InBlock.gif        nameValue 
= name
InBlock.gif        indexValue 
= GetIndex(name)
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Function GetName()Function GetName(ByVal i As IntegerAs String
InBlock.gif        Debug.Assert(i 
> 0)
InBlock.gif
InBlock.gif        
Dim left As Integer = (i - 1\ 26
InBlock.gif        
Dim right As Integer = i Mod 26
InBlock.gif
InBlock.gif        
Dim nameLeft As String
InBlock.gif        
Dim nameRight As String
InBlock.gif        
If left > 0 Then
InBlock.gif            nameLeft 
= GetName(left)
InBlock.gif        
Else
InBlock.gif            nameLeft 
= String.Empty
InBlock.gif        
End If
InBlock.gif
InBlock.gif        
If right = 0 Then right = 26
InBlock.gif        nameRight 
= c_NameChar(right)
InBlock.gif
InBlock.gif        
Return nameLeft & nameRight
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Function GetIndex()Function GetIndex(ByVal name As StringAs Integer
InBlock.gif        Debug.Assert(
Not String.IsNullOrEmpty(name))
InBlock.gif        
Dim len As Integer = name.Length
InBlock.gif        
Dim bit As Integer = 1
InBlock.gif
InBlock.gif        
For i As Integer = len - 1 To 0 Step -1
InBlock.gif            
Dim c As Char = name(i)
InBlock.gif            
Dim val = c_NameChar.IndexOf(Char.ToUpper(c))
InBlock.gif
InBlock.gif            GetIndex 
+= bit * val
InBlock.gif            bit 
*= 26
InBlock.gif        
Next
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New(ByVal index As Integer)
InBlock.gif        nameValue 
= GetName(index)
InBlock.gif        indexValue 
= index
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Overrides Function GetHashCode()Function GetHashCode() As Integer
InBlock.gif        
Return indexValue
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Overrides Function Equals()Function Equals(ByVal obj As ObjectAs Boolean
InBlock.gif        
If obj Is Nothing Then Return False
InBlock.gif
InBlock.gif        
Return TryCast(obj, ColumnWrapper).indexValue = indexValue
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedBlockEnd.gif
End Class

有了ColumnWrapper,下面就是CellWrapper,表示单个单元格。
ContractedBlock.gifExpandedBlockStart.gifCellWrapper
ExpandedBlockStart.gifContractedBlock.gifPublic Class CellWrapperClass CellWrapper
InBlock.gif
InBlock.gif    
Private addr As String
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property Address()Property Address() As String
InBlock.gif        
Get
InBlock.gif            
Return addr
InBlock.gif        
End Get
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
InBlock.gif    
Private rowValue As Integer
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property RowIndex()Property RowIndex() As Integer
InBlock.gif        
Get
InBlock.gif            
Return rowValue
InBlock.gif        
End Get
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
InBlock.gif    
Private columnValue As ColumnWrapper
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property Column()Property Column() As ColumnWrapper
InBlock.gif        
Get
InBlock.gif            
Return columnValue
InBlock.gif        
End Get
InBlock.gif
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
InBlock.gif    
Private cellValue As String
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property Value()Property Value() As String
InBlock.gif        
Get
InBlock.gif            
Return cellValue
InBlock.gif        
End Get
InBlock.gif
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New(ByVal row As IntegerByVal column As ColumnWrapper)
InBlock.gif        rowValue 
= row
InBlock.gif        columnValue 
= column
InBlock.gif
InBlock.gif        
Me.addr = "$" & column.Name & "$" & row
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
InBlock.gif    
Private Shared rx As New Regex("\$([A-Z]+)\$([1-9][0-9]*)", RegexOptions.Compiled)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New(ByVal address As String)
InBlock.gif        
Me.addr = address
InBlock.gif
InBlock.gif        
Dim matches As MatchCollection = rx.Matches(address)
InBlock.gif        
If matches.Count = 0 Then Throw New ArgumentException("address")
InBlock.gif
InBlock.gif        
Dim firstMatch As Match = matches(0)
InBlock.gif
InBlock.gif        
Me.columnValue = New ColumnWrapper(firstMatch.Groups(1).Value)
InBlock.gif        
Me.rowValue = Integer.Parse(firstMatch.Groups(2).Value)
InBlock.gif
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedBlockEnd.gif
End Class

接下来我们要表示矩形区域RectRangeWrapper。我们用来表示矩形区域。当我们需要计算矩形区域的大小时,只要使用着两个角单元格的位置信息即可算出。
ContractedBlock.gifExpandedBlockStart.gifRectRangeWrapper
ExpandedBlockStart.gifContractedBlock.gifPublic Class RectRangeWrapperClass RectRangeWrapper
InBlock.gif    
Private addr As String
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property Address()Property Address() As String
InBlock.gif        
Get
InBlock.gif            
Return addr
InBlock.gif        
End Get
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
InBlock.gif    
Private isWide As Boolean = False
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property IsWideRange()Property IsWideRange() As Boolean
InBlock.gif        
Get
InBlock.gif            
Return isWide
InBlock.gif        
End Get
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
InBlock.gif
InBlock.gif    
Private leftTop As CellWrapper
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property LeftTopCell()Property LeftTopCell() As CellWrapper
InBlock.gif        
Get
InBlock.gif            
Return leftTop
InBlock.gif        
End Get
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
InBlock.gif
InBlock.gif    
Private rightBottom As CellWrapper
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property RightBottomCell()Property RightBottomCell() As CellWrapper
InBlock.gif        
Get
InBlock.gif            
Return rightBottom
InBlock.gif        
End Get
InBlock.gif
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property Width()Property Width() As Integer
InBlock.gif        
Get
InBlock.gif            
Return Me.rightBottom.Column.Index - Me.leftTop.Column.Index + 1
InBlock.gif        
End Get
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property Height()Property Height() As Integer
InBlock.gif        
Get
InBlock.gif            
Return Me.rightBottom.RowIndex - Me.leftTop.RowIndex + 1
InBlock.gif        
End Get
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New(ByVal address As String)
InBlock.gif
InBlock.gif        
If address.IndexOf(":"c) > 0 Then
InBlock.gif            
Dim cells() As String = address.Split(":"c)
InBlock.gif
InBlock.gif            
Try
InBlock.gif                leftTop 
= New CellWrapper(cells(0))
InBlock.gif                rightBottom 
= New CellWrapper(cells(1))
InBlock.gif            
Catch ex As ArgumentException
InBlock.gif                
'wide range selected:
InBlock.gif

InBlock.gif                leftTop 
= Nothing
InBlock.gif                rightBottom 
= Nothing
InBlock.gif                
Me.isWide = True
InBlock.gif            
End Try
InBlock.gif        
Else
InBlock.gif            
If address Like "$[A-Z,a-z]*$[1-9]*" Then
InBlock.gif                leftTop 
= New CellWrapper(address)
InBlock.gif                rightBottom 
= leftTop
InBlock.gif            
End If
InBlock.gif        
End If
InBlock.gif
InBlock.gif        
Me.addr = address
ExpandedSubBlockEnd.gif    
End Sub

ExpandedBlockEnd.gif
End Class

最后是多个矩形区域组成的完整Range,我们用MultiRectRangeWrapper类来描述。它其实就是一个矩形区域的集合。
ContractedBlock.gifExpandedBlockStart.gifMultiRectRangeWrapper
ExpandedBlockStart.gifContractedBlock.gifPublic Class MultiRectRangeWrapperClass MultiRectRangeWrapper
InBlock.gif
InBlock.gif    
Private rectRanges As List(Of RectRangeWrapper)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property Areas()Property Areas() As List(Of RectRangeWrapper)
InBlock.gif        
Get
InBlock.gif            
Return rectRanges
InBlock.gif        
End Get
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
InBlock.gif
InBlock.gif    
Private ReadOnly addr As String
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property Address()Property Address() As String
InBlock.gif        
Get
InBlock.gif            
Return addr
InBlock.gif        
End Get
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New(ByVal address As String)
InBlock.gif        addr 
= address
InBlock.gif        rectRanges 
= New List(Of RectRangeWrapper)
InBlock.gif
InBlock.gif        
'parse the ranges
InBlock.gif
        Dim numberOfRanges As Integer
InBlock.gif        
Dim rectRangeAddr As String()
InBlock.gif
InBlock.gif        
If addr.IndexOf(","< 0 Then
InBlock.gif            rectRangeAddr 
= New String(0) {addr}
InBlock.gif            numberOfRanges 
= 1
InBlock.gif        
Else
InBlock.gif            rectRangeAddr 
= addr.Split(",")
InBlock.gif            numberOfRanges 
= rectRangeAddr.Length
InBlock.gif        
End If
InBlock.gif
InBlock.gif        
For Each r As String In rectRangeAddr
InBlock.gif            rectRanges.Add(
New RectRangeWrapper(r))
InBlock.gif        
Next
ExpandedSubBlockEnd.gif    
End Sub

ExpandedBlockEnd.gif
End Class

好了,现在四个包装类已经全部写完了。用法就简单多了。用Range.Address属性初始化MultiRectRangeWrapper类,就可以得到一个该Range中所有矩形区域的集合,进而轻松访问该举行区域中每个单元格。比如下面这个例子,展示了一些简单的区域操作:
'取得用户选定的区域
Dim myrange As New MultiRectRangeWrapper(Application.Selection.Address)
For Each rectRange As RectRangeWrapper In myrange.Areas
    
If Not rectRange.IsWideRange Then
        
'非扩展选择的区域,比如整行或整列
        '修改左上角的数字格式
        Me.Range(rectRange.LeftTopCell.Address).NumberFormat = "0.00"

        
'将最后一个选中区域复制到剪贴版
        Me.Range(rectRange.Address).Cut()
    
End If
Next

我写这个只是为了我自己写程序方便,并没有考虑太多因素,所以可能写得比较粗糙,功能有限。有兴趣的可以在我这程序的基础上继续改进。
http://www.lbrq.cn/news/783667.html

相关文章:

  • 网页游戏网站斗地主/永久免费的建站系统有哪些
  • 一个购物网站开发语言/友情链接的作用
  • 代做毕业设计的网站好/杭州seo的优化
  • 如何寻找一批做网站的公司/怎么优化一个网站
  • 招聘网站如何做/备案查询官网
  • 阿里巴巴做网站的/关键词排名查询
  • 聊城市网站建设公司/重庆seo网站推广优化
  • 最近日本字幕mv高清在线/网站关键字优化软件
  • 网站挂载/seo搜索引擎优化书籍
  • bs网站做映射/品牌推广方式有哪些
  • 网站优化 书/个人怎么做网络推广
  • 东营招标投标信息网/seo公司优化排名
  • 创建一个网站的费用/最近实时热点事件
  • app跟网站的区别是什么/推广是什么意思
  • 宁夏网站开发公司/性能优化大师
  • 做实体上什么网站找项目/网易搜索引擎
  • 自动发卡网和卡密兑换网站开发视频教程/网上营销培训课程
  • 十大门户网站有哪些/上海网站设计
  • 做寄生虫对自己的网站有影响吗/怎么开个人网站
  • 商城网站建设案例/百度app浏览器下载
  • 如何做淘外网站推广/怎么让某个关键词排名上去
  • 电脑制作网站总么做/天津网站seo设计
  • 湘潭市 网站建设/品牌营销网站建设
  • 百度手机导航官方新版/天津seo网站推广
  • 沛县做网站/兰州关键词快速上首页排名
  • 平顶山有做网站的公司/河南网站优化公司
  • 网站建设相关费用预算推广/百度登录个人中心官网
  • 自己代码做网站/app开发费用
  • 广州最大网站建设/中国新闻发布
  • 佛山 网站设计公司/什么软件引流客源最快
  • 多传感器融合
  • 调试|谷歌浏览器调试长连接|调试SSE和websocket
  • 数据与模型优化随机森林回归进行天气预测
  • Redis之通用命令与String类型存储
  • 深度学习TR3周:Pytorch复现Transformer
  • LLM大模型开发-SpringAI:ChatClient、Ollama、Advisor