VB6-COM接口操作开源OpenOffice编辑Excel,Word文件(中国首创)

请先安装工具

 引用网址
OpenOffice开发文档PDF_sdk(英文)http://www.openoffice.org/api/basic/man/tutorial/tutorial.pdf
JDK1.8 32位https://www.7down.com/soft/267473.html
OpenOffice4.1.7中文版https://www.openoffice.org/download/

OpenOffice_百度百科
https://baike.baidu.com/item/OpenOffice/7384410?fr=aladdin

Private Sub Command1_Click()
good_新建一个表和DOC
End Sub

Private Sub Command3_Click()
'新建Excel类表格
Dim mNoArgs()
Dim oSpreadsheetDocument As Object
Dim oTextDocument As Object
'Using StarOffice API - Basics 19
Dim oSM As Object
Set oSM = CreateObject("com.sun.star.ServiceManager")
Dim oDesktop
Set oDesktop = oSM.CreateInstance("com.sun.star.frame.Desktop")
'oDesktop = createUnoService("com.sun.star.frame.Desktop")
Dim sUrl
sUrl = "private:factory/scalc"
Set oSpreadsheetDocument = _
oDesktop.loadComponentFromURL(sUrl, "_blank", 0, mNoArgs())


 'GetCell = oSheet.getCellByPosition(nColumn, nRow)
 Dim oSheet As Object
 Set oSheet = oSpreadsheetDocument.getSheets().getByIndex(0)
 Dim Row As Long, Col As Long
 Row = 2
 Col = 2
  
  Dim s As String
 For Row = 1 To 3
 For Col = 1 To 5
 
 'oSheet.getCellByPosition(Col - 1, Row - 1).Value = Row & Col
 s = "v" & Row & Col
 
 'oSheet.getCellByPosition(Col - 1, Row - 1).v = Row & Col'数值
 oSheet.getCellByPosition(Col - 1, Row - 1).String = s '文本
 Next
 Next

End Sub

Sub good_新建一个表和DOC()
Dim mNoArgs()
Dim oSpreadsheetDocument As Object
Dim oTextDocument As Object
'Using StarOffice API - Basics 19
Dim oSM As Object
Set oSM = CreateObject("com.sun.star.ServiceManager")
Dim oDesktop
Set oDesktop = oSM.CreateInstance("com.sun.star.frame.Desktop")
'oDesktop = createUnoService("com.sun.star.frame.Desktop")
Dim sUrl
sUrl = "private:factory/scalc"
Set oSpreadsheetDocument = _
oDesktop.loadComponentFromURL(sUrl, "_blank", 0, mNoArgs())
sUrl = "private:factory/swriter"
Set oTextDocument = _
oDesktop.loadComponentFromURL(sUrl, "_blank", 0, mNoArgs)
End Sub

Private Sub Command4_Click()
 '打开一个WORD文件,GOOD
Dim mFileProperties(0) ' As New com.sun.star.beans.PropertyValue
Dim sUrl As String
Dim oSM As Object
Set oSM = CreateObject("com.sun.star.ServiceManager")
Dim oDesktop
Dim oDocument
Set oDesktop = oSM.CreateInstance("com.sun.star.frame.Desktop")

sUrl = "file:///" & App.Path & "\002word.doc"
sUrl = Replace(sUrl, "\", "/")
sUrl = GetFileName(App.Path & "\002word.doc")

'mFileProperties(0).Name = "FilterName"
'mFileProperties(0).Value = "scalc: Text - txt - csv (StarCalc)"
Set oDocument = oDesktop.loadComponentFromURL(sUrl, "_blank", 0, mFileProperties())
End Sub
Function GetFileName(ByVal sUrl As String) As String
sUrl = "file:///" & sUrl
sUrl = Replace(sUrl, "\", "/")
GetFileName = sUrl
End Function

Private Sub Command5_Click()
 '打开一个Excel文件,GOOD
Dim mFileProperties(0) ' As New com.sun.star.beans.PropertyValue
Dim sUrl As String
Dim oSM As Object
Set oSM = CreateObject("com.sun.star.ServiceManager")
Dim oDesktop
Dim oDocument
Set oDesktop = oSM.CreateInstance("com.sun.star.frame.Desktop")

sUrl = GetFileName(App.Path & "\001excel.xls")

Set oDocument = oDesktop.loadComponentFromURL(sUrl, "_blank", 0, mFileProperties())
End Sub

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

专注VB编程开发20年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值