计算Google文档中的行数 [英] Counting the number of lines in Google Document

查看:117
本文介绍了计算Google文档中的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我希望能够统计Google文档中的行数。例如,脚本必须为以下文本返回6。





似乎没有任何东西可靠的方法从文本中提取'\ n'或'\r'字符。

  text.findText(/ \r / g)// OR 
text.findText(/ \\\
/ g)

第二行代码不应该起作用,因为根据GAS文档, '新行字符自动转换为/ r'

解决方案

正如你在评论中指出的那样,没有API可以检索Google文档中的行数。发生这种情况是因为文档是在客户端动态呈现的,所以服务器不知道这个数字。



一种可能的解决方案是挖取Google Doc的HTML,因为每行都用它自己的 div 与kix-lineview类相关联,但是您需要在iframe或无头浏览器中打开页面,然后滚动页面通过页面,使他们呈现,然后能够计数div


Problem:

I'd like to be able to count the number of lines in a Google Document. For example, the script must return 6 for the following text.

There doesn't seem to be any reliable method of extracting '\n' or '\r' characters from the text though.

text.findText(/\r/g)  //OR
text.findText(/\n/g)

The 2nd line of code is not supposed to work anyway, because according to GAS documentation, 'new line characters are automatically converted to /r'

解决方案

As you noted in the comments there is no API to do retrieve the number of lines in Google Docs. This happens because the document is rendered dynamically in the client side, so the server doesn't know this number.

One possible solution is scraping the HTML of the Google Doc, because each line is redered with it's own divwith the "kix-lineview" class, however you will need to actually open the page in an iframe or headless browser and then scroll page by page to make them render and then be able to count the divs

这篇关于计算Google文档中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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