# 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);

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.

Hi Pat, How Are you?

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);

vlin := vlin+1;

message('Linha:', vlin);

UNTIL(vlin>numRows);

END;

RUN(RGBToCMYK);

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×