Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
nuNuKim committed Dec 11, 2013
1 parent 815ede3 commit 984fb0c
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 16 deletions.
Binary file added .DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ Creates SpreadsheetML (.xlsx) files in sequence with streaming interface.
x.write [1,2,3]
x.end()

* Multiple sheets support

# coffee-script

x = xlsx()
x.pipe fs.createWriteStream("./out.xlsx")

sheet1 = x.sheet('first sheet')
sheet1.write ["first", "sheet"]
sheet1.end()

sheet2 = x.sheet('another')
sheet2.write ["second", "sheet"]
sheet2.end()

x.finalize()

14 changes: 11 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = xlsxStream = function(opts) {
return sheetStream(zip, sheet, opts);
};
proxy.finalize = function() {
var buffer, name, obj, sheet, _i, _len, _ref, _ref1;
var buffer, func, name, obj, sheet, _i, _len, _ref, _ref1, _ref2;
_ref = templates.statics;
for (name in _ref) {
buffer = _ref[name];
Expand All @@ -56,9 +56,17 @@ module.exports = xlsxStream = function(opts) {
store: opts.store
});
}
_ref1 = templates.sheet_related;
_ref1 = templates.semiStatics;
for (name in _ref1) {
obj = _ref1[name];
func = _ref1[name];
zip.append(func(opts), {
name: name,
store: opts.store
});
}
_ref2 = templates.sheet_related;
for (name in _ref2) {
obj = _ref2[name];
buffer = obj.header;
for (_i = 0, _len = sheets.length; _i < _len; _i++) {
sheet = sheets[_i];
Expand Down
14 changes: 11 additions & 3 deletions lib/templates.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions src/index.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# xlsx ファイルをストリームで変換する。
# Convert stream of Array to a xlsx file.
#
# * 使い方
# * Usage
#
# out = fs.createWriteStream('out.xlsx')
# stream = xlsxStream()
Expand All @@ -19,11 +19,10 @@ duplex = require 'duplexer'

templates = require './templates'
utils = require "./utils"

sheetStream = require "./sheet"

module.exports = xlsxStream = (opts = {})->
# zip にアーカイブする。
# archiving into a zip file using archiver (internally using node's zlib built-in module)
zip = archiver.create('zip', opts)
defaultRepeater = through()
proxy = duplex(defaultRepeater, zip)
Expand Down Expand Up @@ -53,13 +52,15 @@ module.exports = xlsxStream = (opts = {})->
sheets.push sheet
sheetStream(zip, sheet, opts)

# 入力ストリームが終わったら、後処理。
# finalize the xlsx file
proxy.finalize = ->
# 静的なファイル
# static files
for name, buffer of templates.statics
zip.append buffer, {name, store: opts.store}
for name, func of templates.semiStatics
zip.append func(opts), {name, store: opts.store}

# シート数に応じて変化するもの
# files modified by number of sheets
for name, obj of templates.sheet_related
buffer = obj.header
buffer += obj.sheet(sheet) for sheet in sheets
Expand Down
37 changes: 34 additions & 3 deletions src/templates.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ module.exports =
ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>
<Override PartName="/xl/sharedStrings.xml"
ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>
<Override PartName="/docProps/core.xml"
ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
<Override PartName="/docProps/app.xml"
ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
"""
sheet: (sheet)-> """
<Override PartName="/#{esc sheet.path}" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
Expand Down Expand Up @@ -91,9 +95,9 @@ module.exports =
"_rels/.rels": xml """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
Target="xl/workbook.xml"/>
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
</Relationships>
"""

Expand Down Expand Up @@ -154,3 +158,30 @@ module.exports =
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="0" uniqueCount="0"/>
"""

"docProps/app.xml": xml """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<Application>node-xlsx-stream</Application>
<DocSecurity>0</DocSecurity>
<ScaleCrop>false</ScaleCrop>
<Company>Microsoft Corporation</Company>
<LinksUpToDate>false</LinksUpToDate>
<SharedDoc>false</SharedDoc>
<HyperlinksChanged>false</HyperlinksChanged>
<AppVersion>#{require('../package.json').version}</AppVersion>
</Properties>
"""

semiStatics:
"docProps/core.xml": (opts)->
today = new Date().toISOString()
"""
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<dc:creator>node-xlsx-stream</dc:creator>
<cp:lastModifiedBy>node-xlsx-stream</cp:lastModifiedBy>
<dcterms:created xsi:type="dcterms:W3CDTF">#{today}</dcterms:created>
<dcterms:modified xsi:type="dcterms:W3CDTF">#{today}</dcterms:modified>
</cp:coreProperties>
"""

0 comments on commit 984fb0c

Please sign in to comment.