Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Tables > Editing a Table
Editing a Table

Adding columns

To add new columns into a table, use the insertColumns() method, which inserts the specified number of columns into the table entity at the specified column index. This method requires three parameters: integer value for column index, from which the insertion will start, double value for column width, and integer value for the count of columns. For example:

pTable->insertColumns(1, 12.5, 2);

Adding rows

To add new columns into a table, use the insertRows() method, which inserts the specified number of rows into the table entity at the specified row index. This method requires three parameters: integer value for row index, from which the insertion will start, double value for row height, and integer value for the count of rows. For example:

pTable->insertRows(2, 3, 1);

Deleting columns

To delete columns from a table entity, use the deleteColumns() method, which requires two integer values: one for the column index and one for the count of columns. For example:

pTable->deleteColumns(1,2);

Remember that you can delete only existing columns. If the column index is equal to or greater than the column count or if the number of columns for deletion is greater than the column count, the exception eInvalidInput occurs.

Deleting rows

To delete rows from a table entity, use the deleteRows() method, which requires two integer values: one for the row index and one for the count of rows. For example:

pTable->deleteRows(2,1);

Remember that you can delete only existing rows. If the row index is equal to or greater than the row count or if the number of rows for deletion is greater than the row count, the exception eInvalidInput is occurs.

Merging the cells

To merge cells, use the mergeCells() method, which requires four integer values: two for the first and last rows of cells to merge and two for the first and last columns of cells to merge. For example:

pTable->mergeCells(1, 3, 2, 3);

To find out whether the cell is part of merged cells, use the isMergedCell() method, which returns a Boolean value. Also this method returns the range of merged cells as four integer parameters, passed to the method by its address. For example:

OdUInt32 rowStart = 0; 
OdUInt32 rowEnd = 0; 
OdUInt32 columnStart = 0; 
OdUInt32 columnEnd = 0; 
bool b = pTable->isMerged(2, 2, &rowStart, &rowEnd, &columnStart, &columnEnd);

Getting a merge range

A merge range includes the top row, bottom row, left column, and right column.

To find the size of merged cells, use the getMergeRange() method, which requires two integer parameters for row and column indexes of the merged cell. This method returns the object of the OdCellRange class and has the following members:

OdInt32 m_bottomRow;
OdInt32 m_leftColumn;
Odint32 m_rightColumn;
Odint32 m_topRow;
For example:
OdCellRange cR = pTable->getMergeRange(0,0);
wcout << L"\nTop row of the merging is = " << cR.m_topRow;
wcout << L"\nBottom row of the merging is = " << cR.m_bottomRow;
wcout << L"\nLeft column of the merging is = " << cR.m_leftColumn;
wcout << L"\nRight column of the merging is = " << cR.m_rightColumn;

To get the merge height, use the mergedHeight() method, which requires two integer parameters for row and column indexes of the merged cell and returns an OdUint32 value of the merge height. For example:

wcout << L"\nMerge height = " << pTable->mergedHeight(0,0);

To get the merge width, use the mergedWidth() method, which requires two integer parameters for row and column indexes of the merged cell and returns an OdUint32 value of the merge width. For example:

wcout << L"\nMerge width = " << pTable->mergedWidth(0,0);

Unmerging cells

To unmerge cells, use the unmergeCells() method, which requires four integer values: two for the first and last rows of cells to unmerge and two for the first and last columns of the cells to unmerge. For example:

pTable->unmergeCells(1, 3, 2, 3);

See Also

Overview of Tables

Specific Table Properties

Working with Table Breaks

Example of Working with Tables

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.