VBA填报从Excel中导入数据
版本:企业版
- 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 CF As TextBox, VW As Object
- Dim TS As StackPanel
- 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)
- TS = CType(OldRoot.Children(5), StackPanel)
- Dim BT1 As New Button
- BT1.Name = "BT_DR"
- BT1.Content = "导入EXCEL数据"
- BT1.Margin = New Thickness(0, 2, 0, 2)
- BT1.Padding = New Thickness(13, 3, 13, 3)
- BT1.Style = CType(Application.Current.Resources("ButtonStyle3"), Style)
- BT1.Foreground = CType(Application.Current.Resources("Foreground1"), System.Windows.Media.Brush)
- AddHandler BT1.Click, Sub()
- ActiveWorkbook.WorkbookSet.GetLock()
- Dim dialog As New OpenFileDialog
- dialog.Filter = "Excel2003文件(*.xls)|*.xls|Excel2007文件(*.xlsx)|*.xlsx|Excel2007启用宏文件(*.xlsm)|*.xlsm"
- dialog.Multiselect = False
- '实例化接口
- Dim ns As IWorkbookSet = Factory.GetWorkbookSet(Globalization.CultureInfo.CurrentCulture)
- Try
- If dialog.ShowDialog() = True Then
- ns.GetLock()
- Dim nw As IWorkbook = ns.Workbooks.OpenFromStream(dialog.File.OpenRead)
- Dim nr As IRange = nw.ActiveWorksheet.Range
- ActiveWorkbook.ActiveWorksheet.WorkbookSet.GetLock()
- Range("C5:I2000").Value = nr("A2:G2000").Value
- ActiveWorkbook.ActiveWorksheet.WorkbookSet.ReleaseLock()
- ns.ReleaseLock()
- nw.Close()
- ns = Nothing
- End If
- Catch ex As Exception
- ns.ReleaseLock()
- C1MessageBox.Show("文件无法打开,请检查是否被占用或者损坏!", "提示", OK, Information)
- 'MessageBox.Show(ex.Message)
- End Try
- ActiveWorkbook.WorkbookSet.ReleaseLock()
- End Sub
- TS.Children.Insert(18, BT1)
- '位置:2保存3新增4提交5退回6进度7打印8预览9导出10捕获11上传图片12上传附件13插入行14插多行15删除行16查找17最后
- 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)
- End Sub'按钮/标签点击事件
- Public Sub FollowHyperlink(sender As Object)
- End Sub '暂不支持
- End Class
- ' 注:除事件字眼下可以自定义代码外的所有代码不允许改动,否则编译将有可能失败。
- End Namespace
复制代码
|
|
hong90342