Jump to content

Get data from a Worksheet with Python script?


Recommended Posts

I've been trying to get data from a worksheet by Python script. Here is the basic code:

 

def FindTable():
    hLayer = vs.GetParent( vs.FObject() )
    vs.EnableDrawingWorksheetPalette(True, None)

    while hLayer != None:
        h = vs.FInLayer( hLayer )
        while h != None:
            # worksheet?
            if vs.GetTypeN(h) == 56:
                rows, cols = vs.GetWSRowColumnCount(h)
                cellnum = vs.GetCellStr(h,1,1)
                vs.AlrtDialog( vs.Concat('Cell 1 ',cellnum,' Name: ',vs.GetName(h),' visible: ',vs.AreWorksheetGridLinesVisible(h),' rows=', rows, ' cols=', cols) )
            
            h = vs.NextObj( h )
        hLayer = vs.NextLayer( hLayer )


    return 0

 

It doesn't work and returns 0 rows and columns. I guess "Worksheet container" type is not good and these APIs  don't work but the cycle returns only handle with type 56 even without any 'if' condition.

Maybe "Worksheet" type is what I'm looking for?  types and IDs  But how can I obtain it?

Link to comment

 

Vsevolod,

The object on the drawing layer is a WORKSHEET IMAGE (type 56). You need a handle to the WORKSHEET (type 18), which is a resource.

 

Add this line:

hWS = vs.GetWSFromImage(h)        # handle to WS resource

and use hWS in your subsequent calls. 

def FindTable():
	hLayer = vs.GetParent( vs.FObject() )
	vs.EnableDrawingWorksheetPalette(True, None)
	while hLayer != None:
		h = vs.FInLayer( hLayer )
		while h != None:
			# worksheet?
			if vs.GetTypeN(h) == 56:
				hWS = vs.GetWSFromImage(h)		# handle to WS resource
				rows, cols = vs.GetWSRowColumnCount(hWS)
				cellnum = vs.GetCellStr(hWS,1,1)
				vs.AlrtDialog( vs.Concat('Cell 1 ',cellnum,' Name: ',vs.GetName(h),' visible: ',vs.AreWorksheetGridLinesVisible(hWS),' rows=', rows, ' cols=', cols) )
            
			h = vs.NextObj( h )
		hLayer = vs.NextLayer( hLayer )
	return 0

 

Raymond

Edited by MullinRJ
  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...