![]() |
#1
|
|||
|
|||
![]()
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) Thanks Guys |
#2
|
||||
|
||||
![]()
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 |
#3
|
|||
|
|||
![]()
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 |
#4
|
|||
|
|||
![]()
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 |
#5
|
||||
|
||||
![]()
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 -Shelby |
#6
|
|||
|
|||
![]()
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. |
#7
|
|||
|
|||
![]()
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 |
#8
|
|||
|
|||
![]()
Thank you guys for this useful information
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
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 |