如何在新的Google电子表格中将gid转换为od *(工作表ID) [英] How to convert from gid to od* (worksheet id) in new Google spreadsheets

查看:272
本文介绍了如何在新的Google电子表格中将gid转换为od *(工作表ID)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Gdata API更新Google电子表格单元格。
现在新的Google电子表格已经发布,看起来gid已经超过了8位数。

以下是示例新工作表,sheet2的gid是1794189920。
https://docs.google.com/电子表格/ d / 1S6mvGGoOJa8JF6Qt6GGH5QT-X0HD4EjZhKNbihAwFuE / edit?usp =共享



我试着用下面的方法转换它们,但是不起作用。 p>

如何将Google电子表格的工作表字符串ID转换为整数索引(GID)?

感谢任何能够帮助解决这个问题的人或建议。



干杯。 Junya

解决方案

好的,这是一个贫民区的答案,因为我根本不满意,因为我没有了解正在发生的事情,但也许它会帮助人们,所以在这里..



我使用的是ruby google_drive gem,只是试图下载我的所有工作表电子表格为CSV。为了做到这一点,我必须从编码的GID(我已经将其称为'WID')转换为真正的GID。之前,我的wid_to_gid方法看起来像这样(从堆栈溢出中的其他答案记录):

  def wid_to_gid(wid)
wid.to_i(36)^ 31578
end

为了处理7 -digit WIDs,我将它改为:

  def wid_to_gid(wid)
wid_val = wid.length> 3? wid [1 ..- 1]:wid
xorval = wid.length> 3? 474:31578
wid_val.to_i(36)^ xorval
end

..一些事情在这里..我意识到(至少在我的电子表格),对于7位数的WID,我可以通过删除第一个字符,转换为基数为36的数字,然后与474异或不知道为什么这个神奇的数字..对不起)。

如果WID只有3位数字,那么旧的转换工作(正如在堆栈上的许多其他答案中已经详细说明的那样溢出)。



对于我正在使用的电子表格,它有3张工作表。以下是每个WID和GID:

  GID  -  WID 
0 - od6
2019719111 - oxehkwt
1506531046 - oowy6v0

我真的只想完成这项工作,所以我没有花费更多的时间调查一次,我得到它的工作。如果其他人可以验证/拒绝这个代码是否适合他们......如果它不工作,或许它至少会给你一些想法!

I am using Gdata api to update Google spreadsheet cell. Now New Google spreadsheet has been released and it seems the gid has over 8 digits.

The following is sample new sheets and the gid of sheet2 is 1794189920. https://docs.google.com/spreadsheets/d/1S6mvGGoOJa8JF6Qt6GGH5QT-X0HD4EjZhKNbihAwFuE/edit?usp=sharing

I tried to convert them with the following method, but doesn't work.

How to convert Google spreadsheet's worksheet string id to integer index (GID)?

Thanks to anyone who can help shed light on this or suggest.

Cheers. Junya

解决方案

All right, this is a ghetto answer because I'm not satisfied with it at all since I don't really understand what's going on, but maybe it will help people, so here goes..

I'm using the ruby google_drive gem, just trying to download all the worksheets in my spreadsheet as CSV. In order to do this, I have to convert from the encoded GID (I've seen it called 'WID') to the real GID. Before, my wid_to_gid method looked like this (documented from other answers here on stack overflow):

def wid_to_gid(wid)
    wid.to_i(36) ^ 31578
end

In order to handle the 7-digit WIDs, I changed it to this:

def wid_to_gid(wid)
    wid_val = wid.length > 3 ? wid[1..-1] : wid
    xorval = wid.length > 3 ? 474 : 31578
    wid_val.to_i(36) ^ xorval
end

So.. a couple things going on here.. I realized that (at least on my spreadsheet), for the 7-digit WIDs, I could get the GID by dropping the first character, converting to base 36 number and then XORing with 474 (no idea why this magic number.. sorry).

If the WID is only 3 digits, then the old transform works (as has been detailed in many other answers on stack overflow).

For the spreadsheet I was working with, it had 3 worksheets. Here are the WIDs and GIDs of each:

GID - WID
0          - od6
2019719111 - oxehkwt
1506531046 - oowy6v0

I really just wanted to get this done so I didn't spend more time investigating once I got it to work. Would appreciate it if others can verify/reject this code as working or not for them... and if it doesn't work, maybe it will at least give you some ideas!

这篇关于如何在新的Google电子表格中将gid转换为od *(工作表ID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆