Skip to content

[AUTO] Format files using DocumentFormat #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Documenter, ExcelReaders

makedocs(modules = [ExcelReaders],
sitename = "ExcelReaders.jl",
analytics = "UA-132838790-1",
pages = [
makedocs(modules=[ExcelReaders],
sitename="ExcelReaders.jl",
analytics="UA-132838790-1",
pages=[
"Introduction" => "index.md"
])

deploydocs(repo = "github.com/queryverse/ExcelReaders.jl.git")
deploydocs(repo="github.com/queryverse/ExcelReaders.jl.git")
8 changes: 4 additions & 4 deletions src/ExcelReaders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using PyCall, DataValues, Dates

export openxl, readxl, readxlsheet, ExcelErrorCell, ExcelFile, readxlnames, readxlrange

const xlrd = PyNULL()
const xlrd = PyNULL()

include("package_documentation.jl")

Expand Down Expand Up @@ -90,7 +90,7 @@ function readxlsheet(file::ExcelFile, sheetname::AbstractString; args...)
end

# Function converts "relative" range like skip rows/cols and size of range to "absolute" from row/col to row/col
function convert_args_to_row_col(sheet;skipstartrows::Union{Int,Symbol} = :blanks, skipstartcols::Union{Int,Symbol} = :blanks, nrows::Union{Int,Symbol} = :all, ncols::Union{Int,Symbol} = :all)
function convert_args_to_row_col(sheet; skipstartrows::Union{Int,Symbol}=:blanks, skipstartcols::Union{Int,Symbol}=:blanks, nrows::Union{Int,Symbol}=:all, ncols::Union{Int,Symbol}=:all)
isa(skipstartrows, Symbol) && skipstartrows != :blanks && error("Only :blank or an integer is a valid argument for skipstartrows")
isa(skipstartrows, Int) && skipstartrows < 0 && error("Can't skip a negative number of rows")
isa(skipstartcols, Symbol) && skipstartcols != :blanks && error("Only :blank or an integer is a valid argument for skipstartcols")
Expand Down Expand Up @@ -178,7 +178,7 @@ function convert_ref_to_sheet_row_col(range::AbstractString)
endrow = parse(Int, m.captures[6])
endcol = colnum(m.captures[5])
end
if (startrow > endrow ) || (startcol > endcol)
if (startrow > endrow) || (startcol > endcol)
error("Please provide rectangular region from top left to bottom right corner")
end
return sheetname, startrow, startcol, endrow, endcol
Expand Down Expand Up @@ -234,7 +234,7 @@ function readxl_internal(file::ExcelFile, sheetname::AbstractString, startrow::I

for row in startrow:endrow
for col in startcol:endcol
data[row - startrow + 1, col - startcol + 1] = get_cell_value(ws, row, col, wb)
data[row-startrow+1, col-startcol+1] = get_cell_value(ws, row, col, wb)
end
end

Expand Down
144 changes: 72 additions & 72 deletions test/test_excelreaders.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testitem "ExcelReaders" begin
using Dates, PyCall, DataValues

# TODO Throw julia specific exceptions for these errors
# TODO Throw julia specific exceptions for these errors
@test_throws PyCall.PyError openxl("FileThatDoesNotExist.xls")
@test_throws PyCall.PyError openxl("runtests.jl")

Expand All @@ -10,104 +10,104 @@
@test file.filename == "TestData.xls"

buffer = IOBuffer()

@test sprint(show, file) == "ExcelFile <TestData.xls>"

for (k, v) in Dict(0 => "#NULL!", 7 => "#DIV/0!", 23 => "#REF!", 42 => "#N/A", 29 => "#NAME?", 36 => "#NUM!", 15 => "#VALUE!")
errorcell = ExcelErrorCell(k)
@test sprint(show, errorcell) == v
end

# Read into DataValueArray
# Read into DataValueArray
for f in [file, filename]
@test_throws ErrorException readxl(f, "Sheet1!C4:G3")
@test_throws ErrorException readxl(f, "Sheet1!G2:B5")
@test_throws ErrorException readxl(f, "Sheet1!G5:B2")

data = readxl(f, "Sheet1!C3:N7")
@test size(data) == (5, 12)
@test data[4,1] == 2.0
@test data[2,2] == "A"
@test data[2,3] == true
@test DataValues.isna(data[4,5])
@test data[2,9] == Date(2015, 3, 3)
@test data[3,9] == DateTime(2015, 2, 4, 10, 14)
@test data[4,9] == DateTime(1988, 4, 9, 0, 0)
@test data[5,9] == Time(15, 2, 0)
@test data[3,10] == DateTime(1950, 8, 9, 18, 40)
@test DataValues.isna(data[5,10])
@test isa(data[2,11], ExcelErrorCell)
@test isa(data[3,11], ExcelErrorCell)
@test isa(data[4,12], ExcelErrorCell)
@test DataValues.isna(data[5,12])

# Test readxlsheet function
@test data[4, 1] == 2.0
@test data[2, 2] == "A"
@test data[2, 3] == true
@test DataValues.isna(data[4, 5])
@test data[2, 9] == Date(2015, 3, 3)
@test data[3, 9] == DateTime(2015, 2, 4, 10, 14)
@test data[4, 9] == DateTime(1988, 4, 9, 0, 0)
@test data[5, 9] == Time(15, 2, 0)
@test data[3, 10] == DateTime(1950, 8, 9, 18, 40)
@test DataValues.isna(data[5, 10])
@test isa(data[2, 11], ExcelErrorCell)
@test isa(data[3, 11], ExcelErrorCell)
@test isa(data[4, 12], ExcelErrorCell)
@test DataValues.isna(data[5, 12])

# Test readxlsheet function
@test_throws ErrorException readxlsheet(f, "Empty Sheet")
for sheetinfo = ["Second Sheet", 2]
@test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows = -1)
@test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows = :nonsense)
@test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows=-1)
@test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows=:nonsense)

@test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols = -1)
@test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols = :nonsense)
@test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols=-1)
@test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols=:nonsense)

@test_throws ErrorException readxlsheet(f, sheetinfo, nrows = -1)
@test_throws ErrorException readxlsheet(f, sheetinfo, nrows = :nonsense)
@test_throws ErrorException readxlsheet(f, sheetinfo, nrows=-1)
@test_throws ErrorException readxlsheet(f, sheetinfo, nrows=:nonsense)

@test_throws ErrorException readxlsheet(f, sheetinfo, ncols = -1)
@test_throws ErrorException readxlsheet(f, sheetinfo, ncols = :nonsense)
@test_throws ErrorException readxlsheet(f, sheetinfo, ncols=-1)
@test_throws ErrorException readxlsheet(f, sheetinfo, ncols=:nonsense)

data = readxlsheet(f, sheetinfo)
@test size(data) == (6, 6)
@test data[2,1] == 1.
@test data[5,2] == "CCC"
@test data[3,3] == false
@test data[6,6] == Time(15, 2, 00)
@test DataValues.isna(data[4,3])
@test DataValues.isna(data[4,6])

data = readxlsheet(f, sheetinfo, skipstartrows = :blanks, skipstartcols = :blanks)
@test data[2, 1] == 1.
@test data[5, 2] == "CCC"
@test data[3, 3] == false
@test data[6, 6] == Time(15, 2, 00)
@test DataValues.isna(data[4, 3])
@test DataValues.isna(data[4, 6])

data = readxlsheet(f, sheetinfo, skipstartrows=:blanks, skipstartcols=:blanks)
@test size(data) == (6, 6)
@test data[2,1] == 1.
@test data[5,2] == "CCC"
@test data[3,3] == false
@test data[6,6] == Time(15, 2, 00)
@test DataValues.isna(data[4,3])
@test DataValues.isna(data[4,6])

data = readxlsheet(f, sheetinfo, skipstartrows = 0, skipstartcols = 0)
@test data[2, 1] == 1.
@test data[5, 2] == "CCC"
@test data[3, 3] == false
@test data[6, 6] == Time(15, 2, 00)
@test DataValues.isna(data[4, 3])
@test DataValues.isna(data[4, 6])

data = readxlsheet(f, sheetinfo, skipstartrows=0, skipstartcols=0)
@test size(data) == (6 + 7, 6 + 3)
@test data[2 + 7,1 + 3] == 1.
@test data[5 + 7,2 + 3] == "CCC"
@test data[3 + 7,3 + 3] == false
@test data[6 + 7,6 + 3] == Time(15, 2, 00)
@test DataValues.isna(data[4 + 7,3 + 3])
@test DataValues.isna(data[4 + 7,6 + 3])

data = readxlsheet(f, sheetinfo, skipstartrows = 0, )
@test data[2+7, 1+3] == 1.
@test data[5+7, 2+3] == "CCC"
@test data[3+7, 3+3] == false
@test data[6+7, 6+3] == Time(15, 2, 00)
@test DataValues.isna(data[4+7, 3+3])
@test DataValues.isna(data[4+7, 6+3])

data = readxlsheet(f, sheetinfo, skipstartrows=0,)
@test size(data) == (6 + 7, 6)
@test data[2 + 7,1] == 1.
@test data[5 + 7,2] == "CCC"
@test data[3 + 7,3] == false
@test data[6 + 7,6] == Time(15, 2, 00)
@test DataValues.isna(data[4 + 7,3])
@test DataValues.isna(data[4 + 7,6])

data = readxlsheet(f, sheetinfo, skipstartcols = 0)
@test data[2+7, 1] == 1.
@test data[5+7, 2] == "CCC"
@test data[3+7, 3] == false
@test data[6+7, 6] == Time(15, 2, 00)
@test DataValues.isna(data[4+7, 3])
@test DataValues.isna(data[4+7, 6])

data = readxlsheet(f, sheetinfo, skipstartcols=0)
@test size(data) == (6, 6 + 3)
@test data[2,1 + 3] == 1.
@test data[5,2 + 3] == "CCC"
@test data[3,3 + 3] == false
@test data[6,6 + 3] == Time(15, 2, 00)
@test DataValues.isna(data[4,3 + 3])
@test DataValues.isna(data[4,6 + 3])

data = readxlsheet(f, sheetinfo, skipstartrows = 1, skipstartcols = 1, nrows = 11, ncols = 7)
@test data[2, 1+3] == 1.
@test data[5, 2+3] == "CCC"
@test data[3, 3+3] == false
@test data[6, 6+3] == Time(15, 2, 00)
@test DataValues.isna(data[4, 3+3])
@test DataValues.isna(data[4, 6+3])

data = readxlsheet(f, sheetinfo, skipstartrows=1, skipstartcols=1, nrows=11, ncols=7)
@test size(data) == (11, 7)
@test data[2 + 6,1 + 2] == 1.
@test data[5 + 6,2 + 2] == "CCC"
@test data[3 + 6,3 + 2] == false
@test_throws BoundsError data[6 + 6,6 + 2] == Time(15, 2, 00)
@test DataValues.isna(data[4 + 6,2 + 2])
@test data[2+6, 1+2] == 1.
@test data[5+6, 2+2] == "CCC"
@test data[3+6, 3+2] == false
@test_throws BoundsError data[6+6, 6+2] == Time(15, 2, 00)
@test DataValues.isna(data[4+6, 2+2])
end
end

Expand Down