Copying Table Cell Properties...

General TRichView support forum. Please post your questions here
Post Reply
Shane Stump
Posts: 54
Joined: Mon Jul 31, 2006 2:10 am

Copying Table Cell Properties...

Post by Shane Stump »

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
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

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.
Shane Stump
Posts: 54
Joined: Mon Jul 31, 2006 2:10 am

Post by Shane Stump »

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
Shane Stump
Posts: 54
Joined: Mon Jul 31, 2006 2:10 am

Post by Shane Stump »

Sergey,

Any idea why the above code isn't working?

Best Regards,

Shane
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

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.
Shane Stump
Posts: 54
Joined: Mon Jul 31, 2006 2:10 am

Post by Shane Stump »

Sergey.

Couple of Things:

1) Do you know when the next version will be out - approximately?

2) Do you have a short-term recommendation on how I can do this (what cell properties do I need to copy (call)?

3) Can you add an option in the next version to also save the page layout ?

Best Regards,

Shane
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

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?
Shane Stump
Posts: 54
Joined: Mon Jul 31, 2006 2:10 am

Post by Shane Stump »

GREAT! Since I am a registered user, I will be happy!

3) What do you mean?
Save margins. I am trying to get some code you posted several months back to work now to save the margins!

Best Regards,

Shane
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I do not want to save RVPrint's properties in RVF by default. Because page properties will be implemented differently in future versions.
Shane Stump
Posts: 54
Joined: Mon Jul 31, 2006 2:10 am

Post by Shane Stump »

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?
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).

Best Regards,

Shane
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

New update is available for registered users. Copying default text and paragraph style for inserted rows/columns is implemented.
Shane Stump
Posts: 54
Joined: Mon Jul 31, 2006 2:10 am

Post by Shane Stump »

THanks!

Shane
Post Reply