1
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ 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"]. $\endgroup$ Mar 1, 2014 at 1:20
  • 2
    $\begingroup$ If the problem persists, try to evaluate Needs["JLink`"] before Importing. $\endgroup$ Mar 1, 2014 at 1:23
  • $\begingroup$ Another possible workaround is to include path into filename: Import[FileNameJoin[{"F:\\Mathematica Projects\\NIST x-ray attenuation data","Hydrogen Z1.xlsx"}]][[1]]. $\endgroup$ Mar 1, 2014 at 1:29
  • 1
    $\begingroup$ 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. $\endgroup$
    – Matt
    Mar 3, 2014 at 23:12

1 Answer 1

2
$\begingroup$

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

$\endgroup$

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.