Jump to content
Developer Wiki and Function Reference Links Read more... ×
Paulo Renan Ferrari

Extract Worksheet (Column) Values

Recommended Posts

Hi,

 

I'm creating a script that convert RGB to CMYK, the Calc it's OK. But, I need to know, how can I extract the information (Values in numbers) contained in worksheet cell (R, G, B Column) to put in VAR (r,g,b)  and after the calc process, paste the result of Cstr, Mstr, Ystr and Kstr in other Worksheet Cell Like (C, M, Y, K Column).


The worksheet name is: CMYK, 

 

PROCEDURE RGBToCMYK;
{ ------------------------------------------------------ }

CONST { ONLY TO TEST}
r = 127;
g = 255;
b = 212;
{ ------------------------------------------------------ }

VAR
c, m, y, k : REAL;

{r, g, b : LONGINT}
Cstr, Mstr, Ystr, Kstr : STRING;

BEGIN
    c := 1 - ( r / 255 );
    m := 1 - ( g / 255 );
    y := 1 - ( b / 255 );
    k := 1;

IF ( c < k ) THEN k := c;
IF ( m < k ) THEN k := m;
IF ( y < k ) THEN k := y;
    c := ( c - k ) / ( 1 - k );
    m := ( m - k ) / ( 1 - k );
    y := ( y - k ) / ( 1 - k );
    
    Cstr := NUM2STR(4, c);
    Mstr := NUM2STR(4, m);
    Ystr := NUM2STR(4, y);
    Kstr := NUM2STR(4, k);
    
    MESSAGE(CONCAT(Cstr, ' ', Mstr, ' ', Ystr, ' ', Kstr));
END;
RUN(RGBToCMYK);

Captura de Tela 2018-08-13 às 15.42.40.png

Captura de Tela 2018-08-13 às 15.41.35.png

Share this post


Link to post

You are not going to use Cut/Copy and Paste. You are going to have to read the cell, do the calculations and then write the data to the correct cell.

 

Check out the GetWSCellValue in the Function Reference for getting values from cell. 

 

Use SetWSCellFormula to store a value into a cell.  The name is a little misleading, but a number is considered a valid "formula" in a cell.

  • Like 1

Share this post


Link to post

Hi Pat, How Are you?

 

Thanks, I appreciate your help.


Before I reading your message, I did it that way below:

 

PROCEDURE RGBToCMYK;
{ ------------------------------------------------------ }

{CONST {TESTE} 
{r = 127;
g = 255;
b = 212;}
{ ------------------------------------------------------ }

VAR
c, m, y, k : REAL;
vred, vgreen, vblue : LONGINT;
Cstr, Mstr, Ystr, Kstr : STRING;
hplan : HANDLE;
numRows, numColumns : INTEGER;
vlin : INTEGER;


BEGIN

    
    hplan := GetObject('_Plan_Teste);
    IF (hplan <> NIL) THEN GetWSRowColumnCount(hplan, numRows, numColumns);

vlin := 2;

REPEAT


    vred := Str2Num(GetCellStr(hplan, vlin, 4));
    vgreen := Str2Num(GetCellStr(hplan, vlin, 5));
    vblue := Str2Num(GetCellStr(hplan, vlin, 6));
    

    c := 1 - ( vred / 255 );
    m := 1 - ( vgreen / 255 );
    y := 1 - ( vblue / 255 );
    k := 1;    
    

IF ( c < k ) THEN k := c;
IF ( m < k ) THEN k := m;
IF ( y < k ) THEN k := y;
    c := ( c - k ) / ( 1 - k );
    m := ( m - k ) / ( 1 - k );
    y := ( y - k ) / ( 1 - k );
    
    Cstr := NUM2STR(4, c);
    Mstr := NUM2STR(4, m);
    Ystr := NUM2STR(4, y);
    Kstr := NUM2STR(4, k);


    LoadCell(vlin, 7, Cstr);
    LoadCell(vlin, 8, Mstr);
    LoadCell(vlin, 9, Ystr);
    LoadCell(vlin, 10, Kstr);
    

    vlin := vlin+1;
    
    message('Linha:', vlin);

UNTIL(vlin>numRows);
    
END;

RUN(RGBToCMYK);

 

Any comments in this code?

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×