Message Boards Message Boards

0
|
9060 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Import .xlsx file from Wolfram Cloud into Mathematica Desktop

Posted 5 years ago

Hi, This seems like a very basic Mathematica question, but Is there a way to directly read Excel data into Mathematica desktop when the .xlsx file is uploaded into Wolfram Cloud? I can import the data easily in Mathematica Online using Import function but how can I get desktop Mathematica to retrieve the data from the cloud?

So I'm looking to replace this with some sort of absolute path version pointing to .xlsx stored in Wolfram Cloud:

Import["Imports/data.xlsx",{"Data",1}];
POSTED BY: Marko Rossi
4 Replies

I think you can simply refer to the file as a CloudObject?

E.g.

Import[ CloudObject["Imports/data.xlsx"], {"Data",1}];

(you will need to be connected to the Wolfram Cloud from the desktop and you will need to have permissions to this cloud object, but that should be automatic if you are the owner of the file)

POSTED BY: Arnoud Buzing
Posted 5 years ago

Thanks, that got me halfway there, somehow Import with CloudObject didn't automatically recognize .xlsx files:

Import["Imports/data.xlsx", {"Data", 1}]

Import::noelem: The Import element "Data" is not present when importing as ZIP.

Import[CloudObject["Imports/data.xlsx"]]

{"[ContentTypes].xml", "rels\.rels", \ "xl\_rels\workbook.xml.rels", "xl\workbook.xml", \ "xl\sharedStrings.xml", "xl\theme\theme1.xml", "xl\styles.xml", \ "xl\worksheets\sheet1.xml", "docProps\core.xml", \ "docProps\app.xml"}

With this modification I got it work:

Import[CloudObject["Imports/data.xlsx"], {"xlsx", "Data", 1} ]

Thanks for your help :)

POSTED BY: Marko Rossi

Great!

I think the message with "ZIP" is a (small) bug or limitation. The Wolfram Language downloads your XLSX file to a temporary local file and then tries to heuristically determine what sort of file it is. However this temporary local file does not have the .xlsx extension and the FileFormat function which tries to determine the type of file then thinks it is a ZIP file (which it might actually be, I am not sure).

You can see this by running Trace on the import and evaluating the specific FileFormat command:

 heldexpression = Block[{DeleteFile = Identity},
    Trace[
     Import[CloudObject["cities.xlsx"], {"Data", 1}],
     FileFormat[___]]] // Flatten // First

This outputs something like this:

FileFormat["C:\\Users\\arnoudb.WRI\\AppData\\Local\\Temp\\m-55e25b16-9220-4769-8791-6e8e2b8a4d19"]

And then if you use ReleaseHold to remove the HoldForm wrapper, you get:

heldexpression // ReleaseHold

Which returns "ZIP".

POSTED BY: Arnoud Buzing

However this temporary local file does not have the .xlsx extension and the FileFormat function which tries to determine the type of file then thinks it is a ZIP file (which it might actually be, I am not sure).

It looks like XLSX files are indeed just zip files:

In[21]:= CopyFile[FindFile["ExampleData/cities.xlsx"], "test.zip"]

Out[21]= "H:\\Documents\\test.zip"

In[22]:= ExtractArchive["test.zip", "unzipped"]

Out[22]= {
    "unzipped\\[Content_Types].xml",
    "unzipped\\docProps\\app.xml",
    "unzipped\\docProps\\core.xml",
    "unzipped\\_rels\\.rels",
    "unzipped\\xl\\drawings\\drawing1.xml",
    "unzipped\\xl\\drawings\\_rels\\drawing1.xml.rels",
    "unzipped\\xl\\media\\image1.png",
    "unzipped\\xl\\_rels\\workbook.xml.rels",
    "unzipped\\xl\\sharedStrings.xml",
    "unzipped\\xl\\styles.xml",
    "unzipped\\xl\\workbook.xml",
    "unzipped\\xl\\worksheets\\_rels\\sheet2.xml.rels",
    "unzipped\\xl\\worksheets\\sheet1.xml",
    "unzipped\\xl\\worksheets\\sheet2.xml"
}
POSTED BY: Richard Hennigan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract