Skip to content

Commit 42ade4c

Browse files
committed
0.4.0 - Update TypeScript 2.8. Modify ExcelBuilder.createFile() JSZip parameter so JSZip is only required by ZipWorker. Add tsconfig 'strictNullChecks', 'noImplicitReturns', and 'forceConsistentCasingInFileNames'. Add npm script 'build-package' for release tarball.
1 parent ce1061e commit 42ade4c

26 files changed

+159
-140
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/
44

55

66
--------
7-
### [0.3.2](N/A) - 2018-02-28
7+
### [0.4.0](https://github.com/TeamworkGuy2/excel-builder-ts/commit/3e3b0e09a3ff939db25b3d5d83537adc213ad5f5) - 2018-04-14
8+
#### Changed
9+
* Update to TypeScript 2.8
10+
* Update tsconfig.json with `strictNullChecks: true`, `noImplicitReturns: true` and `forceConsistentCasingInFileNames: true`
11+
* Added release tarball and npm script `build-package` to package.json referencing external process to generate tarball
12+
* Cleanup JSZip dependency:
13+
* `ExcelBuilder.createFile()` now requires a JSZip instance or object with `file()` method instead of creating a JSZip instance from a constructor function and generating the zip file. i.e. use `ExcelBuilder.createFile(new JSZip(), ...).generateAsync(...)` instead of previously using `ExcelBuilder.createFile(JSZip, ...)`
14+
* `JSZip` is only required if using `ZipWorker`
15+
16+
17+
--------
18+
### [0.3.2](https://github.com/TeamworkGuy2/excel-builder-ts/commit/ce1061e1897a1b369c97a2d70d3da05510926b20) - 2018-02-28
819
#### Changed
920
* Update to TypeScript 2.7
1021
* Update dependencies: mocha, @types/chai, @types/mocha

ExcelBuilder.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"use strict";
2-
/// <reference path="../definitions/jszip/jszip.d.ts" />
32
var Workbook = require("./workbook/Workbook");
43
/**
54
* @name Excel
@@ -23,7 +22,7 @@ var ExcelBuilder = /** @class */ (function () {
2322
* options.base64 Whether to 'return' the generated file as a base64 string
2423
* options.success The callback function to run after workbook creation is successful.
2524
* options.error The callback function to run if there is an error creating the workbook.
26-
* options.requireJsPath (Optional) The path to requirejs. Will use the id 'requirejs' to look up the script if not specified.
25+
* options.requireJsPath The path to requirejs.
2726
*/
2827
ExcelBuilder.createFileAsync = function (workbook, options, jszipPath, zipWorkerPath, worksheetExportWorkerPath) {
2928
workbook.generateFilesAsync({
@@ -46,13 +45,13 @@ var ExcelBuilder = /** @class */ (function () {
4645
}
4746
}, worksheetExportWorkerPath);
4847
};
49-
/** Turns a workbook into a downloadable file.
50-
* @param jszip A JSZip equivalent library to use to generate/zip the excel file
48+
/** Generates the xml/binary data files for a workbook and loads them into the provided object.
49+
* @param zip A JSZip library equivalent object with a file() method to add all the xlsx files to
5150
* @param workbook The workbook that is being converted
52-
* @param options - options to modify how the excel doc is created. Only accepts a base64 boolean at the moment.
51+
* @param options options to modify how the excel doc is created. Only accepts a base64 boolean at the moment.
52+
* @returns the JSZip style object
5353
*/
54-
ExcelBuilder.createFile = function (jszip, workbook, options) {
55-
var zip = new jszip();
54+
ExcelBuilder.createFile = function (zip, workbook) {
5655
var files = workbook.generateFiles();
5756
Object.keys(files).forEach(function (path) {
5857
var content = files[path];
@@ -64,9 +63,7 @@ var ExcelBuilder = /** @class */ (function () {
6463
zip.file(path, content, { base64: true, binary: true });
6564
}
6665
});
67-
return zip.generateAsync({
68-
base64: (!options || options.base64 !== false)
69-
});
66+
return zip;
7067
};
7168
return ExcelBuilder;
7269
}());

ExcelBuilder.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/// <reference path="../definitions/jszip/jszip.d.ts" />
2-
31
import Workbook = require("./workbook/Workbook");
2+
import XmlDom = require("./xml/XmlDom")
43

54
/**
65
* @name Excel
@@ -25,9 +24,9 @@ class ExcelBuilder {
2524
* options.base64 Whether to 'return' the generated file as a base64 string
2625
* options.success The callback function to run after workbook creation is successful.
2726
* options.error The callback function to run if there is an error creating the workbook.
28-
* options.requireJsPath (Optional) The path to requirejs. Will use the id 'requirejs' to look up the script if not specified.
27+
* options.requireJsPath The path to requirejs.
2928
*/
30-
static createFileAsync(workbook: Workbook, options: { base64: boolean; error: () => void; requireJsPath?: string; success: (data: any) => void; }, jszipPath: string, zipWorkerPath: string, worksheetExportWorkerPath: string) {
29+
static createFileAsync(workbook: Workbook, options: { base64: boolean; error: () => void; requireJsPath: string; success: (data: any) => void; }, jszipPath: string, zipWorkerPath: string, worksheetExportWorkerPath: string) {
3130

3231
workbook.generateFilesAsync({
3332
requireJsPath: options.requireJsPath,
@@ -51,26 +50,25 @@ class ExcelBuilder {
5150
}
5251

5352

54-
/** Turns a workbook into a downloadable file.
55-
* @param jszip A JSZip equivalent library to use to generate/zip the excel file
53+
/** Generates the xml/binary data files for a workbook and loads them into the provided object.
54+
* @param zip A JSZip library equivalent object with a file() method to add all the xlsx files to
5655
* @param workbook The workbook that is being converted
57-
* @param options - options to modify how the excel doc is created. Only accepts a base64 boolean at the moment.
56+
* @param options options to modify how the excel doc is created. Only accepts a base64 boolean at the moment.
57+
* @returns the JSZip style object
5858
*/
59-
static createFile(jszip: typeof JSZip, workbook: Workbook, options?: { base64?: boolean; }) {
60-
var zip = new jszip();
59+
static createFile<F extends { file(path: string, content: string | XmlDom, opts?: { base64?: boolean; binary?: boolean }): void }>(zip: F, workbook: Workbook): F {
6160
var files = workbook.generateFiles();
6261
Object.keys(files).forEach(function (path) {
6362
var content = files[path];
6463
path = path.substr(1);
6564
if (path.indexOf(".xml") !== -1 || path.indexOf(".rel") !== -1) {
6665
zip.file(path, content, { base64: false });
67-
} else {
66+
}
67+
else {
6868
zip.file(path, content, { base64: true, binary: true });
6969
}
70-
})
71-
return zip.generateAsync({
72-
base64: (!options || options.base64 !== false)
7370
});
71+
return zip;
7472
}
7573

7674
}

bin/excel-builder-ts-0.4.0.tgz

31.6 KB
Binary file not shown.

drawings/AbsoluteAnchor.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import Util = require("../util/Util");
22
import XmlDom = require("../xml/XmlDom");
33

44
class AbsoluteAnchor {
5-
x: number;
6-
y: number;
7-
width: number;
8-
height: number;
5+
x: number | null;
6+
y: number | null;
7+
width: number | null;
8+
height: number | null;
99

1010

1111
/**
@@ -51,13 +51,13 @@ class AbsoluteAnchor {
5151
public toXML(xmlDoc: XmlDom, content: XmlDom.NodeBase) {
5252
var root = Util.createElement(xmlDoc, "xdr:absoluteAnchor");
5353
var pos = Util.createElement(xmlDoc, "xdr:pos");
54-
pos.setAttribute("x", <any>this.x);
55-
pos.setAttribute("y", <any>this.y);
54+
pos.setAttribute("x", this.x);
55+
pos.setAttribute("y", this.y);
5656
root.appendChild(pos);
5757

5858
var dimensions = Util.createElement(xmlDoc, "xdr:ext");
59-
dimensions.setAttribute("cx", <any>this.width);
60-
dimensions.setAttribute("cy", <any>this.height);
59+
dimensions.setAttribute("cx", this.width);
60+
dimensions.setAttribute("cy", this.height);
6161
root.appendChild(dimensions);
6262

6363
root.appendChild(content);

drawings/Drawing.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ var Drawing = /** @class */ (function () {
2020
* @returns a cell anchor object
2121
*/
2222
Drawing.prototype.createAnchor = function (type, config) {
23-
config = config || {};
24-
config.drawing = this;
23+
var cfg = (config != null ? config : {});
24+
cfg.drawing = this;
2525
switch (type) {
2626
case "absoluteAnchor":
27-
this.anchor = new AbsoluteAnchor(config);
27+
this.anchor = new AbsoluteAnchor(cfg);
2828
break;
2929
case "oneCellAnchor":
30-
this.anchor = new OneCellAnchor(config);
30+
this.anchor = new OneCellAnchor(cfg);
3131
break;
3232
case "twoCellAnchor":
33-
this.anchor = new TwoCellAnchor(config);
33+
this.anchor = new TwoCellAnchor(cfg);
3434
break;
3535
}
3636
return this.anchor;

drawings/Drawing.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ abstract class Drawing implements Drawings.Drawing {
2828
* @returns a cell anchor object
2929
*/
3030
public createAnchor(type: "absoluteAnchor" | "oneCellAnchor" | "twoCellAnchor", config?: { drawing?: Drawings.Drawing; from?: Util.OffsetConfig; to?: Util.OffsetConfig; } & Util.Pos): Drawing.AnchorLike {
31-
config = config || <any>{};
32-
config.drawing = this;
31+
var cfg = (config != null ? config : <any>{});
32+
cfg.drawing = this;
3333
switch (type) {
3434
case "absoluteAnchor":
35-
this.anchor = new AbsoluteAnchor(config);
35+
this.anchor = new AbsoluteAnchor(cfg);
3636
break;
3737
case "oneCellAnchor":
38-
this.anchor = new OneCellAnchor(config);
38+
this.anchor = new OneCellAnchor(cfg);
3939
break;
4040
case "twoCellAnchor":
41-
this.anchor = new TwoCellAnchor(<{ from: Util.OffsetConfig; to: Util.OffsetConfig; }><any>config);
41+
this.anchor = new TwoCellAnchor(<{ from: Util.OffsetConfig; to: Util.OffsetConfig; }><any>cfg);
4242
break;
4343
}
4444
return this.anchor;

drawings/OneCellAnchor.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import Util = require("../util/Util");
22
import XmlDom = require("../xml/XmlDom");
33

44
class OneCellAnchor {
5-
x: number;
6-
y: number;
7-
xOff: number;
8-
yOff: number;
9-
width: number;
10-
height: number;
5+
x: number | null;
6+
y: number | null;
7+
xOff: number | null;
8+
yOff: number | null;
9+
width: number | null;
10+
height: number | null;
1111

1212

1313
/**
@@ -32,7 +32,7 @@ class OneCellAnchor {
3232
}
3333

3434

35-
public setPos(x: number, y: number, xOff: number, yOff: number) {
35+
public setPos(x: number, y: number, xOff: number | undefined, yOff: number | undefined) {
3636
this.x = x;
3737
this.y = y;
3838
if (xOff !== undefined) {

drawings/Picture.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import XmlDom = require("../xml/XmlDom");
33
import Drawing = require("./Drawing");
44
import Drawings = require("./Drawings");
55

6-
class Picture {
6+
class Picture implements Drawings.Drawing {
77
static Cctor = (function () {
88
var thisProto = Picture.prototype;
99
Picture.prototype = new (<any>Drawing)();
@@ -24,7 +24,7 @@ class Picture {
2424
this.id = Util._uniqueId("Picture");
2525
this.pictureId = Util.uniqueId("Picture");
2626
this.fill = {};
27-
this.mediaData = null;
27+
this.mediaData = <any>null;
2828
}
2929

3030

@@ -85,7 +85,7 @@ class Picture {
8585
var pictureFill = Util.createElement(xmlDoc, "xdr:blipFill");
8686
pictureFill.appendChild(Util.createElement(xmlDoc, "a:blip", [
8787
["xmlns:r", Util.schemas.relationships],
88-
["r:embed", this.mediaData.rId]
88+
["r:embed", <any>this.mediaData.rId]
8989
]));
9090
pictureFill.appendChild(Util.createElement(xmlDoc, "a:srcRect"));
9191
var stretch = Util.createElement(xmlDoc, "a:stretch");

drawings/TwoCellAnchor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TwoCellAnchor {
1616
}
1717

1818

19-
public setFrom(x: number, y: number, xOff: number, yOff: number) {
19+
public setFrom(x: number | undefined, y: number | undefined, xOff: number, yOff: number) {
2020
this.from.x = x;
2121
this.from.y = y;
2222
if (xOff !== undefined) {
@@ -28,7 +28,7 @@ class TwoCellAnchor {
2828
}
2929

3030

31-
public setTo(x: number, y: number, xOff: number, yOff: number) {
31+
public setTo(x: number | undefined, y: number | undefined, xOff: number, yOff: number) {
3232
this.to.x = x;
3333
this.to.y = y;
3434
if (xOff !== undefined) {

0 commit comments

Comments
 (0)