Skip to content

Commit

Permalink
Merge pull request #17 from dhoegh/Conda_0.3
Browse files Browse the repository at this point in the history
Conda support 0.3
  • Loading branch information
davidanthoff committed Nov 11, 2015
2 parents f09fc99 + 9aa8368 commit b5b29a0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: python
python:
- 2.6 # This test the use of Conda.jl as PyCall require 2.7
- 2.7
- 3.3
compiler:
Expand Down
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Compat
DataArrays
DataFrames
Dates
PyCall
PyCall 1.1
Conda
28 changes: 23 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
environment:
matrix:
# Releases
- JULIAVERSION: "stable/win32"
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
PYTHONDIR: "C:\\Python34"
PYTHON: "C:\\Python34\\python.exe"

- JULIAVERSION: "stable/win64"
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
PYTHONDIR: "C:\\Python34-x64"
PYTHON: "C:\\Python34-x64\\python.exe"

- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
PYTHONDIR: "use_conda"
PYTHON: "use_conda"

- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
PYTHONDIR: "use_conda"
PYTHON: "use_conda"
# Nightlies
- JULIAVERSION: "download/win32"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
PYTHONDIR: "C:\\Python34"
PYTHON: "C:\\Python34\\python.exe"

- JULIAVERSION: "download/win64"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"
PYTHONDIR: "C:\\Python34-x64"
PYTHON: "C:\\Python34-x64\\python.exe"

- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
PYTHONDIR: "use_conda"
PYTHON: "use_conda"

- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"
PYTHONDIR: "use_conda"
PYTHON: "use_conda"

notifications:
- provider: Email
on_build_success: false
Expand All @@ -29,7 +45,9 @@ install:
# Install xlrd
- python -m pip install xlrd
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile($("http://status.julialang.org/"+$env:JULIAVERSION), "C:\projects\julia-binary.exe")
- ps: (new-object net.webclient).DownloadFile(
$("http://s3.amazonaws.com/"+$env:JULIAVERSION),
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
build_script:
Expand Down
43 changes: 33 additions & 10 deletions src/ExcelReaders.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@

module ExcelReaders

using Compat, PyCall, DataArrays, DataFrames
VERSION < v"0.4-" && using Dates

import Base.show
import Base.show, Conda

export openxl, readxl, readxlsheet, ExcelErrorCell

@pyimport xlrd
const xlrd = PyCall.PyNULL()

function __init__()
try
copy!(xlrd, pyimport("xlrd"))
catch e
if PyCall.conda
info("Installing xlrd via the Conda package...")
Conda.add("xlrd")
copy!(xlrd, pyimport("xlrd"))
else
error("""Failed to pyimport("xlrd"): ExcelReaders will not work until you have a functioning xlrd module.
For automated ExcelReaders installation, try configuring PyCall to use the Conda Python distribution within Julia. Relaunch Julia and run:
ENV["PYTHON"]=""
Pkg.build("PyCall")
using ExcelReaders
pyimport exception was: """, e)
end
end

end

type ExcelFile
workbook::PyObject
Expand All @@ -30,11 +53,11 @@ function show(io::IO, o::ExcelFile)
end

function show(io::IO, o::ExcelErrorCell)
print(io, xlrd.error_text_from_code[o.errorcode])
print(io, xlrd[:error_text_from_code][o.errorcode])
end

function openxl(filename::String)
wb = xlrd.open_workbook(filename)
wb = xlrd[:open_workbook](filename)
return ExcelFile(wb, basename(filename))
end

Expand Down Expand Up @@ -168,20 +191,20 @@ function readxl_internal(file::ExcelFile, sheetname::String, startrow::Int, star
data[row-startrow+1, col-startcol+1] = NA
else
celltype = ws[:cell_type](row-1,col-1)
if celltype == xlrd.XL_CELL_TEXT
if celltype == xlrd[:XL_CELL_TEXT]
data[row-startrow+1, col-startcol+1] = convert(String, cellval)
elseif celltype == xlrd.XL_CELL_NUMBER
elseif celltype == xlrd[:XL_CELL_NUMBER]
data[row-startrow+1, col-startcol+1] = convert(Float64, cellval)
elseif celltype == xlrd.XL_CELL_DATE
date_year,date_month,date_day,date_hour,date_minute,date_sec = xlrd.xldate_as_tuple(cellval, wb[:datemode])
elseif celltype == xlrd[:XL_CELL_DATE]
date_year,date_month,date_day,date_hour,date_minute,date_sec = xlrd[:xldate_as_tuple](cellval, wb[:datemode])
if date_month==0
data[row-startrow+1, col-startcol+1] = Time(date_hour, date_minute, date_sec)
else
data[row-startrow+1, col-startcol+1] = DateTime(date_year, date_month, date_day, date_hour, date_minute, date_sec)
end
elseif celltype == xlrd.XL_CELL_BOOLEAN
elseif celltype == xlrd[:XL_CELL_BOOLEAN]
data[row-startrow+1, col-startcol+1] = convert(Bool, cellval)
elseif celltype == xlrd.XL_CELL_ERROR
elseif celltype == xlrd[:XL_CELL_ERROR]
data[row-startrow+1, col-startcol+1] = ExcelErrorCell(cellval)
else
error("Unknown cell type")
Expand Down

0 comments on commit b5b29a0

Please sign in to comment.