Copying Table Cell Properties...
-
- Posts: 54
- Joined: Mon Jul 31, 2006 2:10 am
Copying Table Cell Properties...
I have allowed my users to create data 'tags' within a document template.
I also allow them to create 'data bands' via tables. The data band tables have a row of fields.
As I parse the document processing tags, when I get to a data set table, I insert RecordCount - 1 rows in the table to hold all the data in the data set.
I use the table's InsertRows() method and I specify the data field row as the row to copy the attributes to the inserted rows and it works as expected.
The problem I am having is that I need to copy the data set row's TEXT cell attributes also (vertical + horizontal alignment, color, font, etc).
What is the best way to do this?
Best Regards,
Shane
I also allow them to create 'data bands' via tables. The data band tables have a row of fields.
As I parse the document processing tags, when I get to a data set table, I insert RecordCount - 1 rows in the table to hold all the data in the data set.
I use the table's InsertRows() method and I specify the data field row as the row to copy the attributes to the inserted rows and it works as expected.
The problem I am having is that I need to copy the data set row's TEXT cell attributes also (vertical + horizontal alignment, color, font, etc).
What is the best way to do this?
Best Regards,
Shane
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
You can use some undocumented methods:
table.Cells[Row,Col].AssignAttributesFrom(SourceCell, False, 1, 1);
Or, if you want this assignment to be undone, use table.AssignCellAttributes with the same parameters.
If the boolean parameter is False, BestWidth and BestHeight properties are not assigned. If it is True, it is assigned, divided by values of the two last parameters.
In both cases, only properties of cell are assigned. Content is not assigned.
table.Cells[Row,Col].AssignAttributesFrom(SourceCell, False, 1, 1);
Or, if you want this assignment to be undone, use table.AssignCellAttributes with the same parameters.
If the boolean parameter is False, BestWidth and BestHeight properties are not assigned. If it is True, it is assigned, divided by values of the two last parameters.
In both cases, only properties of cell are assigned. Content is not assigned.
-
- Posts: 54
- Joined: Mon Jul 31, 2006 2:10 am
Sergey,
I tried AssignAttributesFrom() and it doesn't copy the source cell's font or alignment properties. Please see C++ code below:
void TReservationDocumentEditDialog::InsertTableRows(TRVTableItemInfo * pTable,int nFieldRow,TDataSet * pDataSet,TOnDocumentProcessTags pOnProcessTags)
{
// Determine last data row
int nLastDataRow = nFieldRow + pDataSet->RecordCount - 1;
// Insert rows
if (nLastDataRow > nFieldRow)
{
pTable->InsertRows(nFieldRow + 1,pDataSet->RecordCount - 1,nFieldRow);
}
// Set alias to field row
TRVTableRow * pFieldRow = (*pTable->Rows)[nFieldRow];
// Copy original field values
for (int nDataRow = nFieldRow + 1; nDataRow <= nLastDataRow; ++nDataRow)
{
for (int nColIndex = 0; nColIndex < pFieldRow->Count; ++nColIndex)
{
TRVTableCellData * pSourceFieldCellData = pTable->Cells[nFieldRow][nColIndex];
TRVTableCellData * pTargetFieldCellData = pTable->Cells[nDataRow][nColIndex];
if (pSourceFieldCellData != NULL)
{
// Assign target attributes same as source field
pTargetFieldCellData->AssignAttributesFrom(pSourceFieldCellData,false,1,1);
// Set aliases to cell data objects
TCustomRVData * pSourceFieldRVData = pSourceFieldCellData->GetRVData();
TCustomRVData * pTargetFieldRVData = pTargetFieldCellData->GetRVData();
// Text item ??
if (pSourceFieldRVData->GetItemStyle(0) >= 0)
{
pTargetFieldRVData->SetItemTextA(0,pSourceFieldRVData->GetItemTextA(0));
}
}
}
}
}
Best Regards,
Shane
I tried AssignAttributesFrom() and it doesn't copy the source cell's font or alignment properties. Please see C++ code below:
void TReservationDocumentEditDialog::InsertTableRows(TRVTableItemInfo * pTable,int nFieldRow,TDataSet * pDataSet,TOnDocumentProcessTags pOnProcessTags)
{
// Determine last data row
int nLastDataRow = nFieldRow + pDataSet->RecordCount - 1;
// Insert rows
if (nLastDataRow > nFieldRow)
{
pTable->InsertRows(nFieldRow + 1,pDataSet->RecordCount - 1,nFieldRow);
}
// Set alias to field row
TRVTableRow * pFieldRow = (*pTable->Rows)[nFieldRow];
// Copy original field values
for (int nDataRow = nFieldRow + 1; nDataRow <= nLastDataRow; ++nDataRow)
{
for (int nColIndex = 0; nColIndex < pFieldRow->Count; ++nColIndex)
{
TRVTableCellData * pSourceFieldCellData = pTable->Cells[nFieldRow][nColIndex];
TRVTableCellData * pTargetFieldCellData = pTable->Cells[nDataRow][nColIndex];
if (pSourceFieldCellData != NULL)
{
// Assign target attributes same as source field
pTargetFieldCellData->AssignAttributesFrom(pSourceFieldCellData,false,1,1);
// Set aliases to cell data objects
TCustomRVData * pSourceFieldRVData = pSourceFieldCellData->GetRVData();
TCustomRVData * pTargetFieldRVData = pTargetFieldCellData->GetRVData();
// Text item ??
if (pSourceFieldRVData->GetItemStyle(0) >= 0)
{
pTargetFieldRVData->SetItemTextA(0,pSourceFieldRVData->GetItemTextA(0));
}
}
}
}
}
Best Regards,
Shane
-
- Posts: 54
- Joined: Mon Jul 31, 2006 2:10 am
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Table.InsertRows already uses AssignAttributesFrom for copying cell properties to the inserted rows.
But only cell properties are copied, not cell content. New cells have one empty text item of 0 text style and 0 paragraph style.
Well, in the next update, styles of this text item will be copied too.
But only cell properties are copied, not cell content. New cells have one empty text item of 0 text style and 0 paragraph style.
Well, in the next update, styles of this text item will be copied too.
-
- Posts: 54
- Joined: Mon Jul 31, 2006 2:10 am
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Posts: 54
- Joined: Mon Jul 31, 2006 2:10 am
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Posts: 54
- Joined: Mon Jul 31, 2006 2:10 am
I will wait for the update for #2 as I need the entire target cell attributes to be copied and you know better than I do what all that means (meaning I have tried the suggestions and it is still incomplete).Sergey Tkachenko wrote:1) This week (update for registered users)
2)
NewCell->Clear();
NewCell->AddNLATag('', StyleNo, ParaNo);
where
ParaNo = SourceCell->GetItemPara(0);
StyleNo = index of style of the first text item in SourceCell (or 0, if this cell does not have text items)
3) What do you mean?
Best Regards,
Shane
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: