在普通糊剂中导入xlsx,并获取所有行和列
我创建了一个脚本,可以将XLSX文件导入Google Sheep及其当前工作,但我需要对其进行修改以获取整个表,而无需使用特定范围并将其粘贴为普通文本,因为当前的输出文本具有大胆和大字体,可以有人帮助我修改或更改脚本需要什么?
我的脚本
const sourceValues = sourceSheet.getRange("B1:V5231").getValues();
const target = SpreadsheetApp.openById(ID).getSheetByName('sheetname');
target.getRange(target.getLastRow()+1, 1, sourceValues.length, sourceValues[0].length).setValues(sourceValues);
谢谢你!
I created a script that can import xlsx file to google sheet and its currently working but I need to modify it to get the whole sheet without using specific range and paste it as normal text since the current output text has bold and large fonts, Can someone help me what I need to modify or change to my script?
My script
const sourceValues = sourceSheet.getRange("B1:V5231").getValues();
const target = SpreadsheetApp.openById(ID).getSheetByName('sheetname');
target.getRange(target.getLastRow()+1, 1, sourceValues.length, sourceValues[0].length).setValues(sourceValues);
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
建议
如果我清楚地了解了您的问题,您想动态地获取包含
.xlsx
数据的表上的范围,而不是使用getRange()
显式地使用特定范围方法。您可以尝试使用
getDatarange()
方法,因为它返回与表格上存在数据的尺寸相对应的范围。至于正常粘贴数据为文本而不格式化,您可以尝试使用
getDisPlayValues()
,而不是使用getValues()
,因为这将会将值返回为String
对象。[update]
如果
getDisPlayValues()
不删除文本格式,您也可以根据此 clearformats 方法“ https://stackoverflow.com/a/37010635/15384825"> extisting post 。此方法将清除内容和/或格式。请参阅下面的示例用法:脚本
参考:
SUGGESTION
If I have understood your question clearly, you want to dynamically get the range on your sheet that contains
.xlsx
data instead of explicitly using a specific range using thegetRange()
method.You may try using the
getDataRange()
method as it returns a range corresponding to the dimensions in which data is present on your sheet.As for the normal pasting of data as text without formatting, you can try using
getDisplayValues()
instead of using thegetValues()
as this will return the values asString
objects.[UPDATE]
If
getDisplayValues()
doesn't remove the text formatting, you can also use theclearFormats
method as per this existing post. This method will clear the contents and/or format. See this sample usage below:Script
References: