英文:
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的基础知识,包括SpreadsheetApp、DriveApp和Advanced Drive Service的特定知识。
- 编写代码的步骤将包括:
- 一旦您创建了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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论