Access worksheet names from Excel file with Google Apps Script (without Drive.Files.insert) - excel

In a Google App Script attached to a Google Sheet, I have the file ID of an excel file. I want to read the worksheet names of that excel file. The tutorials I've seen on conversion load the excel file as a blob then write it to Drive as a Google Sheet, then read it.
Is there a way to do this that does not to create artifacts that I then need to delete? The reasoning is that I am concerned with the following: safety if there's a bug (the wrong thing gets deleted), additional processing time (I need to process a long list of excel files), and leftover artifacts if the script aborts unexpectedly between inserting and deleting.
Thank you!

Answering your questions, the reason the tutorials first convert the Excel file to a Google Sheet is to interact with it (in your case, to gather the worksheet names) it's because the Google APIs or Apps Script cannot interact with the Excel file as row data, and Google needs to convert the file to something readable using Google APIs.
A workaround for this will be to use Excel JavaScript API to read the information original Excel file, you can use externals API in Apps Script since it's based in JavaScript, so you will use Apps Script as an IDE.
However, you can do the same with any other IDE that works with JavaScript.
There are some examples on how to list the worksheets using the Excel JavaScript API in this blog.
If you will like to keep using Google APIs, and using the Google Apps Script built-in services. You will need to convert the file to Google Sheets.
Updating Answer:
You can review more about the Excel Services API services here.

Related

Reading data from shared teams text file using VBA in Excel

I have created a tool using VBA that performs several pulls from BigQuery and does a variety of transformations and summarization inside of Excel. The tool is an evolving tool and to make sure that the users are using the most current version of the tool, I would like to have a version file saved on the shared Teams page that the tool would check and if needed, download the newest version onto the tool to the user's folder. I have scrubbed the web for several solutions to this ask but not one that actually works. Below are the links to the solutions I have attempted. The issue is that the connectors for opening text files seem to not work with a URL from Teams. I need to know how to make this work. Any help would be greatly appreciated.
https://www.excel-easy.com/vba/examples/read-data-from-text-file.html
This solution doesn't seem to work with a URL as I get a Bad Filename error.
https://chandoo.org/forum/threads/download-file-from-sharepoint-and-save-it-in-system-folder.41779/
Problem with this one is that the download for some reason shows completed but actually never moves local.
Connecting to Excel file stored on SharePoint via ADODB
https://www.connectionstrings.com/textfile/
I attempted to use this solution using the text file connection string but was not successful here either.
https://www.exceltip.com/import-and-export-in-vba/import-data-from-a-text-file-ado-using-vba-in-microsoft-excel.html
Again, another bad name error.
Any help or advice on how to connect to a simple text file shared in a Teams folder would be greatly appreciated.

Is it possible to fill in PDF forms through Google Script? Or add text on PDF through Google Script on the cloud?

Now basically all our jobs are deployed on Google Suites and triggered through Google Script, so what we want is that we can add this function - filling in the PDF forms - using Google Script as well.
Before what we are trying to do was to design a PDF-like template using Google Sheet and by looping, updating the blank information of the form, and finally saving the result as PDF, we will have the result that we want.
However in this time, the PDF is not that easy to imitate in Google Sheet. It is from the government and thus it is better to keep their format and simply fill in the PDF form.
Actually, we've tried to use the Excel VBA or Python on the hard drive to do and it is pretty simple task to finish. But the problem would be wasting time to switch between platforms and it is not a good solution to deploy everything on the Cloud.
So we are wondering if there is a way to 1) filling PDF forms through Google Script? 2) Or add text on PDF through Google Script on the cloud? 3) Or do it on the cloud in general?
Google Apps Script does not have a native way to programatically fill in an existing PDF.
You'll have to find some 3rd party service/API, or a JavaScript library, that lets you programatically fill in an existing PDF and then you can call it or use it in GAS.

Visual Studio Interface with MS Excel backend for Multiple Users to Run simultaneously

Until last month, I was creating Google WebApps with HTML interface, Java and Google Apps Script to let the users save data to Google Sheets.
That was working beautifully as all the users were able to save data to a single spreadsheet simultaneously without any data misses/issues.
This month onwards, I don't have the option to use Google Web Apps.
Therefore, I bought Visual Studio. Basically, I am trying to create an Interface using Visual Studio as I have some experience on Visual Basic codes, and then looking forward to save the data to MS Excel.
I have setup an FTP drive where I have saved a test .EXE file which saves their clipboard text to a single Rich Text File(I used the timer to save/read/refresh the file every few seconds). Since all the users have read/write/execute rights to that FTP folder, they are able to launch the .exe file simultaneouly from their systems and it's working perfectly. We are looking at a team of 100+ people.
Now the next step for me is to let them open the .EXE file where the data can be saved to a single Excel file. With Google Spreadsheets it was way too easy. But I need some guidance on how to do that with Microsoft. I studied through articles and articles to track the last updated row and push the data below that. I need tips from someone who has done something like this and if there's a better/efficient way of doing that.
Any help/article would be appreciated.

403 Forbidden on reading CSV file in OneDrive

I am trying to read my CSV files using Microsoft Graph API:
/me/drive/items/${someId}/workbook/worksheets('${someSheetName}')/usedRange
However it returns
403 Forbidden -> AccessDenied -> Could not get WAC token.
When reading a XLSX file, it works fine. I am using personal microsoft account.
Thanks for your help.
CSV and .xls are not supported formats. Only .xlsx works for this feature.
As others have pointed out, CSV files are not supported in the new Excel API. However, to help others who were initially confused by the error message like me, I'd like to elaborate a bit more.
First, it's useful to distinguish the Microsoft Graph API and the Excel API. The Microsoft Graph API mostly provides the basic functionalities of a file storage system so that third-party can work with files and folders in OneDrive and SharePoint. The Excel API, on the other hand, provides Excel functionalities so that third-parties can work with Excel files (.xlsx files specifically). Although the Excel API uses the same resource identification system and shares the same request "syntax" as the Microsoft Graph API, the two are not the same.
The request below clearly belongs to the Excel API, not the Graph API. Although the Graph API can handle CSV file (it doesn't care what type of file it's working with since it's application-agnostic), the Excel API can't.
/me/drive/items/${someId}/workbook/worksheets('${someSheetName}')/usedRange
If you look at the endpoints in the Excel API, you'll see that most of them point to features that do not exist in CSV files: workbook, worksheet, cells, etc. For instance, the request above attempts to read a specific worksheet within a workbook file, which is not possible if the file is CSV.
Also, the Excel API handles features such as formulas, data types, and cell formatting, which are also not present in CSV files.
Essentially, CSV files are no more than just plain-text files and thus are not supported by the Excel API.
Of course, it would be really helpful if the Excel API team could return a more meaningful error message. I personally find the current error message very misleading.

Running Excel automation locally or on server

Wanted some opinions on which method is a better practice. We have a sales report that MUST be generated in a very specific format (down to the row colors and fonts).
I already have written a macro which pulls from our database and populates the entire workbook in about 15 seconds. The question is how should it be populated?
1) Process server-side: Users initiate the request on the intranet page. ASP.NET opens the workbook template, executes the macro and serves back the final sheet.
2) Process locally: Users download the blank template, run from their desktops which automatically connect to the database.
I like the first one because I can enforce the template, timing, users, and security of the data. But is running Excel automation on an internet web server recommended? I like the second option, but I'm afraid of losing standardization as template sheets begin floating around the company.
As for server side:
I highly.. HIGHLY.. recommend checking out the OpenOffice/LibreOffice XML format for spread sheets.
You can use the localc binary in headless mode to convert the XML file to XLSX or what have you. I use it to create PDF files instead of using ReportLab.
Alternatively here are some other projects that attempt to write to Microsoft formats directly:
http://pypi.python.org/pypi/xlrd
http://pypi.python.org/pypi/xlwt
As for client side:
If you expect the user to be only using Excel and not any other spreadsheet software then go ahead and use an ODBC data source. ODBC will have to be configured per user unless you use some fun VBScript to pull the data from an HTTP server every time it is loaded. There is also the option of making an XLS spreadsheet that simply holds the data and including it into an XLS document as well which would be both a server and client XLS requirement.
Go for server side. Makes information simple to archive and share and will most likely be multi-platform as well.
If you like to use your first option, then you want to avoid using VBA on an installed instance of Excel on the server. This is extremely resource intensive and does not scale well. Instead, if you are writing ASP.NET code, then you should try using the Microsoft Office Interop functionality that is built into the .NET framework. It should possible to adapt your existing VBA code to run under ASP.NET with some changes, but you will have a much more reliable product in the end.
Example Code
However, as #whardier points out in his response, if this were for a large scale or public site, the suggestions he makes would be much more suitable and would scale much further.

Resources