问题描述
Dim appExcel As Object
设置appExcel = CreateObject(Excel.Application)
appExcel.Visible = False
Dim xlsBook作为新的excel.Workbook
Dim xlsSheet As New excel.Worksheet
Dim rowlocation As Integer
Dim columnlocation As Integer
Dim celladdress As String
设置xlsBook = appExcel.Workbooks.Open(Text1.Text)
设置xlsSheet = xlsBook.Worksheets(Sheet1)
Dim x As excel.Shapes
对于每个x在xlsSheet.Shapes
x.Copy
Picture1.Picture = Clipboard.GetData(vbCFBitmap)
Text2.Text = x.Name
rowlocation = x .TopLeftCell.Row
columnlocation = x.TopLeftCell.Column
celladdress = xlsSheet.Cells(x.BottomRightCell .Row + 1,x.TopLeftCell.Column).Address(RowAbsolute:= False,ColumnAbsolute:= False)
MsgBox ActiveSheet.Range(celladdress)
下一个
End If
不幸的是,这个代码不会在我的朋友的PC上工作,因为他没有安装Excel, OpenOffice电子表格。我试图在Openoffice中打开Excel,然后文件打开,我的目标是如何在OpenOffice中转换上面的代码?我的意思是运行OpenOffice文件的代码。
这是我的代码,但它不工作
Dim objServiceManager As Object
Dim objDesktop As Object
Dim objDocument As Object
Dim objText As Object
Dim objCursor As Object
Dim oDoc As Object
Dim ARG()
Dim oGraph As Object
Dim oView As Object
Dim oDrawPage As Object
Dim oSheet As Object
Dim Image As System_Drawing.Image
Dim oimage As Object
Dim osize As Object
设置objServiceManager = CreateObject(com.sun.star.ServiceManager)
设置objDesktop = objServiceManager.createInstance( com.sun.star.frame.Desktop)
设置oDoc = objDesktop.loadComponentFromURL(file:/// C:\Users\paul\Desktop\Testing.ods,_blank ,0,ARG())
设置oSheet = oDoc.getSheets()。getByIndex(0)
设置oGrap h = oDoc.createInstance(com.sun.star.drawing.GraphicObjectShape)
设置oView = oDoc.CurrentController
设置oDrawPage = oView.getActiveSheet.DrawPage
对于i = 0到2
对于j = 0到9
'Form1.Image1.Picture = Clipboard.GetData
Form1.Image1.Picture = LoadPicture(oDrawPage)
下一个
下一个
TYSM以供将来帮助
这是VB6中的最新代码,并且有一个错误,表示vnd.sun.star缺少
Dim objServiceManager As Object
Dim objDesktop As Object
Dim objDocument As Object
Dim objText As Object
Dim objCursor As Object
Dim oDoc As Object
Dim ARG()
Dim oGraph As Object
Dim oView As Object
Dim oDrawPage As Object
Dim oSheet As Object
Dim Image As S ystem_Drawing.Image
Dim oimage As Object
Dim osize As Object
Dim Cell As Object
Dim sGraphicUrl As String
Dim oDisp
Dim oFrame
Dim opos As Object
设置objServiceManager = CreateObject(com.sun.star.ServiceManager)
设置objDesktop = objServiceManager.createInstance(com sun.star.frame.Desktop)
设置osize = objServiceManager.Bridge_GetStruct(com.sun.star.awt.Size)
设置opos = objServiceManager.Bridge_GetStruct(com.sun.star。 awt.Point)
设置oDoc = objDesktop.loadComponentFromURL(file:/// C:\Users\paul\Desktop\ACE Express - Fairview_Sample PC of Gondola.ods,_blank, 0,ARG())
设置oSheet = oDoc.getSheets()。getByIndex(0)
设置oimage = oDoc.createInstance(com.sun.star.drawing.GraphicObjectShape)
设置oView = oDoc.CurrentController
设置oDrawPage = oView.getActiveSheet.DrawPage
Se (oimage.GraphicURL)
这是解压缩图片的输出
我不知道你的代码是什么,因为我通常不使用Microsoft Office。然而,看起来这个任务可以使用OpenOffice Basic来完成。学习OpenOffice Basic的最佳场所之一是
下一步图像按钮应该通过添加事件处理程序来实现相当简单。
有关文档,请参阅和。但是大多数情况下,我刚刚使用来计算出来。
编辑2 :
关于您发布的错误, GraphicURL
属性在这种情况下是引用内存中对象而不是文件路径的字符串。字符串的示例如下所示:。
所以不适合传递到,它需要一个文件名。
也许你可以从或oImage.Graphic。使用MRI来查看哪些属性可用。
例如,看起来像是有一个可以这样工作的getDIB()方法:
Form1.Image1.Picture = oImage.Bitmap.getDIB()
还有一个想法:不用使用Office应用程序,您可以编写解压缩文件的代码,并读取Pictures子目录中的每个图像。
I have a code that exports image from excel into a picturebox and here it is.
Dim appExcel As Object Set appExcel = CreateObject("Excel.Application") appExcel.Visible = False Dim xlsBook As New excel.Workbook Dim xlsSheet As New excel.Worksheet Dim rowlocation As Integer Dim columnlocation As Integer Dim celladdress As String Set xlsBook = appExcel.Workbooks.Open(Text1.Text) Set xlsSheet = xlsBook.Worksheets("Sheet1") Dim x As excel.Shapes For Each x In xlsSheet.Shapes x.Copy Picture1.Picture = Clipboard.GetData(vbCFBitmap) Text2.Text = x.Name rowlocation = x.TopLeftCell.Row columnlocation = x.TopLeftCell.Column celladdress = xlsSheet.Cells(x.BottomRightCell.Row + 1, x.TopLeftCell.Column).Address(RowAbsolute:=False, ColumnAbsolute:=False) MsgBox ActiveSheet.Range(celladdress) Next End If
and unfortunately this code wont work on my friends PC becuase he does not have an Excel installed but he has OpenOffice spreadsheet. I tried to open the Excel in Openoffice then the file opens now my goal is how can i convert the code above in OpenOffice? I mean run the code for OpenOffice files.
This is my code but its not working
Dim objServiceManager As Object Dim objDesktop As Object Dim objDocument As Object Dim objText As Object Dim objCursor As Object Dim oDoc As Object Dim ARG() Dim oGraph As Object Dim oView As Object Dim oDrawPage As Object Dim oSheet As Object Dim Image As System_Drawing.Image Dim oimage As Object Dim osize As Object Set objServiceManager = CreateObject("com.sun.star.ServiceManager") Set objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop") Set oDoc = objDesktop.loadComponentFromURL("file:///C:\Users\paul\Desktop\Testing.ods", "_blank", 0, ARG()) Set oSheet = oDoc.getSheets().getByIndex(0) Set oGraph = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape") Set oView = oDoc.CurrentController Set oDrawPage = oView.getActiveSheet.DrawPage For i = 0 To 2 For j = 0 To 9 ' Form1.Image1.Picture = Clipboard.GetData Form1.Image1.Picture = LoadPicture(oDrawPage) Next Next
TYSM for future help
This is the latest code in VB6 and it has an error saying vnd.sun.star is missing
Dim objServiceManager As Object Dim objDesktop As Object Dim objDocument As Object Dim objText As Object Dim objCursor As Object Dim oDoc As Object Dim ARG() Dim oGraph As Object Dim oView As Object Dim oDrawPage As Object Dim oSheet As Object Dim Image As System_Drawing.Image Dim oimage As Object Dim osize As Object Dim Cell As Object Dim sGraphicUrl As String Dim oDisp Dim oFrame Dim opos As Object Set objServiceManager = CreateObject("com.sun.star.ServiceManager") Set objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop") Set osize = objServiceManager.Bridge_GetStruct("com.sun.star.awt.Size") Set opos = objServiceManager.Bridge_GetStruct("com.sun.star.awt.Point") Set oDoc = objDesktop.loadComponentFromURL("file:///C:\Users\paul\Desktop\ACE Express - Fairview_Sample PC of Gondola.ods", "_blank", 0, ARG()) Set oSheet = oDoc.getSheets().getByIndex(0) Set oimage = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape") Set oView = oDoc.CurrentController Set oDrawPage = oView.getActiveSheet.DrawPage Set oimage = oDrawPage.getByIndex(0) Image1.Picture = LoadPicture(oimage.GraphicURL)
Here is the output of the unzip picture
解决方案I do not know exactly what your code does, because I normally do not use Microsoft Office. However it looks like this task can be accomplished using OpenOffice Basic. One of the best places to learn OpenOffice Basic is Andrew Pitonyak's Macro Document.
To start with, look at section
5.9.5. Convert all linked images
.EDIT:
To do this in Calc, first I went to
Tools -> Macros -> Organize Dialogs
and created a dialog named "ImageViewerForm" with an image control named "MyImageControl".Then I went to
Tools -> Macros -> Organize Macros -> OpenOffice Basic
and added the following code:Sub ShowImageViewerDialog oDoc = ThisComponent oDlg = CreateUnoDialog(DialogLibraries.Standard.ImageViewerForm) oControl = oDlg.Model.MyImageControl oDrawPage = oDoc.getDrawPages().getByIndex(0) oImage = oDrawPage.getByIndex(0) oControl.ImageURL = oImage.GraphicURL oDlg.execute() End Sub
To run the code, go to
Tools -> Macros -> Run Macro
. Here is the result:The "Next Image" button should be fairly straightforward to implement by adding an event handler.
For documentation, see GraphicObjectShape and UnoControlButtonModel. But mostly I just used the MRI tool to figure it out.
EDIT 2:
Regarding the error you posted, the
GraphicURL
property in this case is a string that references an in-memory object, not a filepath. An example of the string is shown here: https://www.openoffice.org/api/docs/common/ref/com/sun/star/graphic/XGraphicObject.html.So it is not suitable for passing to LoadPicture, which takes a filename.
Perhaps you can get the actual image data from oImage.Bitmap or oImage.Graphic. Use MRI to see what attributes are available.
For example, it looks like there is a getDIB() method that might work like this:
Form1.Image1.Picture = oImage.Bitmap.getDIB()
One more idea: Instead of using an Office application, you could write code that unzips the file and reads each image in the Pictures subdirectory.
这篇关于如何使用OpenOffice电子表格从Excel文件获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!