Ask Your Question
0

How to open Excel 2nd or 3rd sheet with Libreoffice macro

asked 2018-05-28 14:31:02 +0200

Lion gravatar image

Hi All Have new requirement about operations in libreoffice macro with Excel file

Requirement : Open Excel file but not First sheet, I want to open 2nd or 3rd or 4th How to open ?

Currently I am using below code to open excel file (first sheet)

Sub Macroexcel
Dim iFName As String
Dim iDoc As Variant
Dim oFName As String
Dim oDoc As Variant
Dim cSheet As Variant
Dim sUrl As String
Dim i As Long
Dim maxSize As Long

Dim OpenProp(1) as New com.sun.star.beans.PropertyValue 
OpenProp(0).name="FilterName"
OpenProp(0).value="MS Excel"
GlobalScope.BasicLibraries.LoadLibrary("Tools")

    iFName = "D:\Amazon\Andere.xlsm"
oFName = "D:\Amazon\Amazon_output.csv"

    sUrl = convertToURL(iFName)
If Not FileExists(sUrl) Then Exit Sub

   iDoc = stardesktop.LoadComponentFromURL(sUrl, "_blank",0, OpenProp())

   Dim oCursor As Variant
   Dim iDataArray As Variant
   Dim iD As Variant

cSheet = iDoc.getSheets().getByIndex(0)
oCursor = cSheet.createCursor()
oCursor.gotoEndOfUsedArea(True)
iDataArray = oCursor.getDataArray()
   ..... more

image description

I want to open "Beispiel" sheet

Thanks in advance

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2018-05-28 17:15:29 +0200

Jim K gravatar image

In your code, 0 indicates the first sheet.

cSheet = iDoc.getSheets().getByIndex(0)

Instead, get the third sheet:

cSheet = iDoc.getSheets().getByIndex(2)

Documentation: XIndexAccess.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-05-28 14:31:02 +0200

Seen: 44 times

Last updated: May 28 '18