vb.net office excel 和wps共存,创建正确的excel对象以便操作excel表格
来源:互联网 发布:矩阵分析 编辑:程序博客网 时间:2024/03/29 14:45
vb6.0版代码请看vb6.0分类下另外一篇文章
代码实现平台:
vs2015+4.0 运行库
Log函数为自编函数,代码为给出,请谅解。
''' <summary> '''office97 8.0 '''office2000 9.0 '''officeXP (2002) 10.0 '''office2003 11.0 '''office2007 12.0 '''office2010 14.0 '''根据系统安装的Excel(Excel或者wps)创建Excel对象''' 一定要先et 然后在ket 最后才是excel''' 在系统中,office excel 比wps 表格具有优先级或者是注册表里面某项决定的 ''' </summary> ''' <param name="xlApp"></param> ''' <param name="ISAM">索引顺序访问方法</param> ''' <param name="filter">文件后缀</param> ''' <returns></returns> Private Function CreateExcelObject(ByRef xlApp As Object, ByRef ISAM As String, ByRef filter As String) As Boolean Dim xlappVersion As Double = 0.0 Dim funcResult As Boolean = False Try xlApp = CreateObject("ET.Application") Catch ex As Exception Debug.Print($"错误代码:{Err.Number}{Environment.NewLine}错误描述:{Err.Description}") Debug.Print($"问题描述:{Environment.NewLine}{ex.Message}{Environment.NewLine}具体信息:{Environment.NewLine}{ex.StackTrace}") Log($"问题描述:{Environment.NewLine}{ex.Message}{Environment.NewLine}具体信息:{Environment.NewLine}{ex.StackTrace}") End Try If xlApp Is Nothing Then Try xlApp = CreateObject("KET.Application") Catch ex As Exception Debug.Print($"错误代码:{Err.Number}{Environment.NewLine}错误描述:{Err.Description}") Debug.Print($"问题描述:{Environment.NewLine}{ex.Message}{Environment.NewLine}具体信息:{Environment.NewLine}{ex.StackTrace}") Log($"问题描述:{Environment.NewLine}{ex.Message}{Environment.NewLine}具体信息:{Environment.NewLine}{ex.StackTrace}") End Try End If If xlApp Is Nothing Then Try xlApp = CreateObject("Excel.Application") Catch ex As Exception Debug.Print($"错误代码:{Err.Number}{Environment.NewLine}错误描述:{Err.Description}") Debug.Print($"问题描述:{Environment.NewLine}{ex.Message}{Environment.NewLine}具体信息:{Environment.NewLine}{ex.StackTrace}") Log($"问题描述:{Environment.NewLine}{ex.Message}{Environment.NewLine}具体信息:{Environment.NewLine}{ex.StackTrace}") End Try End If If xlApp Is Nothing Then Debug.Print($"来源:{New StackTrace().GetFrame(0).GetMethod.Name} 获取Excel或者WPS对象失败") Return funcResult End If xlApp.Visible = False xlappVersion = Convert.ToDouble(xlApp.version) Select Case xlappVersion Case <= 11.0# filter = ".xls" ISAM = "Excel 8.0" funcResult = True Case > 11.0# filter = ".xlsx" ISAM = "Excel 12.0 Xml" funcResult = True Case Else Debug.Print($"来源:{New StackTrace().GetFrame(0).GetMethod.Name} 获取Excel或者WPS对象失败") End Select Debug.Print($"来源:{New StackTrace().GetFrame(0).GetMethod.Name} 获取Excel或者WPS对象成功") Return funcResult End Function
调用
Dim xlApp As Object = Nothing Dim excelFilter As String = "" Dim excelISAM As String = ""
'后期绑定Excel对象 不需要知道系统安装的是哪个版本的Excel '不需要引用Excel If CreateExcelObject(xlApp, excelISAM, excelFilter) = False Then MessageBox.Show("本机未安装Excel或者WPS,导出失败!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information) Exit Sub End If
1 0
- vb.net office excel 和wps共存,创建正确的excel对象以便操作excel表格
- vb6.0 office excel 和wps共存,创建正确的excel对象以便操作excel表格
- C#操作WPS的EXCEL表格
- vb.net操作Excel表格类
- 天易26----java导出excel表格(支持wps和office excel)
- vb.net 操作EXCEL
- VB.NET EXCEL操作
- VB.NET操作Excel
- .NET操作Excel表格
- [VB.NET]VB.NET创建外部excel对象
- 金山WPS、微软Office EXCEL表格通用C++接口
- NPOI ADO office wps 四种方式 读excel表格
- .NET操作Excel表格的整理
- Excel操作类(VB.NET)
- vb.net操作excel文件
- vb.net操作excel汇集
- vb.net操作excel文件
- vb.net操作Excel常用命令
- [BZOJ4513] [SDOI2016] 储能表 - 数位DP
- 关于Cocopods错误 is not used in any concrete target
- Java入门项目dao
- 【api】请求 http https 拦截 支持PC 移动设备等
- SpringMVC requestMapping
- vb.net office excel 和wps共存,创建正确的excel对象以便操作excel表格
- 内连接和外连接
- 【前端开发系列】—— 利用选择器添加内容
- Linux shell ${}简单用法
- Java IO 转换流的读入和写出
- Java入门项目model
- Hugo的安装与academic主题的使用
- JAVA 日期、时间函数大全
- Java入门项目view