Skip to content

Commit

Permalink
Version 0.4.0
Browse files Browse the repository at this point in the history
### Added
- Method Sheet#last_column().
- Method Sheet#empty?().
- Several test assertions for new functionality.
- Using new xlsx_drone version (0.2.0).
  • Loading branch information
damian-m-g committed Jan 16, 2021
1 parent 7b83786 commit 2b811ec
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 20 deletions.
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.idea/
Gemfile.lock
ProgrammerNotes.md
*.gem
.yardoc/
coverage/
doc/
releases/
test/benchmark/*.xlsx
!test/benchmark/xlsx_200000_rows.xlsx
.yardoc/
coverage/
doc/
Gemfile.lock
ProgrammerNotes.md
*.gem
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ Removed, Fixed, Security, and others; and this project adheres to [Semantic Vers

## [Unreleased]

## [0.4.0] - 2021-01-16
### Added
- Method Sheet#last_column().
- Method Sheet#empty?().
- Several test assertions for new functionality.
- Using new xlsx_drone version (0.2.0).

## [0.3.0] - 2021-01-12
### Added
- A benchmark comparison against other xlsx reading libraries.
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Fast _Microsoft Excel's_ **\*.xlsx** reader. Binding of [C's xlsx_drone](https:/
* [Usage](#usage)
* [API](#api)
* [TODO](#todo)
* [News](#news)
* [License](#license)

## Summary
Expand Down Expand Up @@ -47,8 +48,9 @@ sheet = wb.load_sheet(1) #: XLSXDrone::Sheet
puts "Sheet #1 name: #{sheet.name}"

1.upto(sheet.last_row) do |row|
p sheet.read_cell(row, 'A')
p sheet.read_cell(row, 'B')
'A'.upto(sheet.last_column) do |column|
p sheet.read_cell(row, column)
end
end
```

Expand All @@ -67,6 +69,12 @@ Also, consider that this TODO list is somehow concatenated to the [C's xlsx_dron

**Be free to [make (or upvote)](https://github.com/damian-m-g/xlsx_drone_rb/issues) any feature request.**

## News

Version 0.4.0 introduces:
* `Sheet#last_column`
* `Sheet#empty?`

## License

#### [MIT](https://github.com/damian-m-g/xlsx_drone_rb/blob/master/LICENSE)
2 changes: 1 addition & 1 deletion data/shields/assertions.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"schemaVersion":1,"label":"test assertions","message":"112","color":"informational"}
{"schemaVersion":1,"label":"test assertions","message":"120","color":"informational"}
2 changes: 1 addition & 1 deletion data/shields/simplecov.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"schemaVersion":1,"label":"coverage","message":"90.15%","color":"brightgreen"}
{"schemaVersion":1,"label":"coverage","message":"90.84%","color":"brightgreen"}
Binary file modified ext/xlsx_drone_x64.dll
Binary file not shown.
Binary file modified ext/xlsx_drone_x86.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions lib/xlsx_drone/native_binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class XLSXSheetT < FFI::Struct
:sheet_xml, :pointer,
:sheetdata, :pointer,
:last_row, :int,
:last_column, :pointer,
:last_row_looked, XLSXReferenceToRowT
end

Expand Down Expand Up @@ -70,6 +71,7 @@ class XLSXCellT < FFI::Struct
attach_function :xlsx_set_print_err_messages, [:int], :void
attach_function :xlsx_open, [:string, :pointer], :int
attach_function :xlsx_load_sheet, [:pointer, :int, :string], :pointer
attach_function :xlsx_get_last_column, [:pointer], :pointer
attach_function :xlsx_read_cell, [:pointer, :uint, :string, :pointer], :void
attach_function :xlsx_close, [:pointer], :int
end
Expand Down
22 changes: 21 additions & 1 deletion lib/xlsx_drone/sheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module XLSXDrone

# XLSX Sheet.
class Sheet

# @return [XLSXDrone::Sheet]
def initialize(xlsx_sheet_mpointer)
@native_sheet = XLSXDrone::NativeBinding::XLSXSheetT.new(xlsx_sheet_mpointer)
Expand All @@ -16,6 +16,26 @@ def last_row
@native_sheet[:last_row]
end

# @return [String] "A" if the sheet is empty
def last_column
if(!@last_column)
mpointer = XLSXDrone::NativeBinding.xlsx_get_last_column(@native_sheet) # NULL or a string
if(mpointer.null?)
# the sheet is empty
@last_column = 'A'
else
@last_column = mpointer.get_string(0).force_encoding(Encoding::UTF_8)
end
else
@last_column
end
end

# @return [Boolean]
def empty?
last_row() == 0 ? true : false
end

# @return [String]
def name
@native_sheet[:name].get_string(0).force_encoding(Encoding::UTF_8)
Expand Down
Binary file added test/helper/empty_sample.xlsx
Binary file not shown.
File renamed without changes.
46 changes: 40 additions & 6 deletions test/tc_sheet.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,58 @@
class TCSheet < Test::Unit::TestCase

XLSX_PATH = "#{File.dirname(__FILE__)}/helper/foo.xlsx"
TEST_FOLDER_ABSOLUTE_PATH = File.dirname(__FILE__)
XLSX_PATH = "#{TEST_FOLDER_ABSOLUTE_PATH}/helper/sample.xlsx"
EMPTY_XLSX_PATH = "#{TEST_FOLDER_ABSOLUTE_PATH}/helper/empty_sample.xlsx"

def setup
@workbook = XLSXDrone.open(XLSX_PATH)
@sheet = @workbook.load_sheet(1)
end

def teardown
@workbook.close()
end

def test_last_row
assert_equal(23, @sheet.last_row)
end

def test_last_column
assert_equal("L", @sheet.last_column)
# if called a second time, must return the same
assert_equal("L", @sheet.last_column)

# this sheet has its last column filled in "B", but has styles manually defined at the right
sheet = @workbook.load_sheet(2)
assert_equal("B", sheet.last_column)

workbook = XLSXDrone.open(EMPTY_XLSX_PATH)
sheet = workbook.load_sheet(1)
assert_equal("A", sheet.last_column)
# second sheet is also empty but has some styles manually defined
sheet = workbook.load_sheet(2)
assert_equal("A", sheet.last_column)

workbook.close()
end

def test_empty?
assert_equal(false, @sheet.empty?)

workbook = XLSXDrone.open(EMPTY_XLSX_PATH)
sheet = workbook.load_sheet(1)
assert_equal(true, sheet.empty?)
# second sheet is also empty but has some styles manually defined
sheet = workbook.load_sheet(2)
assert_equal(true, sheet.empty?)

workbook.close()
end

def test_name
assert_equal('Sheet1', @sheet.name)
end

def test_read_cell
# headers
assert_equal("General", @sheet.read_cell(1, "A"))
Expand Down Expand Up @@ -144,8 +182,4 @@ def test_read_cell
assert_equal(nil, @sheet.read_cell(13, "D"))
assert_equal(nil, @sheet.read_cell(50, "A"))
end

def teardown
@workbook.close()
end
end
2 changes: 1 addition & 1 deletion test/tc_workbook.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class TCWorkbook < Test::Unit::TestCase

XLSX_PATH = "#{File.dirname(__FILE__)}/helper/foo.xlsx"
XLSX_PATH = "#{File.dirname(__FILE__)}/helper/sample.xlsx"

def setup
@workbook = XLSXDrone.open(XLSX_PATH)
Expand Down
2 changes: 1 addition & 1 deletion test/tc_xlsx_drone.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class TCXLSXDrone < Test::Unit::TestCase

XLSX_PATH = "#{File.dirname(__FILE__)}/helper/foo.xlsx"
XLSX_PATH = "#{File.dirname(__FILE__)}/helper/sample.xlsx"

def test_open
assert_raise(XLSXDrone::LogicError::ClientError::MalformedParams) {XLSXDrone.open(123)}
Expand Down
2 changes: 1 addition & 1 deletion xlsx_drone.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "xlsx_drone"
s.version = "0.3.0"
s.version = "0.4.0"
s.summary = "Fast Microsoft Excel's XLSX reader. Binding of C's xlsx_drone lib."
s.author = "Damián M. González"
s.homepage = "https://github.com/damian-m-g/xlsx_drone_rb"
Expand Down

0 comments on commit 2b811ec

Please sign in to comment.