当前位置:首页 > 未分类 > 正文内容

Color Codes for Google Spreadsheets

ceacer3周前 (05-02)未分类5954

This Google Script converts the currently active Google Spreadsheet into a square grid of randomly colored boxes using hexadecimal numbers. Credit 五味田和則

The random colors are generated using a JavaScript method - Math.ceil(Math.random()* 0xFFFFFF).toString(16)`. Also, since the value of the cell is the same as the color code, you can copy a cell to copy its color code.

function colorCodes() {
  var sheet = SpreadsheetApp.getActiveSheet();
  for (var i = 1; i <= 100; i++) {
    sheet.setRowHeight(i, 20);
    sheet.setColumnWidth(i, 20);
    for (var j = 1; j <= 100; j++) {
      var colorcode = Math.ceil(Math.random() * 0xffffff).toString(16);
      sheet
        .getRange(i, j)
        .setBackground("#" + colorcode)
        .setValue(color);
    }
  }
}

相关文章

How to Create Multiple Sub

How to Create Multiple Sub

A teacher would like to create separate Google Drive folders for each student in her class. Within e...

How to Mail Merge with Outlook and Google Sheets

How to Mail Merge with Outlook and Google Sheets

The Mail merge add-on for Gmail lets you send personalized emails to your contacts in bulk. You can...

How to Link Postal Addresses to Google Maps in Google Sheets

How to Link Postal Addresses to Google Maps in Google Sheets

Bob Canning writes: I have a Google Spreadsheet with postal addresses in column A. Each week, a real...

How to Sort Google Sheets Automatically with Apps Script

How to Sort Google Sheets Automatically with Apps Script

This Google Spreadsheet on Udemy courses has about 50 sheets, one for each programming language, and...

How to Use Conditional Logic in Google Documents

How to Use Conditional Logic in Google Documents

Conditional content allows you to customize your Google Docs template and generate different version...

How Teachers can Email Parents of Students from Google Forms

How Teachers can Email Parents of Students from Google Forms

A school provides email accounts for students that are enrolled in high school. The school has publ...