Last active
August 29, 2015 14:11
-
-
Save macx/66ab8e82547c8470a636 to your computer and use it in GitHub Desktop.
Convert Google Spreadsheet gid to wid and vice versa (Base 36)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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