Paulo Renan Ferrari Posted August 13, 2018 Share Posted August 13, 2018 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); Quote Link to comment
Pat Stanford Posted August 13, 2018 Share Posted August 13, 2018 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. 1 Quote Link to comment
Paulo Renan Ferrari Posted August 13, 2018 Author Share Posted August 13, 2018 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? Quote Link to comment
Recommended Posts
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.