3
$\begingroup$

I am importing data from Excel and plotting it with DateListPlot. My code is

DateListPlot[{
  Join @@ Import[""][[1 ;;, 3 ;;]][[All, All, 2 ;; 3]], 
  Join @@ Import[""][[1 ;;, 3 ;;]][[All, All, 4 ;; 5]]}, 
  Joined -> True, 
  FrameTicks -> All]

But my problem is this works for just for the first sheet (year 2013) of the many in the same file. Sheet 2 is for Year 2012 and has the same format, and so forth. I want to get all the sheets for all the years; they are continuations of each other. Could you help me to figure out what code will do this?

$\endgroup$
2
  • 2
    $\begingroup$ offtop: 1;; = ;; = All $\endgroup$
    – Kuba
    Jun 21, 2013 at 10:42
  • $\begingroup$ @Kuba thanks can you see my coding skills?!!!! $\endgroup$
    – Alex
    Jun 21, 2013 at 10:47

1 Answer 1

3
$\begingroup$

This might work:

Import["test.xls", "Sheets"]

{Sheet1, Sheet2}

data1 = Import["test.xls", {"Sheets", "Sheet1"}];
data2 = Import["test.xls", {"Sheets", "Sheet2"}];
all = Sort[Join[data1, data2]];
DateListPlot[all, Joined -> True]

But I haven't got Excel here so I can't test it.

Edit

With lots of sheets:

sheets = Import["test.xls", "Sheets"]
data  =  Import["test.xls", {"Sheets", # }] & /@ sheets

and see how the data looks then.

$\endgroup$
7
  • $\begingroup$ thanks but what if I have 50 sheets?Please pay attention to my required format of [[1 ;;, 3 ;;]][[All, All, 2 ;; 3]], [[1 ;;, 3 ;;]][[All, All, 4 ;; 5]] $\endgroup$
    – Alex
    Jun 21, 2013 at 10:37
  • 1
    $\begingroup$ @Alex No idea what all that means... :) But once you've imported the data, just select the bits you want - that should be basic list-manipulation stuff. $\endgroup$
    – cormullion
    Jun 21, 2013 at 10:58
  • $\begingroup$ It fails to import data what could be wrong? $\endgroup$
    – Alex
    Jun 21, 2013 at 11:18
  • 1
    $\begingroup$ I'm sorry, I'm not a doctor... :/ $\endgroup$
    – cormullion
    Jun 21, 2013 at 11:28
  • $\begingroup$ I am recovered :D thanks $\endgroup$
    – Alex
    Jun 21, 2013 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.