HELP SCRIPT RETIRER UN LIEN HYPERTEXTE

56 views
Skip to first unread message

CHARLIE BOUVIER

unread,
Oct 19, 2021, 4:59:52 AM10/19/21
to Google Apps Script Community
Bonjour à tous!

Je viens vers vous pour obtenir de l'aide. J'ai actuellement une extraction d'un fichier et j'aimerai savoir s'il était possible d'obtenir le lien brut d'une cellule avec un lien hypertexte?
Dans ma cellule, il y a le titre, ce n'est pas une formule du genre: =Hyperlink(xxxx)
Je n'ai que le titre souligné avec le lien quand je clique, j'aimerai un moyen d'obtenir dans une colonne juste le lien url brut contenu dans cette formule, des idées? 

Un grand merci :)

Emeric HOCHART

unread,
Oct 19, 2021, 6:48:41 AM10/19/21
to Google Apps Script Community
  
let ss = SpreadsheetApp.getActiveSpreadsheet();
  let ws = ss.getActiveSheet();
  let range = ws.getRange("A1");
  let value = range.getRichTextValue().getLinkUrl();

CHARLIE BOUVIER

unread,
Oct 19, 2021, 10:37:53 AM10/19/21
to Google Apps Script Community
Ca fonctionne parfaitement mais j'ai un problème de rapidité avec ce script (j'ai environ 12000 lignes à transformer):
function testlien() 
{
  let ss = SpreadsheetApp.getActiveSpreadsheet();
  let ws = ss.getActiveSheet();
  for(var i=2;i<12979;i++) 
{
  let range = ws.getRange(i,26);
  let value = range.getRichTextValue().getLinkUrl();
  ws.getRange(i,26).setValue(value);
  }
}

Y a-t-il une solution pour accélérer le script?
Je crois que d'aller chercher une valeur sur le serveur avec la fonction getrange prend un peu trop de temps :/

Message has been deleted

Emeric HOCHART

unread,
Oct 20, 2021, 12:53:04 AM10/20/21
to Google Apps Script Community
function testlien() 
{
  let ss = SpreadsheetApp.getActiveSpreadsheet();
  let ws = ss.getActiveSheet();
  let range = ws.getRange(2,26,12977,1);
  let values = range.getRichTextValues();
  let urls = [];
  for (var i = 0; i < values.length; i++) {
    for (var j = 0; j < values[i].length; j++) {
      urls.push([values[i][j].getLinkUrl()]);
    }
  }
  range.setValues(urls);
  
}

Il vaut mieux utiliser setValues et et getRichTextValues 1 seule fois .
En revanche pas de solution pour la méthode getLinkUrl, tu es obligé de parcourir ton array.
Je n'ai pas testé mais cela devrait accélérer

Emerson Maia

unread,
Oct 20, 2021, 3:49:28 AM10/20/21
to google-apps-sc...@googlegroups.com
Good morning, a way for you to do this and make a slice in your array, for example.
example 1:
const newarray = [...youroriginalarray]
.filter(valor => valor[0] !=== "" )
.slice(3,Number.MAX_VALUE)

const values = newarray .map((row) => [row[1]])
wsform.getRange(2, 1, values.length, values[0].length).setValues(values)

exemplo 2;

const value = ws.getRange(2,26).getValue()
.(slice(3,Number.MAX_VALUE)

    ws.getRange(5,5).setValue(value)

Obs: Something like that, to slice the slice and the following

(3, for the beginning of the slicing, Number.MAX_VALUE until the end but you can slice in different ways),

the first example, I get several links in the array and we put them all in your spreadsheet,
in the second one we just got a specific one.


it was just an example search for slice, sorry my english i live in brazil my english is not good, i hope i have helped. Have a nice day.




--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/0e16da5e-005a-492a-a504-9457ce157f42n%40googlegroups.com.

CHARLIE BOUVIER

unread,
Nov 24, 2021, 9:17:14 AM11/24/21
to Google Apps Script Community
Bonjour,

Un grand merci pour vos réponses, elles m'ont été très utiles! 

Reply all
Reply to author
Forward
0 new messages