Skip to content

Commit

Permalink
Support empty input data.
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenv committed Mar 14, 2013
1 parent 1fee883 commit 5c6c859
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class XlsxWriter
if @cellLabelMap[col]
colIndex = @cellLabelMap[col]
else
if col == 0
# Provide a fallback for empty spreadsheets
row = 1
col = 1

input = (+col - 1).toString(26)
while input.length
a = input.charCodeAt(input.length - 1)
Expand Down
2 changes: 2 additions & 0 deletions test/common.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ module.exports = (name, data) ->

it 'Should have header row', ->
assert(result.length >= 1, "Should have header row")
return if !data[0]

for key, index in _.keys(data[0])
assert.equal(result[0][index], key)

it 'Should contain right values', ->
assert.equal(result.length, data.length + 1)
return if !data[0]

for row, rowNr in result
continue if rowNr == 0 # Header
Expand Down
3 changes: 3 additions & 0 deletions test/dimensions_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ assert = require('assert')
describe 'Dimensions', ->
writer = new XlsxWriter('tmp.xslx')

it 'Calculates 0x0 dimensions', ->
assert.equal(writer.dimensions(0, 0), 'A1:A1')

it 'Calculates 1x1 dimensions', ->
assert.equal(writer.dimensions(1, 1), 'A1:A1')

Expand Down
4 changes: 4 additions & 0 deletions test/empty_test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test = require('./common')

test 'empty-test', [
]

0 comments on commit 5c6c859

Please sign in to comment.