如何从用户那里读取Excel文件并生成Google表格文件。

huangapple go评论88阅读模式
英文:

How to read excel file from user and generating Google Sheet file

问题

我需要允许用户上传Excel(xlsx)文件,然后使用Google脚本生成Google Sheets文件(生成的文件使用输入文件的值,通过某些公式处理它们,并基于所有处理生成另一个Excel文件作为输出)。

我目前在一个简单的桌面应用程序中完成这个任务(使用MS Excel等),但问题是我有管理员权限,我希望其他人在他们的电脑上也能执行相同的操作,但他们没有管理员权限,所以请帮助我,通过Google Sheets,我可以实现最好的方式是什么。我需要以下操作:

  • 从用户那里获取XLSX文件
  • 使用Google表格脚本读取两列。
  • 处理读取的值,并创建一个包含6/7列的新Google Sheets文件。

请帮助我,因为我不是在寻找现成的代码,而是想要一个起步,因为我以前从未使用过Google脚本。

英文:

I need to allow user upload excel (xlsx) file and then generate a Google Sheets file using Google Scripts (the generated file uses the input file values, process them with certain formulas and provides another excel file as output based on all processing)

I am currently doing the task in a simple desktop application (using MS Excel etc.), but problem is I have admin rights and I want other people to do the same on their PCs but they dont have admin rights, so please help me with this, whats the best way I can implement it via Google Sheets. I need following to do:

  • Get an XLSX file from user
  • Read two columns using google sheet script.
  • Process the read values and create a new google sheet file with 6/7 columns

Plz help as I am not looking for a ready made code but a head start, as I have never worked with google scripts before.

答案1

得分: 1

  • 首先,您需要学习Apps Script的基础知识,包括SpreadsheetAppDriveAppAdvanced Drive Service的特定知识。
  • 编写代码的步骤将包括:
    • 获取您在Google Drive上的Excel文件
    • 获取其blob
    • 使用blob的内容创建一个新文件,其mimeType为GOOGLE_SHEETS
  • 一旦您创建了Google电子表格 - 使用SpreadsheetApp方法处理它,以删除不需要的内容/创建仅包含所需内容的副本。

在这里您可以找到有用的示例。

注意:在将它们转换为Google表格之前,先获取感兴趣的列可能是有道理的,但这不是您可以使用Apps Script或Google API执行的操作,因为它们没有编辑Excel文件的方法。

英文:
  • First you need to study the basics of Apps Script in general, and of the SpreadsheetApp, DriveApp and Advanced Drive Service in specific.
  • The steps to write your code would be
    • retrieving the excel file on your Google Drive
    • retrieving its blob
    • creating a new file of the mimeType GOOGLE_SHEETS with the contents of your blob
  • Once you create a Google Spreadsheet - process it with the SpreadsheetApp methods to delete spare contents/ create a copy with only the desired contents.

Here you can find useful samples.

> Note: It might make sense to retrieve the columns of interest before
> converting them to Google Sheets, but this is not something you can do
> with Apps Script or a Google API since they do not have methods to
> edit Excel files.

huangapple
  • 本文由 发表于 2020年1月3日 14:40:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574242.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定