在普通糊剂中导入xlsx,并获取所有行和列

发布于 2025-02-03 19:50:36 字数 423 浏览 4 评论 0原文

我创建了一个脚本,可以将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空宴 2025-02-10 19:50:36

建议

如果我清楚地了解了您的问题,您想动态地获取包含.xlsx数据的表上的范围,而不是使用getRange()显式地使用特定范围方法。

您可以尝试使用getDatarange()方法,因为它返回与表格上存在数据的尺寸相对应的范围。

至于正常粘贴数据为文本而不格式化,您可以尝试使用getDisPlayValues(),而不是使用getValues(),因为这将会将值返回为String对象。

[update]

如果getDisPlayValues()不删除文本格式,您也可以根据此 clearformats 方法“ https://stackoverflow.com/a/37010635/15384825"> extisting post 。此方法将清除内容和/或格式。请参阅下面的示例用法:

脚本

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);
target.clearFormats();

clearformats 方法将在设置值之后删除 target 工作表上的文本格式。

参考:

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 the getRange() 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 the getValues() as this will return the values as String objects.

[UPDATE]

If getDisplayValues() doesn't remove the text formatting, you can also use the clearFormats method as per this existing post. This method will clear the contents and/or format. See this sample usage below:

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);
target.clearFormats();

The clearFormats method will remove the formatting of the text on the target sheet after setting the values.

References:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文