Group Abstract Group Abstract

Message Boards Message Boards

0
|
11.5K Views
|
10 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Import data from an Excel file?

POSTED BY: MA Ghorbani
10 Replies

Thanks a lot, Neil.

POSTED BY: MA Ghorbani

The posted code works as long as your kernel is cleared. If the variables (ie Istanbul) are defined it will fail. One option is to handle that.

sheet = Import["data-2.xlsx", "Rules"];
Map[Remove, "Sheets" /. sheet]; MapThread[
 Set[Evaluate[Symbol[#1]], #2] &, {"Sheets" /. sheet, 
  "Data" /. sheet}]

By doing Remove, the symbol is erased so it can be used in the assignment.

Regards,

Neil

POSTED BY: Neil Singer

There is no file attached

POSTED BY: Neil Singer

Here is the file.

Thank you so much, Neil.

You helped me every time.

Attachments:
POSTED BY: MA Ghorbani
POSTED BY: Neil Singer

Dear Neil,

You are right. I have about 17 sheets in one excel file. I tried to apply your code for my data. Maybe I didn't get it right.

If possible, could you please perform your code for the attached data.xlsx file?

I appreciate your help and time.

POSTED BY: MA Ghorbani
POSTED BY: Neil Singer

Thanks a lot Neil.

I considered an excel file (the attached file) with two sheets named "Ukraine" and "Istanbul" . When I use the names of the sheets, I can not get the expected output.

In[12]:= Import["C:\\Users\\agri-ghorbani\\Desktop\\data.xlsx"][[1]]

Out[12]= {{51.3, 44.3}, {29.2, 102.8}, {76.9, 66.7}}

In[13]:= Import["C:\\Users\\agri-ghorbani\\Desktop\\data.xlsx"][[
  Ukraine]];

During evaluation of In[13]:= Part::pkspec1: The expression Ukraine cannot be used as a part specification.

In[14]:= Import["C:\\Users\\agri-ghorbani\\Desktop\\data.xlsx"][[2]]

Out[14]= {{45.2, 39.7, 38.9}, {79.8, 65.6, 65.4}, {109.8, 24.6, 35.4}}

In[15]:= Import["C:\\Users\\agri-ghorbani\\Desktop\\data.xlsx"][[
  Istanbul]];

During evaluation of In[15]:= Part::pkspec1: The expression Istanbul cannot be used as a part specification.
Attachments:
POSTED BY: MA Ghorbani
Posted 7 years ago

Try this-

Import["C:\\Users\\agri-ghorbani\\Desktop\\data.xlsx", {"Data","Ukraine"}]
POSTED BY: Girish Arabale

Thank you so much, Girish.

POSTED BY: MA Ghorbani
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard