如何修复损坏的导入在线excel在谷歌表?



我需要这个在线excel:https://members.tsetmc.com/tsev2/excel/MarketWatchPlus.aspx?d=0

在我的谷歌表,但当我使用Importdata公式如下:Importdata("https://members.tsetmc.com/tsev2/excel/MarketWatchPlus.aspx?d=0"

的导入方式被破坏了,像这样:输入图片描述

,但原始在线文件是这样的:输入图片描述

我该如何修复它?

我相信你的目标如下。

  • 您希望将从URL下载的XLSX数据中的值放到Google Spreadsheet的活动表单中。

问题和解决方法:

在现阶段,Google Spreadsheet的内置函数中似乎没有直接从URL的XLSX数据中检索数据的方法。所以在这个答案中,我想建议使用Google Apps Script来实现你的目标。当使用Google Apps Script时,您的目标可以实现。

示例脚本的流程如下:

  1. 检索XLSX数据
  2. 将XLSX数据转换为Google电子表格作为临时电子表格。
  3. 从转换后的电子表格中检索值
  4. 将转换后的电子表格中的值放到活动表格中。
  5. 删除临时电子表格。

示例脚本:

请将以下脚本复制粘贴到Google电子表格的脚本编辑器中。在使用此脚本之前,请在高级谷歌服务中启用驱动器API。请在脚本编辑器中运行myFunction的功能。通过这种方式,XLSX数据的值被放到活动工作表中。

function myFunction() {
// 1. Retrieve XLSX data.
const url = "https://members.tsetmc.com/tsev2/excel/MarketWatchPlus.aspx?d=0"; // This is your URL.
const blob = UrlFetchApp.fetch(url).getBlob();
// 2. Convert XLSX data to Google Spreadsheet as the temporal Spreadsheet.
const id = Drive.Files.insert({title: "temp", mimeType: MimeType.GOOGLE_SHEETS}, blob).id;
// 3. Retrieve values from the converted Spreadsheet.
const values = SpreadsheetApp.openById(id).getSheets()[0].getDataRange().getValues();
// 4. Put the values from the converted Spreadsheet to the active sheet.
const dstSheet = SpreadsheetApp.getActiveSheet();
dstSheet.getRange(1, 1, values.length, values[0].length).setValues(values);
// 5. Remove the temporal Spreadsheet.
DriveApp.getFileById(id).setTrashed(true);
}
  • 如果您想把数值放到特定的表和范围,请修改4. Put the values from the converted Spreadsheet to the active sheet.的脚本。

引用:

  • 文件:插入
  • getvalue ()
  • setvalue(值)

最新更新