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

A table object has cells that are numbered according to row number and column number. A table object has a finite number of rows and columns. Columns have width, and rows have height. The whole table object also has its own width and height.

Table size

The size of a table includes its width, height, and number of rows and columns.

Table width

Table width indicates how wide the table object is. To get the table width, use the width() method, which does not have arguments and returns the width as a Double value. For example:

wcout << L"\nWidth = " << pTable->width();

To set a new table width, use the setWidth() method, which requires a Double value for the new table width. For example:

pTable->setWidth(67.3);

Table height

Table height indicates how long the table object is. To get the table height, use the height() method, which does not have arguments and returns the height as a Double value. For example:

wcout << L"\nHeight = " << pTable->height();

To set a new table height, use the setHeight() method, which requires a Double value for the new table height. For example:

pTable->setHeight(30.5);

Minimum size of a table

Minimum height and width of a table are special values. If you try to set the height and width of the table with values that are lower than the minimum values, they will be replaced by the minimum values.

To get the minimum height of the table, use the minimumTableHeight() method, which requires no parameters and returns a Double value of the minimum overall height for the table entity. For example:

wcout << L"\nMinimum height of the table: " << pTable->minimumTableHeight();

To get the minimum width of the table, use the minimumTableWidth() method, which requires no parameters and returns a Double value of the minimum overall width for the table entity. For example:

wcout << L"\nMinimum width of the table: " << pTable->minimumTableWidth();

Number of rows

The number of rows indicates how many rows are in the table object. To get the number of rows, use the numRows() method, which does not have arguments and returns the number of rows as an Integer value. For example:

wcout << L"\nRows = " << pTable->numRows();

Number of columns

Number of columns indicates how many columns are in the table object. To get the number of columns, use the numColumns() method, which does not have arguments and returns the number of columns as an Integer value. For example:

wcout << L"\nColumns = " << pTable->numColumns();

Setting the table size

To set the size of a table (rows+columns), use the setSize() method, which requires two Integer parameters: one for the number of rows and one for the number of columns. For example:

pTable->setSize(3,4);

This example sets 3 rows and 4 columns for pTable.

Cell size

Each cell is determined by its row index and column index. So, if you want to know the width and height of the cell, you should know the width of its column and height of its row.

Column width

Column width indicates how wide the column is. To get the width of a separate column, use the columnWidth() method, which requires an Integer value of the column number and returns the width as a Double value. For example:

wcout << L"\nColumnWidth = " << pTable->columnWidth(2);

To set a new value for the column width, use the setColumnWidth() method, which requires two arguments: an Integer value for the column index as the first argument and a Double value of the new column width as the second argument. For example:

pTable->setColumnWidth(2, 34.5);

Row height

Row height indicates the height of the row. To get the height of a separate row, use the rowHeight() method, which requires an Integer value for the number of the row and returns its height as a Double value. For example:

wcout << L"\nRowHeight = " << pTable-> rowHeight(2);

To set a new value for the row height, use the setRowHeight() method, which requires two arguments: an Integer value of the row index as the first argument and a Double value of the new row height as the second argument. For example:

pTable->setRowHeight(3, 2.4);

Minimum size of the cell

Minimum row height and minimum column width play the same role for the cell as the minimum table height and minimum table width for the table.

To get the minimum height of a row, use the minimumRowHeight() method, which requires one Integer parameter to indicate the row index and returns a Double value of the minimum row height for the specified row. For example:

wcout << L"\nMinimum height of the row: " << pTable->minimumRowHeight(1);

To get the minimum width of a column, use the minimumColumnWidth() method, which requires one Integer parameter to indicate the column index and returns a Double value of the minimum column width for the specified column. For example:

wcout << L"\nMinimum width of the column: " << pTable->minimumColumnWidth(1);

Flow direction

Flow direction shows the direction of rows in the table. To get the flow direction of a table entity, use the flowDirection() method, which requires no arguments and returns one of the following values of the FlowDirection enumerator:

enum FlowDirection
{
	kTtoB = 0,
	kBtoT = 1
}

kTtoB means that rows flow from top to bottom:

kBtoT means that rows flow from bottom to top:

For example:

wcout << L"\nFlow direction: " << pTable-> rowDirection();

To set the flow direction, use the setFlowDirection() method, which requires one parameter: one value from the FlowDirection enumerator (see above). For example:

pTable->setFlowDirection(OdDb::FlowDirection::kTtoB);

Table style

You can create and store table styles that contain text height, flow direction, and other properties and use them for creating table objects.

To set a table style, use the setTableStyle() method, which requires one parameter: the Object ID of the OdDbTableStyle. For example:

pTable->setTableStyle(stId);

To get the object ID of the table style, use the tableStyle() method which requires no parameters and returns the ID of the table style as an OdDbObjectId value. For example:

stId = pTable->tableStyle();

Column name

To get the column name, use the getColumnName() method, which requires one integer parameter that indicates the column index. For example:

wcout << L"\nColumn name: " << pTable-> getColumnName(1);

To set the column name, use the setColumnName() method, which requires two parameters: one integer value to indicate the column index and one OdString parameter for the column name. For example:

pTable->setColumnName(1,OD_T("B"));

Row types

A table can have several types of rows, such as "title,""header,"and "data." The next picture describes the row types of the table entity.

Row types are represented by the OdDb::RowType enumerator and consist of the following values:

enum RowType
{
	kUnknownRow		= 0x0,
	kDataRow		= 0x1,
	kTitleRow		= 0x2,
	kHeaderRow		= 0x4
}

Working with cells

To work with a cell, you should know its row and column indexes. To work with the data in the cell, you should know what type of data is stored in the cell.

Cell style

Table cells have different styles, just like rows which have such styles as "_TITLE","_HEADER", and "_DATA".

To set the style for a cell, use the setCellStyle() method, which requires three parameters: two integers to indicate row and column indexes and a OdString parameter to indicate cell style. Note that each table must have its own table style. For example:


pTable->setCellStyle(2,2, L"_DATA");

To get the style of a cell, use the cellStyle() method, which requires two integers to indicate the row and column indexes of the cell. It returns the result as an OdString value. For example:

odPrintConsoleString(L"\t %s", pTable->cellStyle(row,col).c_str());

Data in cells

Cells may contain text, object references, or both. To get the object ID of the block table record in the cell, use the blockTableRecordID() method and two integer parameters for the row and column indexes. For example:

wcout << L"\nObject ID of cell [3,3] = " << pTable-> blockTableRecordId(3,3);

If a cell has multiple content, use the blockTableRecordID() method and three integer parameters: row index, column index, and number of content. For example:

wcout << L"\nObject ID of cell [3,3] = " << pTable-> blockTableRecordId(3,3,0);

To set the object ID of the block table record into the cell, use the setBlockTableRecordId() method and three parameters: two integers for row index and column index, and an OdDbObjectId value for the Object ID of the block. For example (newBlockId is the reference of the Object ID):

pTable->setBlockTableRecordId(2, 1, newBlockId);

If a cell has multiple content, use the setBlockTableRecordId() method and four parameters: two integers for row and column indexes, one integer for the number of content, and an OdDbObjectId value for the Object ID of the block. For example (newBlockId is the reference of the Object ID):

pTable->setBlockTableRecordId(2, 1, 0, newBlockId);

To get data from text cells, use the textString() method and two arguments: number of rows (integer) and number of columns (integer). This method returns the text string in the specified cell of the table entity. For example:

wcout << L"\nData = " << pTable->textString(2,3);

If a cell has multiple content, use the textString() method and three integer arguments: row index, column index, and the number of the content. This method returns the text string in the specified cell of the table entity. For example:

wcout << L"\nData = " << pTable->textString(2,3,1);

To set data in a text cell, use the SetTextString() method and three arguments: two integer values that indicate the number of the cell row and column and a String value of the text to insert. For example:

pTable->setTextSring(2,3, L"Some_text");

If a cell has multiple content, use the SetTextString() method and four arguments: two integer values that indicate the number of the cell row and column, Integer value of the number of the content, and a String value of the text to insert. For example:

pTable->setTextSring(2,3,1, L"Some_text");

To find out whether a cell is empty, use the isEmpty() method, which requires two integers to indicate the row and column indexes. This method returns a Boolean value of the result. For example:

bool b = pTable->isEmpty(2,2);

Text height

You can get and set the height of text by row type or a cell.

Text height of the row type

To get the text height of a specified row type, use the textHeight() method, which requires one argument: one value from the OdDb::RowType enumerator:

enum RowType
{
  kUnknownRow	= 0x0,
  kDataRow	= 0x1,
  kTitleRow	= 0x2,
  kHeaderRow	= 0x4
}

This method returns the text height as a Double value. For example:

wcout << L"\nText height of the data rows = " << pTable-> textHeight(OdDb::RowType::kDataRow);

To set the text height for a specified row type, use the setTextHeight() method, which requires two parameters: text height as a Double value and row type as one of the values from the OdDb::RowType enumerator (see above). For example:

pTable->setTextHeight (2.5,OdDb::RowType::kDataRow);

Text height of the cell

To get text height of the specified cell, use the textHeight() method, that requires two integer parameters to indicate row and column of the cell. This method returns text height as double value. For example:

wcout << L"\nText height of the cell [1,3] = " << pTable-> textHeight(1,3);

To set the text height of the specified cell, use the setTextHeight() method, which requires three parameters: two integers as the row and column indexes and the text height as a Double value. For example:

pTable-> setTextHeight (1, 3, 4.5);

Working with scale of the block reference

You can scale block references in a cell.

Auto-scaling

To set or unset auto-scaling for a cell with kBlockCell type, use the setAutoScale() method, which requires three parameters: two integers as the row and column indexes and a Boolean value for the auto-scaling flag. For example:

pTable->setAutoScale(3,3,true);

To find out whether the cell is auto-scaling, use the isAutoScale() method, which requires two integer parameters as the row and column indexes. This method returns true if the block in the specified cell of the table entity is scaled automatically. For example:

if(pTable->isAutoScale(3,3))
	wcout << L"\nCell [3,3] is auto-scaled"
else wcout << L"\nCell [3,3] is not auto-scaled"

Scaling the block reference

To get the scale of the block reference, use the blockScale() method, which requires two integers as the row and column indexes. This method returns the scale factor of the block reference as a Double value.

wcout << L"\nScale factor of the cell [1,2] = " << pTable-> blockScale(1,2);

To set the scale factor of the block reference in the specified cell, use the setBlockScale() method, which requires three parameters: two integers as the row and column indexes and a Double value for the scale factor of the block reference.

pTable-> setBlockScale(1, 2, 3.5);

Data rotation

You can rotate the data in cells.

To get the rotation of text or a block reference, use the rotation() method, which returns the rotation angle as a Double value and requires three parameters: two integers to indicate the row and column of the cell, and an Integer value for indicating the number of the content. For example:

wcout << L"\nRotation angle in cell [2,2] is "<< pTable->rotation(2,2,0);

To set the rotation of text or a block reference, use the setRotation() method, which requires four parameters: two Integer values to indicate the row and column of the cell, an Integer value for indicating the number of the content, and a Double value for the rotation angle in radians. For example:

pTable->setRotation(2,2,0,OdaToRadian(30.0));

Alignment

You can set various alignment settings by row type or cell.

Alignment of row type

To get the alignment of a specified row type, use the alignment() method, which requires one RowType parameter to indicate the row type for which you want to return the alignment. The RowType is an enumerator and consists of the following values:

enum RowType
{
	kUnknownRow	= 0x0,
	kDataRow	= 0x1,
	kTitleRow	= 0x2,
	kHeaderRow	= 0x4
}

This method returns one of the following values of the CellAlignment enumerator:

enum CellAlignment {
	kTopLeft 	= 1,
	kTopCenter	= 2,
	kTopRight	= 3,
	kMiddleLeft	= 4,
	kMiddleCenter	= 5,
	kMiddleRight	= 6,
	kBottomLeft	= 7,
	kBottomCenter	= 8,
	kBottomRight	= 9
}

For example:

wcout << L"\nAlign of Data rows = " << pTable-> alignment(OdDb::RowType::kDataRow);

To set the alignment of a row type, use the setAlignment() method, which requires two parameters: one of the values from the CellAlignment enumerator (see above) and one of the values from the rowTypes enumerator (see above). For example:

pTable->setAlignment(3, OdDb::CellAlignment::kBottomLeft);

Alignment of the cell

To get the alignment of a specified cell, use the alignment() method, which requires two integer parameters for the row and column indexes. This method returns one of the following values of the CellAlignment enumerator:

enum CellAlignment {
	kTopLeft	= 1,
	kTopCenter	= 2,
	kTopRight	= 3,
	kMiddleLeft	= 4,
	kMiddleCenter	= 5,
	kMiddleRight	= 6,
	kBottomLeft	= 7,
	kBottomCenter	= 8,
	kBottomRight	= 9
}

For example:

wcout << L"\nAlign of cell [2,3] = " << pTable-> alignment(2,3);

To set the alignment of a row type, use the setAlignment() method, which requires three parameters: two integers to indicate the row and column indexes and one of the values from CellAlignment enumerator (see above). For example:

pTable->setAlignment(2, 3, OdDb::CellAlignment::kTopCenter);

Working with grid lines

Each cell has four lines around it: horizontal bottom, horizontal top, vertical right and vertical left.

Grid line style

Each grid line can be a single or double line.

To get the style of a grid line, use the gridLineStyle() method, which requires three parameters: two integers for row and column indexes and one value from the OdDb::GridLineType enumerator:

enum GridLineType
{
	kInvalidGridLine	= 0x00,
	kHorzTop		= 0x01,
	kHorzInside		= 0x02,
	kHorzBottom		= 0x04,
	kVertLeft		= 0x08,
	kVertInside		= 0x10,
	kVertRight		= 0x20,
	kHorzGridLineTypes	= kHorzTop | kHorzBottom | kHorzInside,
	kVertGridLineTypes	= kVertLeft | kVertRight | kVertInside,
	kOuterGridLineTypes	= kHorzTop | kHorzBottom | kVertLeft | kVertRight,
	kInnerGridLineTypes	= kHorzInside | kVertInside,
	kAllGridLineTypes	= kOuterGridLineTypes | kInnerGridLineTypes
}

This method returns a value from the OdDb::GridLineStyle enumerator with next implementation:

enum GridLineStyle
{
	kGridLineStyleSingle = 1,
	kGridLineStyleDouble = 2
}

For example:

wcout << L"\nStyle of the horizontal bottom line of the cell [2,2]:" << pTable->gridLineStyle(2, 2, OdDb::GridLineType::kHorzBottom);

To set the style of a grid line, use the setGridLineStyle() method, which requires four parameters: two integers for row and column indexes, one of the values from the OdDb::GridLineType enumerator (see above), and one value from the OdDb::GridLineStyle enumerator (see above). For example:

pTable->setGridLineStyle(2, 2, OdDb::GridLineType::kHorzBottom, OdDb::GridLineStyle::kGridLineStyleDouble);

Spacing of the double grid line

If a cell has a double grid line, you can get its spacing by using the gridDoubleLineSpacing() method, which requires three parameters: two integers as the row and column indexes and one value from the OdDb::GridLineType enumerator:

enum GridLineType
{
	kInvalidGridLine	= 0x00,
	kHorzTop		= 0x01,
	kHorzInside		= 0x02,
	kHorzBottom		= 0x04,
	kVertLeft		= 0x08,
	kVertInside		= 0x10,
	kVertRight		= 0x20,
	kHorzGridLineTypes	= kHorzTop | kHorzBottom | kHorzInside,
	kVertGridLineTypes	= kVertLeft | kVertRight | kVertInside,
	kOuterGridLineTypes	= kHorzTop | kHorzBottom | kVertLeft | kVertRight,
	kInnerGridLineTypes	= kHorzInside | kVertInside,
	kAllGridLineTypes	= kOuterGridLineTypes | kInnerGridLineTypes
}

The method returns double line spacing as a Double value. For example:

wcout << L"\nSpacing of the bottom line of the cell [2,2]:" << pTable->gridDoubleLineSpacing(2, 2, OdDb::GridLineType::kHorzBottom);

To set double line spacing, use the setGridDoubleLineSpacing() method, which requires four parameters: two integers for the row and column indexes, one of the values from OdDb::GridLineType enumerator (see above), and a Double value for the new spacing. For example:

pTable->setGridDoubleLineSpacing(2, 2, OdDb::GridLineType::kHorzBottom, 0.2);

Grid line visibility

To get the visibility of a grid line, use the gridLineVisibility() method. There are two variations: by specified cell or specified rowType.

OdDb::RowType is an enumerator and consists of the following values:

enum RowType
{
	kUnknownRow		= 0x0,
	kDataRow		= 0x1,
	kTitleRow		= 0x2,
	kHeaderRow		= 0x4
}

This method requires two parameters: one value from the OdDb::GridLineType enumerator and one value from the OdDb::RowType enumerator. OdDb::GridLineType has the following implementation:

enum GridLineType
{
	kInvalidGridLine	= 0x00,
	kHorzTop		= 0x01,
	kHorzInside		= 0x02,
	kHorzBottom		= 0x04,
	kVertLeft		= 0x08,
	kVertInside		= 0x10,
	kVertRight		= 0x20,
	kHorzGridLineTypes	= kHorzTop | kHorzBottom | kHorzInside,
	kVertGridLineTypes	= kVertLeft | kVertRight | kVertInside,
	kOuterGridLineTypes	= kHorzTop | kHorzBottom | kVertLeft | kVertRight,
	kInnerGridLineTypes	= kHorzInside | kVertInside,
	kAllGridLineTypes	= kOuterGridLineTypes | kInnerGridLineTypes
}

This method returns one value from the OdDb::Visibility enumerator:

enum Visibility
{
	kInvisible	= 1,
	kVisible	= 0
}

For example:

wcout << L"\n Visibility of the grid bottom lines of Data rows = " << pTable-> gridVisibility(OdDb::GridLineType::kHorzBottom , OdDb::RowType::kDataRow);

To set the visibility of a grid line for a specified row type, use the setGridVisibility() method, which requires three parameters: one value from the OdDb::Visibility enumerator (see above), one value from the OdDb::GridLineType enumerator, and one value from the OdDb::RowType enumerator. For example:

pTable->setGridVisibility(OdDb::Visibility::kInvisible, OdDb::GridLineType::kHorzBottom, OdDb::RowType::kDataRow);

To get the grid line visibility value from a specified cell, use the gridVisibility() method, which requires three parameters: two integers as row and column indexes and one value from the OdDb::GridLineType enumerator (see above). This method returns one value from the OdDb::Visibility enumerator. For example:

wcout << L"\n Visibility of the grid top line from cell [2,2] = " << pTable-> gridVisibility(2, 2, OdDb::GridLineType::kHorzTop);

To set the visibility of the grid line for the specified cell, use the setGridVisibility() method, which requires four parameters: two integers as row and column indexes, one value from the OdDb::GridLineType enumerator (see above), and one value from the OdDb::Visibility enumerator (see above). For example:

pTable->setGridVisibility(2, 2, OdDb::GridLineType::kHorzTop, OdDb::Visibility::kInvisible);

See Also

Overview of Tables

Editing a Table

Working with Table Breaks

Example of Working with Tables

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