← Shop shelf

Make every Google Sheets copy at once

A small Google script turns the Excel files into real Google Sheets, fixes the picture column widths, shares each file, and lists the "make a copy" links. Paste that list here and every product's Teacher PDF gets its link.

  1. 1. Download the student files

    Unzip them, then in Google Drive make a folder named Pixel Art Excel Files and upload the .xlsx files into it. Use the Google account that owns your TPT files; school accounts often block public sharing.

  2. 2. Add the script (one time only)

    1. Go to script.google.com › New project.
    2. Delete what's there and paste the script below.
    3. In the left sidebar click + next to Services, pick Drive API, click Add.
    Script
    // Pixel Art -> Google Sheets converter
    // One-time setup: click "+" next to Services (left sidebar), pick "Drive API", click Add.
    // Then choose convertAll in the toolbar and click Run. Run it again until the log says "All done".
    
    const IN_FOLDER = "Pixel Art Excel Files";
    const OUT_FOLDER = "Pixel Art Google Sheets";
    const LINKS_FILE = "Pixel Art Links";
    const PIXEL_PX = 20;            // width of each mystery-picture column
    const TIME_BUDGET_MS = 4.5 * 60 * 1000; // Apps Script stops runs at 6 minutes
    
    function convertAll() {
      const start = Date.now();
      const src = folder_(IN_FOLDER);
      if (!src) throw new Error('Make a Drive folder named "' + IN_FOLDER + '" and put the .xlsx files in it.');
      const out = folder_(OUT_FOLDER) || DriveApp.createFolder(OUT_FOLDER);
    
      const done = {};
      const existing = out.getFilesByType(MimeType.GOOGLE_SHEETS);
      while (existing.hasNext()) { const f = existing.next(); done[f.getName()] = f.getId(); }
    
      let converted = 0, left = 0, shareFailed = 0;
      const files = src.getFiles();
      while (files.hasNext()) {
        const f = files.next();
        const name = f.getName();
        if (!/\.xlsx$/i.test(name) || /ANSWER_KEY/i.test(name)) continue;
        const base = name.replace(/\.xlsx$/i, "");
        if (done[base]) continue;
        if (Date.now() - start > TIME_BUDGET_MS) { left++; continue; }
    
        const copy = Drive.Files.copy({ mimeType: MimeType.GOOGLE_SHEETS }, f.getId());
        const file = DriveApp.getFileById(copy.id);
        file.setName(base);
        file.moveTo(out);
        fixWidths_(copy.id);
        try { file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW); } catch (e) { shareFailed++; }
        done[base] = copy.id;
        converted++;
      }
    
      writeLinks_(src, done);
      Logger.log("Converted " + converted + " file(s) this run.");
      if (shareFailed) Logger.log(shareFailed + " file(s) could not be shared publicly. School accounts often block this; use a personal Google account.");
      Logger.log(left ? left + " file(s) still to go. Click Run again." : 'All done! Open "' + LINKS_FILE + '" in the "' + IN_FOLDER + '" folder.');
    }
    
    /** Google's xlsx import drops some column widths, so set every picture column again. */
    function fixWidths_(id) {
      const ss = SpreadsheetApp.openById(id);
      ss.getSheets().forEach(function (sh) {
        const last = sh.getLastColumn();
        if (last < 10) return; // the "Start Here" tab
        sh.setColumnWidths(5, last - 4, PIXEL_PX);
        const extra = sh.getMaxColumns() - last;
        if (extra > 0) sh.deleteColumns(last + 1, extra);
      });
      SpreadsheetApp.flush();
    }
    
    function writeLinks_(src, done) {
      const found = src.getFilesByName(LINKS_FILE);
      const ss = found.hasNext() ? SpreadsheetApp.open(found.next()) : SpreadsheetApp.create(LINKS_FILE);
      DriveApp.getFileById(ss.getId()).moveTo(src);
      const sh = ss.getSheets()[0];
      const rows = Object.keys(done).sort().map(function (n) {
        return [n, "https://docs.google.com/spreadsheets/d/" + done[n] + "/copy"];
      });
      sh.clear();
      sh.getRange(1, 1, 1, 2).setValues([["File", "Copy link"]]).setFontWeight("bold");
      if (rows.length) sh.getRange(2, 1, rows.length, 2).setValues(rows);
      sh.autoResizeColumns(1, 2);
    }
    
    function folder_(name) {
      const it = DriveApp.getFoldersByName(name);
      return it.hasNext() ? it.next() : null;
    }
    
  3. 3. Run it

    Pick convertAll in the toolbar and click Run. The first time, Google asks for permission: choose your account, then Advanced › Go to (project name) › Allow. Each run converts for about 4½ minutes, so click Run again until the log says All done. Already-converted files are skipped. The Sheets land in Pixel Art Google Sheets.

  4. 4. Paste the links here

    Open Pixel Art Links (in your Pixel Art Excel Files folder), select columns A and B, copy, and paste below. You can do this after each theme; pasting again just updates the links.