forked from exceljs/exceljs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
561f575
commit 54ab82d
Showing
3 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var _ = require('underscore'); | ||
var HrStopwatch = require('./utils/hr-stopwatch'); | ||
|
||
var Excel = require('../excel'); | ||
|
||
var inputFile = process.argv[2]; | ||
var outputFile = process.argv[3]; | ||
|
||
var wb = new Excel.Workbook(); | ||
|
||
var passed = true; | ||
var assert = function(value, failMessage, passMessage) { | ||
if (!value) { | ||
if (failMessage) console.error(failMessage); | ||
passed = false; | ||
} else { | ||
if (passMessage) console.log(passMessage); | ||
} | ||
}; | ||
|
||
// assuming file created by testBookOut | ||
wb.xlsx.readFile(inputFile) | ||
.then(function() { | ||
console.log('Loaded', inputFile); | ||
|
||
wb.eachSheet(function(sheet) { | ||
console.log(sheet.name); | ||
}); | ||
|
||
var ws = wb.getWorksheet('Sheet1'); | ||
|
||
assert(ws, "Expected to find a worksheet called sheet1"); | ||
|
||
ws.getCell('B1').value = new Date(); | ||
ws.getCell('B1').numFmt = 'hh:mm:ss'; | ||
|
||
ws.addRow([1, 'hello']); | ||
return wb.xlsx.writeFile(outputFile); | ||
}) | ||
.then(function() { | ||
assert(passed, "Something went wrong", "All tests passed!"); | ||
}) | ||
.catch(function(error) { | ||
console.error(error.message); | ||
console.error(error.stack); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var _ = require('underscore'); | ||
var HrStopwatch = require('./utils/hr-stopwatch'); | ||
|
||
var Excel = require('../excel'); | ||
|
||
var inputFile = process.argv[2]; | ||
var outputFile = process.argv[3]; | ||
|
||
|
||
var passed = true; | ||
var assert = function(value, failMessage, passMessage) { | ||
if (!value) { | ||
if (failMessage) console.error(failMessage); | ||
passed = false; | ||
} else { | ||
if (passMessage) console.log(passMessage); | ||
} | ||
}; | ||
|
||
|
||
var workbook = new Excel.Workbook(); | ||
workbook.xlsx.readFile('./out/template.xlsx') | ||
.then(function(stream) { | ||
var options = { | ||
useSharedStrings: true, | ||
useStyles: true | ||
}; | ||
|
||
return stream.xlsx.writeFile("./out/template-out.xlsx", options) | ||
.then(function(){ | ||
console.log("Done."); | ||
}) | ||
}) | ||
.catch(function(error) { | ||
console.error(error.message); | ||
console.error(error.stack); | ||
}); |