如何从用户读取Excel文件并生成Google表格文件 [英] How to read excel file from user and generating Google Sheet file
问题描述
我需要允许用户上传excel(xlsx)文件,然后使用Google脚本生成Google表格文件(生成的文件使用输入文件值,使用某些公式对其进行处理,并基于所有处理方式提供另一个excel文件作为输出)
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)
我目前正在一个简单的桌面应用程序中执行此任务(使用MS Excel等),但问题是我拥有管理员权限,我希望其他人在其PC上执行相同的操作,但他们没有管理员权限,所以请帮我解决这个问题,这是通过Google表格实现它的最佳方法是什么.我需要执行以下操作:
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:
- 从用户获取XLSX文件
- 使用Google工作表脚本阅读两列.
- 处理读取的值并创建一个包含6/7列的新的Google表格文件
请Plz帮助,因为我不是在寻找现成的代码,而是抢先一步,因为我以前从未使用过Google脚本.
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.
推荐答案
- 首先,您需要学习 Apps脚本和 SpreadsheetApp ,高级驱动器服务(具体而言).
- 编写代码的步骤是
- 在您的Google云端硬盘中检索excel文件
- 检索其 blob
- 创建mimeType
> GOOGLE_SHEETS
包含您的内容 - 创建Google Spreadsheet后,请使用SpreadsheetApp方法对其进行处理以删除备用内容/创建仅包含所需内容的副本.
- 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.
注意:在检索感兴趣的列之前,可能有道理将它们转换为Google表格,但这不是您可以做的使用Apps脚本或Google API,因为它们没有方法编辑Excel文件.
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.
这篇关于如何从用户读取Excel文件并生成Google表格文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!