数据其实是个很重要的东西,数据丢失会给我们带来很大的麻烦,我们今天不考虑数据丢失的问题,这里我们主要介绍VB.NET数据自增的问题,下面给大家演示一段代码,希望可以给大家带来技术上的帮助。
VB.NET数据自增的代码如下:
- Public Class Sheet1
- Private MyWeekMenu As Office.CommandBarButton
- Private MyMonthMenu As Office.CommandBarButton
- Private MySeriesMenu As Office.CommandBarButton
- Private missing = System.Reflection.Missing.Value
- Private Sub Sheet1_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
- AddMenuBar()
- End Sub
- Private Sub Sheet1_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
- End Sub
- Private Sub AddMenuBar()
- Try
- Dim MyCommandBarPopup As Office.CommandBarPopup = Nothing
- Dim MyCommandBarMenu As Office.CommandBar = _
- CType(Application.CommandBars.ActiveMenuBar, Office.CommandBar)
- Dim MyControlsCount As Integer = MyCommandBarMenu.Controls.Count
- MyCommandBarPopup = CType(MyCommandBarMenu.Controls.Add( _
- Office.MsoControlType.msoControlPopup, missing, missing, _
- MyControlsCount, True), Office.CommandBarPopup)
- If (MyCommandBarPopup IsNot Nothing) Then
- MyCommandBarPopup.Caption = "演示数据自增"
- MyWeekMenu = CType(MyCommandBarPopup.Controls.Add( _
- Office.MsoControlType.msoControlButton, missing, missing, _
- missing, True), Office.CommandBarButton)
- MyWeekMenu.Caption = "自增星期数据"
- AddHandler MyWeekMenu.Click, AddressOf MyWeekMenuCommand_Click
- MyMonthMenu = CType(MyCommandBarPopup.Controls.Add( _
- Office.MsoControlType.msoControlButton, missing, missing, _
- missing, True), Office.CommandBarButton)
- MyMonthMenu.Caption = "自增月份数据"
- AddHandler MyMonthMenu.Click, AddressOf MyMonthMenuCommand_Click
- MySeriesMenu = CType(MyCommandBarPopup.Controls.Add( _
- Office.MsoControlType.msoControlButton, missing, missing, _
- missing, True), Office.CommandBarButton)
- MySeriesMenu.Caption = "自增序列数据"
- AddHandler MySeriesMenu.Click, AddressOf MySeriesMenuCommand_Click
- End If
- Catch ex As Exception
- MessageBox.Show(ex.Message, "51cto信息提示", _
- MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- '自增星期数据
- Private Sub MyWeekMenuCommand_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
- Dim MyRange As Microsoft.Office.Tools.Excel.NamedRange = _
- Me.Controls.AddNamedRange(Me.Range("A1", missing), "NamedRange1")
- 'MyRange.Value2 = "星期一"
- 'MyRange.AutoFill(Me.Range("A1", "A5"), Excel.XlAutoFillType.xlFillWeekdays)
- MyRange.Value2 = "Monday"
- MyRange.AutoFill(Me.Range("A1", "A5"), Excel.XlAutoFillType.xlFillWeekdays)
- End Sub
- '自增月份数据 '更多.net源码和实例
- Private Sub MyMonthMenuCommand_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
- Dim MyRange As Microsoft.Office.Tools.Excel.NamedRange = _
- Me.Controls.AddNamedRange(Me.Range("B1", missing), "NamedRange2")
- 'MyRange.Value2 = "Jan"
- MyRange.Value2 = "January"
- MyRange.AutoFill(Me.Range("B1", "B12"), Excel.XlAutoFillType.xlFillMonths)
- End Sub
- '自增序列数据
- Private Sub MySeriesMenuCommand_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
- Dim MyRange As Microsoft.Office.Tools.Excel.NamedRange = _
- Me.Controls.AddNamedRange(Me.Range("C1", missing), "NamedRange3")
- MyRange.Value2 = "1975年1月1日 生产日报"
- MyRange.AutoFill(Me.Range("C1", "C31"), Excel.XlAutoFillType.xlFillSeries)
- End Sub
- End Class
以上是VB.NET数据自增的一个列子,大家试试吧。
【编辑推荐】