OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 30-05-2010, 09:18
beczukdavid
Guest
 
Posts: n/a
Question How to Edit a Table

I have another question

How do you edit a Table cells values after you have created the table like this for example:

Code:
Set s1 = ActiveLayer.CreateCustomShape("Table",300, 450,1000, 200, 6, 3)
How could I edit the cells so I can insert the values from a Form?

Thanks Guys
Reply With Quote
  #2  
Old 30-05-2010, 17:32
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Tables

Here is an example that shows you several things you can do with tables, from entering text to changing outlines and fills. This example makes a calendar for January.
Code:
Sub JanuaryCalendar()
    Dim s1 As Shape

    'Create a Table with 5 columns and 3 rows
    Set s1 = ActiveLayer.CreateCustomShape("Table", 1, 10, 5, 7, 7, 6)

    'Add Days of the Week to the each column in Row 1
    s1.Custom.Cell(1, 1).TextShape.Text.Story = "Sun"
    s1.Custom.Cell(2, 1).TextShape.Text.Story = "Mon"
    s1.Custom.Cell(3, 1).TextShape.Text.Story = "Tue"
    s1.Custom.Cell(4, 1).TextShape.Text.Story = "Wed"
    s1.Custom.Cell(5, 1).TextShape.Text.Story = "Thu"
    s1.Custom.Cell(6, 1).TextShape.Text.Story = "Fri"
    s1.Custom.Cell(7, 1).TextShape.Text.Story = "Sat"

    'Add a row above the first column
    s1.Custom.AddRow 1
    
    'Merge the cells in row
    'Add the Title 'January'
    'Center the text
    s1.Custom.Rows(1).Cells.All.Merge
    s1.Custom.Cell(1, 1).TextShape.Text.Story = "January"
    s1.Custom.Cell(1, 1).TextShape.Text.Story.Words.All.Size = 22
    s1.Custom.Cell(1, 1).TextShape.Text.Story.Alignment = _
    cdrCenterAlignment

    'Populate the calendar with dates
    Dim i As Integer
    For i = 1 To 31

    'Insert the numbers starting at cell 13 (ie 1+12)
    s1.Custom.Cells(i + 12).TextShape.Text.Story = i
    Next i

    'Merge the cells with no date
    s1.Custom.Cells.Range(9).Merge

    'Place a fill in the cells containing no dates
    Dim f1 As Fill
    Set f1 = ActiveDocument.CreateFill("EmptyCellFill")
    f1.ApplyUniformFill CreateRGBColor(220, 220, 220)
    s1.Custom.Cells.Range(9, 10, 11, 12).ApplyFill f1

    'Put a border around the tableshape
    s1.Outline.Width = 0.05

    'Put a border around row 1 of the tableshape
    s1.Custom.Rows(1).Cells.All.Borders.All.Width = 0.05
    
    'Put a green border around the January 1st cell
    s1.Custom.Cells(13).Borders.All.Width = 0.05
    s1.Custom.Cells.Range(13).Borders.All.Color.RGBAssign 0, 255, 0
End Sub
-Shelby
Reply With Quote
  #3  
Old 26-07-2010, 15:29
gag546112
Guest
 
Posts: n/a
Default Re: Tables

Hi Shelby,
This is excellent detail.

Do you happen to have any reference information that gives details of the parameters needed to use the CreateCustomShape method for creating tables? I want to dynamically create a table in code, but can't find this level of detail.

I'm using X4.

Thanks,

George
Reply With Quote
  #4  
Old 26-07-2010, 16:11
gag546112
Guest
 
Posts: n/a
Default Re: Tables

Well, after digging for a long time trying to figure this out, I adopted the bootstrap approach - create a table using your example and then dig into the properties of it to figure out which value corresponds with which property.

Please correct me if I'm wrong, or confirm the correctness of my deduction.

Here is your create statement--
CreateCustomShape("Table", 1, 10, 5, 7, 7, 6)
where
1 = LeftX
10 = TopY
5 = RightX
7 = BottomY
7 = Number of Columns
6 = Number of Rows

Of course, this is all dependent on which unit of measurement has been set up and whether your page is laid out as landscape or portrait. In my case, I was set up as cdrInch and landscape, so the table ended up half-way off the top of the page. A bit of tweaking and a change to cdrPixel gave me the level of control that I needed.

Oh to have a complete reference manual or even a book that discusses all of this in detail. It's a pity that the help file is mostly silent on this topic (custom shapes), and many others.

George
Reply With Quote
  #5  
Old 26-07-2010, 20:11
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Table - Help File

The Help file actually shows a pretty good example of this and the parameters. Here is part of it from the X5 help file:

Creating tables
CorelDRAW supports the automation of tables through the use of custom shapes. Here is the syntax for creating a table:

Function CreateCustomShape("Table", Left As Double, Top As Double, Right As Double, Bottom As Double, Columns As Long, Rows As Long) As Shape


Parameter Description
Left Specifies the distance from the left side of the table to the left side of the page frame. This value is measured in document units.
Top Specifies the distance from the top of the table to the top of the page frame. This value is measured in document units.
Right Specifies the distance from the right side of the table to the right side of the page frame. This value is measured in document units.
Bottom Specifies the distance from the bottom of the table to the bottom of the page frame. This value is measured in document units.
Columns Specifies the number of columns
Rows Specifies the number of rows


For information on working with tables, see the TableShape class. The Shape.Custom property provides access to the properties and methods of the TableShape class.

VBA example
The following VBA example creates a document containing a calendar for the month of January 2009, highlighting the cell for January 1st.
Code:
Sub Test() 
Dim s1 As Shape 
CreateDocument 
'Create a Table with 5 columns and 3 rows 
Set s1 = ActiveLayer.CreateCustomShape("Table", 1, 10, 5, 7, 7, 6) 
'Add Days of the Week to the each column in Row 1 
s1.Custom.Cell(1, 1).TextShape.Text.Story = "Sun" 
s1.Custom.Cell(2, 1).TextShape.Text.Story = "Mon" 
s1.Custom.Cell(3, 1).TextShape.Text.Story = "Tue" 
s1.Custom.Cell(4, 1).TextShape.Text.Story = "Wed" 
s1.Custom.Cell(5, 1).TextShape.Text.Story = "Thu" 
s1.Custom.Cell(6, 1).TextShape.Text.Story = "Fri" 
s1.Custom.Cell(7, 1).TextShape.Text.Story = "Sat" 
'Add a row above the first column 
s1.Custom.AddRow 1 
'Merge the cells in row 
'Add the Title 'January' 
'Center the text 
s1.Custom.Rows(1).Cells.All.Merge 
s1.Custom.Cell(1, 1).TextShape.Text.Story = "January" 
s1.Custom.Cell(1, 1).TextShape.Text.Story.Words.All.Size = 22 
s1.Custom.Cell(1, 1).TextShape.Text.Story.Alignment = _ 
cdrCenterAlignment 
'Populate the calendar with dates 
Dim i As Integer 
For i = 1 To 31 
'Insert the numbers starting at cell 13 (ie 1+12) 
s1.Custom.Cells(i + 12).TextShape.Text.Story = i 
Next i 
'Merge the cells with no date 
s1.Custom.Cells.Range(9).Merge 
'Place a fill in the cells containing no dates 
Dim f1 As Fill 
Set f1 = ActiveDocument.CreateFill("EmptyCellFill") 
f1.ApplyUniformFill CreateRGBColor(220, 220, 220) 
s1.Custom.Cells.Range(9, 10, 11, 12).ApplyFill f1 
'Put a border around the tableshape 
s1.Outline.Width = 0.05 
'Put a border around row 1 of the tableshape 
s1.Custom.Rows(1).Cells.All.Borders.All.Width = 0.05 
'Put a green border around the January 1st cell 
s1.Custom.Cells(13).Borders.All.Width = 0.05 
s1.Custom.Cells.Range(13).Borders.All.Color.RGBAssign 0, 255, 0 
End Sub
Best of luck,

-Shelby
Reply With Quote
  #6  
Old 27-07-2010, 06:01
gag546112
Guest
 
Posts: n/a
Default Re: Table - Help File

Thanks Shelby, this is great. Mind you, it isn't actually correct. The comment on the 4th line says that it will create a table with 5 columns and 3 rows, but the code creates one with 7 columns and 6 rows.!!

The X4 help file doesn't have this level of detail. I'll ask Corel if they'll send me the X5 help file. Maybe its got more detail for other things.

Regards,

George

Last edited by gag546112; 27-07-2010 at 06:05.
Reply With Quote
  #7  
Old 27-07-2010, 07:30
gag546112
Guest
 
Posts: n/a
Default Re: Table - Help File

So I did a bit of experimenting, creating tables using different values and have concluded that the X5 help text is wrong.

Here is what it should say:

Parameter Description
Left Specifies the distance from the left side of the table to the left side of the page frame. This value is measured in document units.
Top Specifies the distance from the top of the table to the bottom of the page frame. This value is measured in document units.
Right Specifies the distance from the right side of the table to the left side of the page frame. This value is measured in document units.
Bottom Specifies the distance from the bottom of the table to the bottom of the page frame. This value is measured in document units.
Columns Specifies the number of columns
Rows Specifies the number of rows


What you are really providing is the coordinates of the top left corner and the bottom right corner of the table. For example, using Document.Unit set to cdrInch and parameters 1,6,8,1,7,6 will create a table of 7 columns by 6 rows, that has its bottom left-hand corner positioned 1 inch in from the left page edge and 1 inch up from the bottom page edge. The table will be 7 inches wide (Right minus Left) by 5 inches tall (Top minus Bottom). The column widths and row heights are evenly distributed along the table lengths, although these can be individually adjusted using the TableColumn.SetWidth and TableRow.SetHeight methods if desired.

I think that covers it now.

I appreciate your help in getting to the bottom of this.

Regards,

George
Reply With Quote
  #8  
Old 19-03-2012, 12:55
beczukdavid
Guest
 
Posts: n/a
Default

Thank you guys for this useful information
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Table outline and VBA Vylda CorelDRAW/Corel DESIGNER VBA 2 24-11-2008 11:48
Table scale and placement. Corel accuracy in question? Morphevs General 2 18-11-2008 07:19
Edit each separately imagino CorelDRAW/Corel DESIGNER VBA 1 23-02-2005 14:59
Index table fadimas CorelDRAW/Corel DESIGNER VBA 2 25-01-2005 00:58
making a table of contents daniello CorelDRAW/Corel DESIGNER VBA 0 26-03-2004 02:35


All times are GMT -5. The time now is 07:49.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com