Skip to content

Commit c0ed9a9

Browse files
committed
0.6.2 - Fix several 'StyleSheet' interface/type issues.
1 parent 3f06fa5 commit c0ed9a9

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

CHANGELOG.md

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

55

66
--------
7-
### [0.6.1](N/A) - 2020-11-24
7+
### [0.6.2](N/A) - 2020-11-25
8+
#### Changed
9+
* Fix issue with `StyleSheet` `BorderProperty.color` and `FontStyle.color` fields not supporting type `string`
10+
* Split `StyleSheet` `Fill` interface into `PatternFill` and `GradientFill` and make `Fill` a union type
11+
12+
#### Fixed
13+
* `Fill` (now changed to `PatternFill`) `bgColor` and `fgColor` fields having an incorrect custom color type with a misspelled `rbg` field, now those fields use the correct `Color` interface
14+
15+
16+
--------
17+
### [0.6.1](https://github.com/TeamworkGuy2/excel-builder-ts/commit/3f06fa54d88ffb1c22773da579c89fd53c56b4e9) - 2020-11-24
818
#### Changed
919
* Improve types in `StyleSheet`
1020
* Reorganize `Util`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "excel-builder-ts",
3-
"version": "0.6.1",
3+
"version": "0.6.2",
44
"description": "TypeScript Port of excel-builder.js - A way to build excel files with javascript",
55
"author": "TeamworkGuy2",
66
"homepage": "https://github.com/TeamworkGuy2/excel-builder-ts",

worksheet/StyleSheet.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ var StyleSheet = /** @class */ (function () {
503503
bgColorElem.setAttribute("theme", bgColor.theme);
504504
}
505505
else {
506-
bgColorElem.setAttribute("rgb", bgColor.rbg);
506+
bgColorElem.setAttribute("rgb", bgColor.rgb);
507507
}
508508
}
509509
var fgColorElem = doc.createElement("fgColor");
@@ -515,7 +515,7 @@ var StyleSheet = /** @class */ (function () {
515515
fgColorElem.setAttribute("theme", fgColor.theme);
516516
}
517517
else {
518-
fgColorElem.setAttribute("rgb", fgColor.rbg);
518+
fgColorElem.setAttribute("rgb", fgColor.rgb);
519519
}
520520
}
521521
fillDef.appendChild(fgColorElem);

worksheet/StyleSheet.ts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class StyleSheet {
7575
}
7676

7777

78-
public createFill(fillInstructions: StyleSheet.Fill): StyleSheet.Fill & { id: number } {
78+
public createFill<T extends StyleSheet.Fill>(fillInstructions: T): T & { id: number } {
7979
var id = this.fills.length;
8080
var fill = fillInstructions;
8181
fill.id = id;
@@ -510,7 +510,7 @@ class StyleSheet {
510510
}
511511

512512

513-
public exportGradientFill(doc: XmlDom, data: StyleSheet.Fill) {
513+
public exportGradientFill(doc: XmlDom, data: StyleSheet.GradientFill) {
514514
var fillDef = doc.createElement("gradientFill");
515515
if (data.degree) {
516516
fillDef.setAttribute("degree", data.degree);
@@ -555,7 +555,7 @@ class StyleSheet {
555555
/**
556556
* Pattern types: http://www.schemacentral.com/sc/ooxml/t-ssml_ST_PatternType.html
557557
*/
558-
public exportPatternFill(doc: XmlDom, data: StyleSheet.Fill) {
558+
public exportPatternFill(doc: XmlDom, data: StyleSheet.PatternFill) {
559559
var fillDef = Util.createElement(doc, "patternFill", [
560560
["patternType", data.patternType]
561561
]);
@@ -571,7 +571,7 @@ class StyleSheet {
571571
bgColorElem.setAttribute("theme", bgColor.theme);
572572
}
573573
else {
574-
bgColorElem.setAttribute("rgb", bgColor.rbg);
574+
bgColorElem.setAttribute("rgb", bgColor.rgb);
575575
}
576576
}
577577

@@ -584,7 +584,7 @@ class StyleSheet {
584584
fgColorElem.setAttribute("theme", fgColor.theme);
585585
}
586586
else {
587-
fgColorElem.setAttribute("rgb", fgColor.rbg);
587+
fgColorElem.setAttribute("rgb", fgColor.rgb);
588588
}
589589
}
590590

@@ -720,9 +720,13 @@ class StyleSheet {
720720
}
721721

722722
module StyleSheet {
723-
// All ST_* types have exact names taken from W3C XML §A.2
723+
// All ST_* types have exact names taken from W3C XML A.2
724724

725-
type ST_BorderStyle = ("none" | "thin" | "medium" | "dashed" | "dotted" | "thick" | "double" | "hair" | "mediumDashed" | "dashDot" | "mediumDashDot" | "dashDotDot" | "mediumDashDotDot" | "slantDashDot");
725+
export type ST_BorderStyle = ("none" | "thin" | "medium" | "dashed" | "dotted" | "thick" | "double" | "hair" | "mediumDashed" | "dashDot" | "mediumDashDot" | "dashDotDot" | "mediumDashDotDot" | "slantDashDot");
726+
727+
export type ST_GradientType = ("linear" | "path");
728+
729+
export type ST_PatternType = ("none" | "solid" | "mediumGray" | "darkGray" | "lightGray" | "darkHorizontal" | "darkVertical" | "darkDown" | "darkUp" | "darkGrid" | "darkTrellis" | "lightHorizontal" | "lightVertical" | "lightDown" | "lightUp" | "lightGrid" | "lightTrellis" | "gray125" | "gray0625");
726730

727731

728732
export interface Alignment {
@@ -758,7 +762,7 @@ module StyleSheet {
758762

759763

760764
export interface BorderProperty {
761-
color?: Color;
765+
color?: Color | string;
762766
style?: ST_BorderStyle;
763767
}
764768

@@ -827,28 +831,35 @@ module StyleSheet {
827831
}
828832

829833

830-
export interface Fill {
834+
export interface PatternFill {
831835
id?: number;
832-
type: string; // 'pattern'
833-
patternType: string;
834-
// Pattern fill
835-
bgColor?: string | { theme?: string; rbg?: string; }; // ARGB
836-
fgColor?: string | { theme?: string; rbg?: string; }; // ARGB
837-
// Gradient fill
838-
degree?: any;
839-
left?: any;
840-
right?: any;
841-
top?: any;
842-
bottom?: any;
843-
start?: string | { pureAt?: number; color?: string; theme?: string; };
844-
end?: string | { pureAt?: number; color?: string; theme?: string; };
836+
type: "pattern";
837+
bgColor?: Color | string;
838+
fgColor?: Color | string;
839+
patternType: ST_PatternType;
845840
}
846841

847842

843+
export interface GradientFill {
844+
id?: number;
845+
type: "gradient";
846+
degree?: number;
847+
left?: number;
848+
right?: number;
849+
top?: number;
850+
bottom?: number;
851+
start?: string | { pureAt?: number; color?: string; theme?: string; }; // stops: GradientStop[];
852+
end?: string | { pureAt?: number; color?: string; theme?: string; }; // stops: GradientStop[];
853+
}
854+
855+
856+
export type Fill = PatternFill | GradientFill;
857+
858+
848859
export interface FontStyle {
849860
id?: number;
850861
bold?: boolean;
851-
color?: string;
862+
color?: Color | string;
852863
fontName?: string;
853864
italic?: boolean;
854865
outline?: boolean;

0 commit comments

Comments
 (0)