With ODA Drawings SDK you are able to link table data with an external Microsoft® Excel spreadsheet.
These are the main classes that provide the table linkage functionality:
OdDbDataLink
— Represents a connection from an OdDbTable object to external table data.OdDbDataLinkManager
— Provides functionality for creating, storing and managing data link objects in the database.OdDbLinkedData
— Provides methods for working with the structure and content of the linked table data, such as adding and removing rows and columns, creating and removing content of a specific cell etc. The paragraphs below describes how to use this functionality to enable interoperability of a table in a .dwg drawing and an external Excel file.
To establish a connection to external table data, get an instance of the OdDbDataLinkManager
class, which creates and manages all the data links for the database. To get the data link manager for a specific database, use the global odDbGetDataLinkManager(OdDbDatabase* db)
function:
OdDbDataLinkManager* dataLinkManager = odDbGetDataLinkManager(pDb);
The function returns the already existing OdDbDataLinkManager
object or creates one if it doesn't exist.
Once you get the OdDbDataLinkManager
object, you are able to create connections to external data. A connection is represented by an OdDbDataLink
object, which can be created using the OdDbDataLinkManager::createDataLink()
method. The method has the following signatures:
OdDbObjectId OdDbDataLinkManager::createDataLink(const OdString& adapterId, const OdString& name,
const OdString& description, const OdString& connectionString)
The method creates an OdDbDataLink
object with specified parameters, puts it to the data link dictionary with the specified name and returns the ObjectID.
You can get the total number of created OdDbDataLink
objects using the OdDbDataLinkManager::dataLinkCount()
method.
To get existing OdDbDataLink
objects, OdDbDataLinkManager
class provides the getDataLink() method with the following signatures:
OdDbDataLink
object by its name, use either:
OdDbObjectId OdDbDataLinkManager::getDataLink(const OdString& name);
OdDbDataLinkPtr OdDbDataLinkManager::getDataLink(const OdString& name, OdDb::OpenMode mode);
To get all existing OdDbDataLink
objects, use:
int OdDbDataLinkManager::getDataLink(OdDbObjectIdArray& dataLinks);
The method gets an array of data links and returns the total number of links in the database.
Removing data links is performed by the removeDataLink()
method implemented in two signatures:
OdDbDataLink
object from the data link dictionary by its ID, use void removeDataLink(const OdDbObjectId& idDataLink);
void removeDataLink(const OdString& sKey, OdDbObjectId& idDataLink);
. ID of the removed object is stored in the idDataLink
parameter.After a data link is created, you can link the table with the external table data. Set the link to table data for a specific cell or a cells range using the OdDbTable::setDataLink()
methods:
void OdDbTable::setDataLink (OdInt32 row, OdInt32 col, const OdDbObjectId& idDataLink, bool bUpdate);
void OdDbTable::setDataLink (const OdCellRange& range, const OdDbObjectId& idDataLink, bool bUpdate);
The bUpdate
flag indicates if the data link is to be updated after it's set.
To get a data link set for a table cell or a cells range, use the OdDbTable::getDataLink ()
methods:
OdDbObjectId getDataLink (OdInt32 row, OdInt32 col) const;
OdInt32 getDataLink (const OdCellRange& pRange, OdDbObjectIdArray& dataLinkIds) const;
OdDbDataLinkPtr getDataLink (OdInt32 row, OdInt32 col, OdDb::OpenMode mode) const;
For linked tables, you can use the OdDbTable::updateDataLink() methods to upload data from your table to the source excel data or download the changes from the source table:
void updateDataLink (OdInt32 row, OdInt32 col, OdDb::UpdateDirection nDir, OdDb::UpdateOption nOption);
void updateDataLink (OdDb::UpdateDirection nDir, OdDb::UpdateOption nOption);
To update the table with downloading data from the source table, use OdDB::kUpdateDirectionSourceToData
as an nDir
value.
To update the source table with uploading data from your table, use OdDB::kUpdateDirectionDataToSource
as an nDir
value.
Sample code of the CreateLinkedTable
command for creating a linked table is available in Drawing\Examples\ExCustObjs\DrxDebugCmds.cpp
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|