403 Forbidden on reading CSV file in OneDrive - excel

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.

Related

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

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.

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.

Azure Data Factory Excel read via HTTP fails

I am looking to import data form a publicly available Excel sheet into ADF. I have set up the dataset using an HTTP linked service (see first screenshot), with AutoResolveIntegrationRuntime. However, when I attempt to preview the data, I get an error suggestion that the source file is not in the correct format (second screenshot).
I'm wondering if I may have something set incorrectly in my configuration?
.xls format is not supported while using HTTP.
Since, the API downloads file you can't preview data. You can load file to blob or Azure Datalake Storage using copy activity and then on top of that file have a dataset to preview.
The workaround is to save your .xlsx file as a .csv file because Azure Data Factory does not support reading .xlsx files explicitly for HTTP connectors.
Furthermore, there is no need to convert the.xlsx file to.csv if you only want to copy it; simply select the Binary Copy option.
Here, is a similar discussion where the MS-FTE has confirmed with Product Team that's its not supported yet for HTTP Connector.
Please submit a proposal in the QnA thread to allow this functionality in future versions, which will be actively monitored by the data factory product team and evaluated for adoption.
Please check the issue at QnA Thread- Here.

Unable to connect to Excel file in OneDrive

I've been searching and searching but with no luck. Is there a way to use Excel VBA to import master file data from another excel workbook saved in OneDrive?
Thanks in advance.
A.) If you have an excel workbook that is stored locally on your PC but inside your OneDrive sync-ed folder.Then you can use following VBA code to approach one drive file. Once file is available there are many routines already on SO to import data.
Sub Test()
Dim fn As String
fn = "Your File " 'change file name
fn = Environ("onedrive") & "\" & fn
'check to see if it exists
If Len(fn) > 0 Then
Debug.Print fn
End If
'... do something.......
End Sub
B.) FETCH FILES If you have the OneDrive desktop app for Windows installed on a PC, you can use the Fetch files feature to access all your files on that PC from another computer by going to the OneDrive website. You can even access network locations if they're included in the PC's libraries or mapped as drives. When you browse a PC's files remotely, you can download copies of them to work on. You can also stream video and view photos in a slide show. To access files on your PC remotely, make sure the PC you want to access is turned on and connected to the Internet. OneDrive also needs to be running on that PC, and the Fetch files setting must be selected. For further Details please refer Fetch files on your PC
C.) FIle on ShareOint - VBA aopproach If your file is on SharePoint. OneDrive doesn't sync the shared files to the local and sync. In such case VBA code is available on SO VBA download a File from OneDrive by #Sid29
D.)REST APIs - Microsoft Graph Another situation is elaborated in the following paragraph which uses API.
The OneDrive REST API is a portion of the Microsoft Graph API which
allows your app to connect to content stored in OneDrive and
SharePoint. The REST API is shared between OneDrive, OneDrive for
Business, SharePoint document libraries, and Office Groups, to allow
your app the flexibility to read and store content in any of these
locations with the same code.
These REST APIs are a part of the Microsoft Graph, a common API for Microsoft services.
For existing solutions using OneDrive API outside of Microsoft Graph, or solutions targeting SharePoint Server 2016, see direct endpoint differences for more context on reading this documentation. OneDrive and SharePoint in Microsoft Graph
E.) It may be difficult to get url of specific online file of onedrive. Microsoft Community has covered a situation where they have suggested VBA code for downloading of a file without URL.It is report xlsx from a web application.
Because the URL isn't the path to the file, it's a 'file request link' it processes single sign on verification, then the download popup is displayed.
Though it depends on the web site , code mentioned in article executed successfully using IE browser. Code mentioned in this article can be experimented with. There is no other method to load online onedrive file through VBA in my knowledge.

Upload Excel 2013 Workbook to website hosted on Azure

Does anyone have guidance and/or example code (which would be awesome) on how I would go about the following?
With a Web application using C# / ASP.NET MVC and hosted on Azure:
Allow a user to upload an Excel Workbook (multiple worksheets) via a web page UI
Populate a Dataset by reading in the worksheets so I can then process the data
Couple of things I'm unclear on:
I've read that Azure doesn't have ACEOLEDB, which is what Excel 2007+ requires, and I'd have to use OPEN XML SDK. Is this true? Is this the only way?
Is it possible to read the file into memory and not actually save it to Azure storage?
I DO NOT need to modify the uploaded spreadsheet. Only read the data in and then throw the spreadsheet away.
Well that's many questions in one post, let me see if we can tackle them one by one
With a Web application using C# / ASP.NET MVC and hosted on Azure:
1.Allow a user to upload an Excel Workbook (multiple worksheets) via a web page UI
2.Populate a Dataset by reading in the worksheets so I can then process the data
Couple of things I'm unclear on:
1.I've read that Azure doesn't have ACEOLEDB, which is what Excel 2007+ requires, and I'd have to use OPEN XML SDK. Is this true? Is
this the only way?
2.Is it possible to read the file into memory and not actually save it to Azure storage?
1/2. You can allow a user to upload the excel workbook to some /temp location and once you have read you can choose to do the cleanup, you can also write a script which can do the cleanup of the files which couldn't get deleted from /temp for whatever reasons.
Alternatively if you want to keep the files, you should store them in Azure Stoarge, and fetch/read when you need to.
check out this thread read excelsheet in azure uploaded as a blob
By default when you upload a file it is wrote into local disk and one later chooses to save the files to azure storage or whatever places.
Reading the excel - you can use any of the nugget packages given here http://nugetmusthaves.com/Tag/Excel and read the excel file, I prefer Gembox and NPOI
http://www.aspdotnet-suresh.com/2014/12/how-to-upload-files-in-asp-net-mvc-razor.html

Resources