From a0c35899700ea0a4b5bdc20d63d4182cd3bdd06d Mon Sep 17 00:00:00 2001 From: zensey Date: Thu, 5 May 2016 16:32:10 +0300 Subject: [PATCH 1/6] Add DateTime format. see formatAsDateTime attribute in addRow method --- src/blobs.coffee | 7 ++++++- src/index.litcoffee | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/blobs.coffee b/src/blobs.coffee index fc129c4..61030eb 100644 --- a/src/blobs.coffee +++ b/src/blobs.coffee @@ -81,7 +81,8 @@ module.exports = - + + @@ -93,6 +94,9 @@ module.exports = + + + """.replace(/\n\s*/g, '') @@ -137,6 +141,7 @@ module.exports = cell: (index, cell) -> """#{index}""" dateCell: (value, cell) -> """#{value}""" + dateTimeCell: (value, cell) -> """#{value}""" numberCell: (value, cell) -> """#{value}""" sheetDataHeader: """""" diff --git a/src/index.litcoffee b/src/index.litcoffee index 5073fbc..600c0f1 100644 --- a/src/index.litcoffee +++ b/src/index.litcoffee @@ -93,6 +93,7 @@ Add a single row. # "A String Column" : "A String Value", # "A Number Column" : 12345, # "A Date Column" : new Date(1999,11,31) + # "A DateTime Column": {value: new Date(), formatAsDateTime: true}, # }) addRow: (row) -> @@ -261,6 +262,11 @@ Adds a cell to the row in progress. # Hyperlink support if Object.prototype.toString.call(value) == '[object Object]' + if value.formatAsDateTime + date = @_dateToOADate(value.value) + @rowBuffer += blobs.dateTimeCell(date, cell) + return + if !value.value || !value.hyperlink throw new Error("A hyperlink cell must have both 'value' and 'hyperlink' keys.") @_addCell(value.value, col) From 78ac54dc96799a3f3749b6a65c8df5152cea8a89 Mon Sep 17 00:00:00 2001 From: Zensey Date: Thu, 5 May 2016 16:32:10 +0300 Subject: [PATCH 2/6] Add DateTime format. see formatAsDateTime attribute in addRow method --- README.md | 1 + src/blobs.coffee | 7 ++++++- src/index.litcoffee | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99a3c3d..43a24b3 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,7 @@ by enclosing it within an object with the keys `value, hyperlink`. "A String Column" : "A String Value", "A Number Column" : 12345, "A Date Column" : new Date(1999,11,31) + "A DateTime Column": {value: new Date(), formatAsDateTime: true}, "A String column with a hyperlink" : {value: "A String Value", hyperlink: "http://www.google.com"} "A Number column with a hyperlink" : {value: 12345, hyperlink: "http://www.google.com"} "A Date column with a hyperlink" : {value: new Date(1999,11,31), hyperlink: "http://www.google.com"} diff --git a/src/blobs.coffee b/src/blobs.coffee index fc129c4..61030eb 100644 --- a/src/blobs.coffee +++ b/src/blobs.coffee @@ -81,7 +81,8 @@ module.exports = - + + @@ -93,6 +94,9 @@ module.exports = + + + """.replace(/\n\s*/g, '') @@ -137,6 +141,7 @@ module.exports = cell: (index, cell) -> """#{index}""" dateCell: (value, cell) -> """#{value}""" + dateTimeCell: (value, cell) -> """#{value}""" numberCell: (value, cell) -> """#{value}""" sheetDataHeader: """""" diff --git a/src/index.litcoffee b/src/index.litcoffee index 5073fbc..600c0f1 100644 --- a/src/index.litcoffee +++ b/src/index.litcoffee @@ -93,6 +93,7 @@ Add a single row. # "A String Column" : "A String Value", # "A Number Column" : 12345, # "A Date Column" : new Date(1999,11,31) + # "A DateTime Column": {value: new Date(), formatAsDateTime: true}, # }) addRow: (row) -> @@ -261,6 +262,11 @@ Adds a cell to the row in progress. # Hyperlink support if Object.prototype.toString.call(value) == '[object Object]' + if value.formatAsDateTime + date = @_dateToOADate(value.value) + @rowBuffer += blobs.dateTimeCell(date, cell) + return + if !value.value || !value.hyperlink throw new Error("A hyperlink cell must have both 'value' and 'hyperlink' keys.") @_addCell(value.value, col) From adc95133a65aef0e861c682ecebd28c99ff50ba3 Mon Sep 17 00:00:00 2001 From: Zensey Date: Wed, 11 May 2016 14:53:18 +0300 Subject: [PATCH 3/6] Add new method: _addSheetDataHeader --- lib/index.js | 7 +++++++ src/index.litcoffee | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/index.js b/lib/index.js index c25b528..6db336a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -45,6 +45,13 @@ module.exports = XlsxWriter = (function() { }); } + XlsxWriter.prototype._addSheetDataHeader = function() { + if (!this.haveHeader) { + this._write(blobs.sheetDataHeader); + return this.haveHeader = true; + } + }; + XlsxWriter.prototype.addRow = function(row) { var col, key, _i, _len, _ref; if (!this.haveHeader) { diff --git a/src/index.litcoffee b/src/index.litcoffee index 600c0f1..07504ca 100644 --- a/src/index.litcoffee +++ b/src/index.litcoffee @@ -79,6 +79,23 @@ When constructing a writer, pass it an optional file path and customization opti # Hook this passthrough into the zip stream. @zip.append(@sheetStream, {name: 'xl/worksheets/sheet1.xml'}) +#### Add SheetDataHeader + +Simply add known header to resulting stream. +Should be used in conjunction with low-level api: _startRow, _addCell, endRow + +##### _addSheetDataHeader: () + +Add SheetDataHeader to resulting stream. + + # @example (javascript) + # writer._addSheetDataHeader() + _addSheetDataHeader: () -> + if !@haveHeader + @_write(blobs.sheetDataHeader) + @haveHeader = true + + #### Adding rows Rows are easy to add one by one or all at once. Data types within the sheet will @@ -116,6 +133,8 @@ Add a single row. @_addCell(row[key] || "", col + 1) @_endRow() + + ##### addRows(rows: Array) Rows can be added in batch. From aab29c6d6cd52138a0c4713d60d5100ad6d1a1fb Mon Sep 17 00:00:00 2001 From: Zensey Date: Tue, 14 Jun 2016 10:27:40 +0300 Subject: [PATCH 4/6] Fix number format in order to parse correctly in MS Office --- lib/blobs.js | 2 +- src/blobs.coffee | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/blobs.js b/lib/blobs.js index 56bbbcf..fb27a69 100644 --- a/lib/blobs.js +++ b/lib/blobs.js @@ -3,7 +3,7 @@ module.exports = { rels: "\n\n \n".replace(/\n\s*/g, ''), workbook: "\n\n \n \n \n \n \n \n \n \n \n".replace(/\n\s*/g, ''), workbookRels: "\n\n \n \n \n".replace(/\n\s*/g, ''), - styles: "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n".replace(/\n\s*/g, ''), + styles: "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n".replace(/\n\s*/g, ''), stringsHeader: function(count) { return ("\n").replace(/\n\s*/g, ''); }, diff --git a/src/blobs.coffee b/src/blobs.coffee index 61030eb..9070fb1 100644 --- a/src/blobs.coffee +++ b/src/blobs.coffee @@ -50,6 +50,9 @@ module.exports = styles: """ + + + @@ -94,9 +97,6 @@ module.exports = - - - """.replace(/\n\s*/g, '') From f2105900f79a3fbd3ab3caad6bf64cc7246f96e7 Mon Sep 17 00:00:00 2001 From: Zensey Date: Thu, 15 Dec 2016 14:44:04 +0300 Subject: [PATCH 5/6] add argument ht (row height) to startRow() --- lib/blobs.js | 11 +++++++++-- lib/index.js | 4 ++-- src/blobs.coffee | 10 +++++++++- src/index.litcoffee | 4 ++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/blobs.js b/lib/blobs.js index fb27a69..6e39968 100644 --- a/lib/blobs.js +++ b/lib/blobs.js @@ -17,8 +17,15 @@ module.exports = { return ""; }, endColumns: "", - startRow: function(row) { - return ""; + startRow: function(row, ht) { + var out; + out = " 0) { + out += " customHeight=\"true\" ht=\"" + ht + "\" "; + } + out += ">"; + console.log(out); + return out; }, endRow: "", cell: function(index, cell) { diff --git a/lib/index.js b/lib/index.js index 6db336a..ffe1743 100644 --- a/lib/index.js +++ b/lib/index.js @@ -178,8 +178,8 @@ module.exports = XlsxWriter = (function() { } }; - XlsxWriter.prototype._startRow = function() { - this.rowBuffer = blobs.startRow(this.currentRow); + XlsxWriter.prototype._startRow = function(ht) { + this.rowBuffer = blobs.startRow(this.currentRow, ht); return this.currentRow += 1; }; diff --git a/src/blobs.coffee b/src/blobs.coffee index 9070fb1..1676322 100644 --- a/src/blobs.coffee +++ b/src/blobs.coffee @@ -136,7 +136,15 @@ module.exports = column: (width, index) -> """""" endColumns: """""" - startRow: (row) -> """""" + #startRow: (row) -> """""" + startRow: (row, ht) -> + out = """0 + out += """ customHeight="true" ht="#{ht}" """ + out += ">" + console.log(out) + return out + endRow: """""" cell: (index, cell) -> """#{index}""" diff --git a/src/index.litcoffee b/src/index.litcoffee index 07504ca..eb45f3f 100644 --- a/src/index.litcoffee +++ b/src/index.litcoffee @@ -306,8 +306,8 @@ Adds a cell to the row in progress. Begins a row. Call this before starting any row. Will start a buffer for all proceeding cells, until @_endRow is called. - _startRow: () -> - @rowBuffer = blobs.startRow(@currentRow) + _startRow: (ht) -> + @rowBuffer = blobs.startRow(@currentRow, ht) @currentRow += 1 Ends a row. Will write the row to the sheet. From 9a7d240156072717014a060a1f69075c80bd8f06 Mon Sep 17 00:00:00 2001 From: Zensey Date: Fri, 16 Dec 2016 11:39:57 +0300 Subject: [PATCH 6/6] add argument ht (row height) to startRow() --- src/blobs.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/blobs.coffee b/src/blobs.coffee index 1676322..cda05ca 100644 --- a/src/blobs.coffee +++ b/src/blobs.coffee @@ -142,7 +142,6 @@ module.exports = if ht>0 out += """ customHeight="true" ht="#{ht}" """ out += ">" - console.log(out) return out endRow: """"""