Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The following function call fails when I invoke it in a fresh Mathematica session:

z1 = Import["Hydrogen Z1.xlsx", 
   Path -> "F:\\Mathematica Projects\\NIST x-ray attenuation data"][[1]]

The path exists and the Excel file exists in that path, but I get the following errors when I invoke the function:

Get::noopen: Cannot open JLink`. >>
Needs::nocont: Context JLink` was not created when Needs was evaluated. >>
Part::partd: Part specification Null[[1]] is longer than depth of object. >>
Part::partd: Part specification Null[[1]] is longer than depth of object. >>

The result returned is Null[1]

On the other hand, if I invoke the Import function to try to fetch data from a web page using the following command, I get no errors:

Import["http://physics.nist.gov/PhysRefData/XrayMassCoef/ElemTab/z56.html", "Data"]

Unfortunately, there are some problems with the way the data is formatted (which is why I downloaded the data into the Excel files in the first place). Strangely, after using Import to fetch data from the web, the original function call to Import to read the Excel files works just fine without error. This leads me to believe that the failure of the first command occurs because some package is needed but not loaded by default and Import is smart enough to load this package when fetching data from the web but not when attempting to read Excel file data locally. So, presumably a Needs statement is needed. What package do I need to load to make this work on the first try (if that is indeed the problem)? Or is the problem something else altogether?

share|improve this question
    
Is your problem reproducible? There is no such problem with example XLSX file in v.8.0.4: Import["cities.xlsx",Path->"C:\\Program Files\\Wolfram Research\\Mathematica\\8.0\\Documentation\\English\\System\\ExampleData"]. –  Alexey Popkov Mar 1 at 1:20
1  
If the problem persists, try to evaluate Needs["JLink`"] before Importing. –  Alexey Popkov Mar 1 at 1:23
    
Another possible workaround is to include path into filename: Import[FileNameJoin[{"F:\\Mathematica Projects\\NIST x-ray attenuation data","Hydrogen Z1.xlsx"}]][[1]]. –  Alexey Popkov Mar 1 at 1:29
1  
Alexey's comment to try Needs["JLink`"] before importing is also a valid answer that solves the problem. However, I accepted george2079's answer since it is what I would have done in the first place if I had known how to transform the web data into a useful format. –  Matt Mar 3 at 23:12
add comment

1 Answer 1

up vote 1 down vote accepted

Its not that hard to read the html directly..

d = Import["http://physics.nist.gov/PhysRefData/XrayMassCoef/ElemTab/z56.html",
    "Data"][[1]];
(heading = d[[;; 3]]) // MatrixForm
(datatable = 
     If[Length[#] == 3, {" "},
                   #[[1 ;; 1]]]~Join~#[[-3 ;;]] & /@ 
                    d[[4 ;;]]) // MatrixForm

enter image description here

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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