Macro with colors

Adding a first (new) user / portal activity notifications / email / chat
Post Reply
JoseD
Posts: 2
Joined: Sun May 03, 2020 9:16 pm

Macro with colors

Post by JoseD » Sun May 03, 2020 9:29 pm

Macro with colors.
I am currently giving the opportunity to this office suite. I am really enjoying it. I think it is a high quality product.
Since I am a novice in using it, I tell you. Forgive me if I have made a mistake that I have not seen.

In the following macro, why doesn't the macro color the cell with the correct colors?

Code: Select all

(function()
{
    var hoja = Api.GetActiveSheet();
    
    // Columnas.
    var columnas = "ABCDEFGHIJKLMNOPQRST";
    
    // Rango de trabajo de la imgen.
    var ancho = 6;
    var alto = 6;
    var inicio_columna = 1;
    var inicio_fila = 3;
    
    // Recorremos los píxeles.
    for(var i = 0; i < alto; i++) {  // Filas.
        for(var j = 0; j < ancho * 3; j += 3 ) {  // Columnas.
            var fila = inicio_fila + i
            var columna = inicio_columna + j
        
            // Conseguimos las tres celdas.
            var celdaRojo  = hoja.GetRange(columnas[columna + 0] + fila);
            var celdaVerde = hoja.GetRange(columnas[columna + 1] + fila);
            var celdaAzul  = hoja.GetRange(columnas[columna + 2] + fila);
            
            // Conseguimos sus valores de RGB.
            var valorRojo  = celdaRojo.GetValue();
            var valorVerde = celdaVerde.GetValue();
            var valorAzul  = celdaAzul.GetValue();
            
            // Calculamos el color.
            var color = Api.CreateColorFromRGB(valorRojo, valorVerde, valorAzul);
            
            // Aplicamos los colores de RGB.
            celdaRojo.SetFillColor(color);
            celdaVerde.SetFillColor(color);
            celdaAzul.SetFillColor(color);
            
            hoja.GetRange(columnas[columna] + (15 + fila)).SetValue(valorRojo + ', ' + valorVerde + ', ' + valorAzul);
        }
    }
})();
Thanks in advance.

Alexandre
Posts: 151
Joined: Thu Dec 12, 2019 11:08 am

Re: Macro with colors

Post by Alexandre » Mon May 18, 2020 1:25 pm

Hello JoseD.
As I noticed you have an extra character at the end of your macro (})(). I mean this character ) . Please change it.
Also attach to your reply screenshots with examples of incorrect colors.

JoseD
Posts: 2
Joined: Sun May 03, 2020 9:16 pm

Re: Macro with colors

Post by JoseD » Fri May 22, 2020 11:42 pm

Thank you very much for the help. Today I have remembered that I did not upload the final result and I like to upload the solutions so that they are saved in the forums for other people.

Code: Select all

(function()
{
    var hoja = Api.GetActiveSheet();
    
    // Columnas.
    var columnas = "ABCDEFGHIJKLMNOPQRST";
    
    // Rango de trabajo de la imgen.
    var ancho = 6;
    var alto = 6;
    var inicio_columna = 1;
    var inicio_fila = 3;
    
    // Recorremos los píxeles.
    for(var i = 0; i < alto; i++) {  // Filas.
        for(var j = 0; j < ancho * 3; j += 3 ) {  // Columnas.
            var fila = inicio_fila + i
            var columna = inicio_columna + j
        
            // Conseguimos las tres celdas.
            var celdaRojo  = hoja.GetRange(columnas[columna + 0] + fila);
            var celdaVerde = hoja.GetRange(columnas[columna + 1] + fila);
            var celdaAzul  = hoja.GetRange(columnas[columna + 2] + fila);
            
            // Conseguimos sus valores de RGB.
            var valorRojo  = celdaRojo.GetValue();
            var valorVerde = celdaVerde.GetValue();
            var valorAzul  = celdaAzul.GetValue();
            
            // Calculamos el color.
            var color = Api.CreateColorFromRGB(valorRojo, valorVerde, valorAzul);
            
            // Aplicamos los colores de RGB.
            celdaRojo.SetFillColor(color);
            celdaVerde.SetFillColor(color);
            celdaAzul.SetFillColor(color);
            
            hoja.GetRange(columnas[columna] + (15 + fila)).SetValue(valorRojo + ', ' + valorVerde + ', ' + valorAzul);
        }
    }
})();
Attachments
Captura de pantalla de 2020-05-23 01-38-24.png
Captura de pantalla de 2020-05-23 01-38-24.png (72.8 KiB) Viewed 492 times

Alexandre
Posts: 151
Joined: Thu Dec 12, 2019 11:08 am

Re: Macro with colors

Post by Alexandre » Thu May 28, 2020 7:28 am

The macro looks unchanged. Did you change anything?

Post Reply