CSDN博客

img yiruoyun

操作Excel类库

发表于2004/10/15 11:08:00  1586人阅读

操作Excel类库 功能 excel文件创建修改 单元格数据格式编辑 图片 图表 插入控制 外部数据的添加 插入等

类库下载:VBExcelWordEditor.rar

事例Demo下载:OfficeDemo.rar

ExcelEditor提供以下方法:

'创建一个Excel对象
Public Sub Creat()

'打开一个Excel对象
Public Sub Open(ByVal FileName As String)
参数描述:FileName :excel文件路径

'获取一个工作表
Public Function GetSheet(ByVal SheetName As String) As Excel.Worksheet
参数描述:SheetName :工作表名称

'添加一个工作表
Public Function AddSheet(ByVal SheetName As String) As Excel.Worksheet

'删除一个工作表
Public Function DelSheet(ByVal SheetName As String)

'重命名一个工作表

Public Function ReNameSheet(ByVal OldSheetName As String, ByVal NewSheetName As String) As Excel.Worksheet

Public Function ReNameSheet(ByVal Sheet As Excel.Worksheet, ByVal NewSheetName As String) As Excel.Worksheet


'设置一个单元格的值

Public Sub SetCellValue(ByVal ws As Excel.Worksheet, ByVal x As Integer, ByVal y As Integer, ByVal value As Object)

参数说明 ws:要设值的工作表 X行Y列 value 值
Public Sub SetCellValue(ByVal ws As String, ByVal x As Integer, ByVal y As Integer, ByVal value As Object)


' 设置一个单元格的属性 字体, 大小,颜色 ,对齐方式

Public Sub SetCellProperty(ByVal ws As Excel.Worksheet, ByVal Startx As Integer, ByVal Starty As Integer, ByVal Endx As Integer, ByVal Endy As Integer, ByVal size As Integer, Optional ByVal name As String = "宋体", Optional ByVal color As Excel.Constants = Excel.Constants.xlAutomatic, Optional ByVal HorizontalAlignment As Excel.Constants = Excel.Constants.xlLeft)


参数说明 :ws:要设值的工作表 Startx 起始单元格的行 Starty 起始单元格的列 Endx 结束单元格的行 Endy 结束单元格的列 size 字体大小 name 字体 color 颜色 HorizontalAlignment 对齐方式

Public Sub SetCellProperty(ByVal wsn As String, ByVal Startx As Integer, ByVal Starty As Integer, ByVal Endx As Integer, ByVal Endy As Integer, Optional ByVal size As Integer = 12, Optional ByVal name As String = "宋体", Optional ByVal color As Excel.Constants = Excel.Constants.xlAutomatic, Optional ByVal HorizontalAlignment As Excel.Constants = Excel.Constants.xlAutomatic.xlRight)


'合并单元格
Public Sub UniteCells(ByVal ws As Excel.Worksheet, ByVal Startx As Integer, ByVal Starty As Integer, ByVal Endx As Integer, ByVal Endy As Integer)

参数说明 :ws:要设值的工作表 Startx 起始单元格的行 Starty 起始单元格的列 Endx 结束单元格的行 Endy 结束单元格的列


'将内存中数据表格插入到Excel指定工作表的指定位置 为在使用摩板时控制格式时使用
Public Sub InsertTable(ByVal dt As Data.DataTable, ByVal ws As String, ByVal startX As Integer, ByVal startY As Integer)

Public Sub InsertTable(ByVal dt As Data.DataTable, ByVal ws As Excel.Worksheet, ByVal startX As Integer, ByVal startY As Integer)


'将内存中数据表格添加到Excel指定工作表的指定位置
Public Sub AddTable(ByVal dt As Data.DataTable, ByVal ws As String, ByVal startX As Integer, ByVal startY As Integer)
Public Sub AddTable(ByVal dt As Data.DataTable, ByVal ws As Excel.Worksheet, ByVal startX As Integer, ByVal startY As Integer)

'插入图片操作"
Sub InsertPictures(ByVal Filename As String, ByVal ws As String)

Sub InsertPictures(ByVal Filename As String, ByVal ws As String, ByVal Height As Integer, ByVal Width As Integer)

Sub InsertPictures(ByVal Filename As String, ByVal ws As String, ByVal left As Integer, ByVal top As Integer, ByVal Height As Integer, ByVal Width As Integer)


插入图表操作"
Public Sub InsertActiveChart(ByVal ChartType As Excel.XlChartType, ByVal ws As String, ByVal DataSourcesX1 As Integer, ByVal DataSourcesY1 As Integer, ByVal DataSourcesX2 As Integer, ByVal DataSourcesY2 As Integer, Optional ByVal ChartDataType As Excel.XlRowCol = Excel.XlRowCol.xlColumns)

参数说明 :ChartType 为图表类型 ws:要设值的工作表名 DataSourcesX1 图表数据源起始单元格的行 DataSourcesY1 图表数据源起始单元格的列 DataSourcesX2 图表数据源结束单元格的行 DataSourcesY2 图表数据源结束单元格的列 ChartDataType 图表数据数据方式

' 保存文档
Public Function Save() As Boolean

' 文档另存为
Public Function SaveAs(ByVal FileName) As Boolean

' 关闭一个Excel对象,销毁对象
Public Sub Close()

这个一定要有!要不然 在系统进程中回有很EXCEL进程没有销毁!


使用方法:引用:VBExcelWordEditor.dll com引用: Microsoft Excel 10.0 Object Library


暂时只做了这些功能,慢慢扩展

共下载 117次

阅读全文
0 0

相关文章推荐

img
取 消
img