Skip to content

Instantly share code, notes, and snippets.

@dfelton
Created February 18, 2022 22:56
Show Gist options
  • Save dfelton/bac3e0f44482ffad66368ba9ab1f8a4e to your computer and use it in GitHub Desktop.
Save dfelton/bac3e0f44482ffad66368ba9ab1f8a4e to your computer and use it in GitHub Desktop.
IMPORTRANGE() column generator of months of the years for Google Sheets
<?php
declare(strict_types=1);
$format = '"=IMPORTRANGE(""%s"",""%s!H1"")"';
$months = [
"JAN",
"FEB",
"MAR",
"APR",
"MAY",
"JUN",
"JUL",
"AUG",
"SEP",
"OCT",
"NOV",
"DEC",
];
$sheets = [
2031 => "foobar",
2032 => "fizzbuzz",
];
$content = '';
foreach ($sheets as $sheet) {
foreach ($months as $month) {
$content .= sprintf($format, $sheet, $month) . PHP_EOL;
}
}
file_put_contents('/tmp/results.csv', $content);
echo "Copy contents of '/tmp/results.csv' and paste into a Google Sheets cell the results." . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment