Tables in RichEdit5

Tables in RichEdit5

Postby Natter » Sun Jul 16, 2023 2:51 pm

Hi,

In RichEdit5, open an RTF file. There are tables in this file. How can I access the cells of these tables ?
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: Tables in RichEdit5

Postby Antonio Linares » Mon Jul 17, 2023 5:43 am

Dear Yuri,

Have a look at this code:
Code: Select all  Expand view  RUN
// Assuming you have a handle to the Rich Edit control
// in the variable `hRichEdit`.

// Get the number of tables in the document.
int tableCount = SendMessage(hRichEdit, EM_GETTABLECOUNT, 0, 0);

// Iterate through the tables.
for (int i = 0; i < tableCount; i++) {
    // Select the current table.
    SendMessage(hRichEdit, EM_SETSEL, 0, MAKELONG(i, i));

    // Get the table properties.
    TABLESELINFO tsi;
    SendMessage(hRichEdit, EM_GETTABLESEL, 0, (LPARAM)&tsi);

    // Extract the table structure information.
    int numRows = tsi.cRows;
    int numCols = tsi.cCols;

    // Iterate through the rows and columns of the table.
    for (int row = 0; row < numRows; row++) {
        for (int col = 0; col < numCols; col++) {
            // Access the cell at the current row and column.
            CELLINFO ci;
            ci.cbSize = sizeof(ci);
            ci.row = row;
            ci.col = col;
            SendMessage(hRichEdit, EM_GETCELLINFO, 0, (LPARAM)&ci);

            // Process the cell's information as needed.
            // The ci contains information such as cell's text, formatting, etc.
            // For example:
            wchar_t cellText[256];
            SendMessage(hRichEdit, EM_GETTEXTRANGE, ci.cpStart, ci.cpEnd, (LPARAM)cellText);
            // Process the cell text...

            // You can also modify the cell content if desired:
            // SendMessage(hRichEdit, EM_SETSEL, ci.cpStart, ci.cpEnd);
            // SendMessage(hRichEdit, EM_REPLACESEL, TRUE, (LPARAM)L"New Text");
        }
    }
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Tables in RichEdit5

Postby Natter » Mon Jul 17, 2023 10:05 am

Antonio, thanks for the example!

1. What is a hRichedit handle, because we are working with a TRichEdit5 object ?
2. Is there any guide for working with RichEdit5 ?
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: Tables in RichEdit5

Postby Antonio Linares » Mon Jul 17, 2023 11:46 am

Dear Yuri,

oRichEdit:hWnd is hRichEdit

We need to adapt that code to FWH. We are going to try it... :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Tables in RichEdit5

Postby Natter » Mon Jul 17, 2023 11:51 am

I understood.
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 86 guests