Skip to content

Instantly share code, notes, and snippets.

@macx
Last active August 29, 2015 14:11
Show Gist options
  • Save macx/66ab8e82547c8470a636 to your computer and use it in GitHub Desktop.
Save macx/66ab8e82547c8470a636 to your computer and use it in GitHub Desktop.
Convert Google Spreadsheet gid to wid and vice versa (Base 36)
/**
* Base 36 convert Google Worksheet Id (wid)
* to Google Spreadsheet ID (gid)
*
* @param string wid [example: `od6` is equal sheet `0`]
* @return string [gid]
*/
function wid2gid(wid) {
return parseInt(String(wid), 36)^31578;
}
/**
* Base 36 convert Google Spreadsheet ID (gid)
* to Google Worksheet Id (wid)
*
* @param string gid [extract from url `gid=ID`]
* @return string [wid]
*/
function gid2wid(gid) {
return parseInt((gid^31578)).toString(36);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment