Jump to content

Create and rewrite a Worksheet


Raph

Recommended Posts

Hello everyone,

 

I have a code with the possibility of creating a worksheet.

It works great! but...
Each time the code is executed, it generates a new table.

Would it be possible to make a code that rewrites the existing table?

I use the following code to create the worksheet:

 

WSH = vs.CreateWS(vs.Concat(S1,' ',vs.Date(2,0)),N1+3,3)

 

Thank you for your feedback

Link to comment

You can certainly reuse a worksheet.

 

Instead of the code you have above to get the handle to the worksheet with the CreateWS call, you will need to use code to get the handle to the existing worksheet.

 

If you have the image of the worksheet selected in the drawing you can use GetWSFromImage.

 

Or you can use other functions to find the WS you want by Name.  GetObject('Your WS Name') is one way.

  • Like 1
Link to comment
7 minutes ago, Jesse Cogswell said:

One way that I've done this is to use DelObject to delete the existing worksheet before creating the new one.

That's what I do.

IF GetObject(GetName(worksheetName)) <> NIL THEN

        DelObject(GetObject(GetName(worksheetName)));

WKSHandle := CreatWS(worksheetName, RowNum, ColNum);

 

Link to comment

Actually, I have no clue.  None of the worksheets to which I do this have sheet images.  I would imagine that the worksheet image would disappear for the deleted worksheet.  However, if you placed the worksheet with a script you can just place it again.  If you didn't originally place it, I would imagine you could collect the location of the worksheet before you delete it and place or move the new one to that location.

 

    WKS := GetObject(WKSName);
    WKSImage := GetWSImage(WKS);
    GetBBox(WKSImage, X1, Y1, X2, Y2);

    DelObject(WKS)

Link to comment

Just did a test and deleting the source worksheet does indeed delete the worksheet image.  @Sam Jones is correct in that you would need to pull the bounding box (GetBBox) and the original worksheet image scale (GetWSImageScaleF) then recreate the worksheet image using CreateWSImage and reapply the scale.  You'll likely need to pull the original object's visual attributes as well.

  • Like 1
Link to comment
  • Marionette Maven

You don't need to get the name of the worksheet since you're already providing it. Also, GetName works on object handles, not strings. 
Here's a short example of how you could use GetName.

 

vs.NameObject('NewRect')	#set the name for the next created object
vs.RectangleN(0,0,0,1,1,1)
vs.AlrtDialog(str(vs.GetName(vs.LNewObj())))


Note that vs.RectangleN doesn't return a handle to the created rectangle, so vs.LNewObj() is used to call to the last created object.
 

  • 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...