-
-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from dolanmiu/feature/table-background
Add shading (background color) for cell
- Loading branch information
Showing
9 changed files
with
164 additions
and
50 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./table"; | ||
export * from "./table-cell"; | ||
export * from "./table-properties"; | ||
export * from "./shading"; |
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 @@ | ||
export * from "./shading"; |
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,37 @@ | ||
import { expect } from "chai"; | ||
|
||
import { Formatter } from "export/formatter"; | ||
|
||
import { ShadingType, TableShading } from "./shading"; | ||
|
||
describe("TableShading", () => { | ||
describe("#constructor", () => { | ||
it("should create", () => { | ||
const cellMargain = new TableShading({}); | ||
const tree = new Formatter().format(cellMargain); | ||
expect(tree).to.deep.equal({ | ||
"w:shd": [ | ||
{ | ||
_attr: {}, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it("should create with params", () => { | ||
const cellMargain = new TableShading({ val: ShadingType.PERCENT_40, color: "FF0000", fill: "555555" }); | ||
const tree = new Formatter().format(cellMargain); | ||
expect(tree).to.deep.equal({ | ||
"w:shd": [ | ||
{ | ||
_attr: { | ||
"w:color": "FF0000", | ||
"w:fill": "555555", | ||
"w:val": "pct40", | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
}); |
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,64 @@ | ||
// http://officeopenxml.com/WPtableShading.php | ||
// http://officeopenxml.com/WPtableCellProperties-Shading.php | ||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; | ||
|
||
export interface ITableShadingAttributesProperties { | ||
readonly fill?: string; | ||
readonly color?: string; | ||
readonly val?: ShadingType; | ||
} | ||
|
||
class TableShadingAttributes extends XmlAttributeComponent<ITableShadingAttributesProperties> { | ||
protected readonly xmlKeys = { | ||
fill: "w:fill", | ||
color: "w:color", | ||
val: "w:val", | ||
}; | ||
} | ||
|
||
export class TableShading extends XmlComponent { | ||
constructor(attrs: ITableShadingAttributesProperties) { | ||
super("w:shd"); | ||
this.root.push(new TableShadingAttributes(attrs)); | ||
} | ||
} | ||
|
||
export enum ShadingType { | ||
CLEAR = "clear", | ||
DIAGONAL_CROSS = "diagCross", | ||
DIAGONAL_STRIPE = "diagStripe", | ||
HORIZONTAL_CROSS = "horzCross", | ||
HORIZONTAL_STRIPE = "horzStripe", | ||
NIL = "nil", | ||
PERCENT_5 = "pct5", | ||
PERCENT_10 = "pct10", | ||
PERCENT_12 = "pct12", | ||
PERCENT_15 = "pct15", | ||
PERCENT_20 = "pct20", | ||
PERCENT_25 = "pct25", | ||
PERCENT_30 = "pct30", | ||
PERCENT_35 = "pct35", | ||
PERCENT_37 = "pct37", | ||
PERCENT_40 = "pct40", | ||
PERCENT_45 = "pct45", | ||
PERCENT_50 = "pct50", | ||
PERCENT_55 = "pct55", | ||
PERCENT_60 = "pct60", | ||
PERCENT_62 = "pct62", | ||
PERCENT_65 = "pct65", | ||
PERCENT_70 = "pct70", | ||
PERCENT_75 = "pct75", | ||
PERCENT_80 = "pct80", | ||
PERCENT_85 = "pct85", | ||
PERCENT_87 = "pct87", | ||
PERCENT_90 = "pct90", | ||
PERCENT_95 = "pct95", | ||
REVERSE_DIAGONAL_STRIPE = "reverseDiagStripe", | ||
SOLID = "solid", | ||
THIN_DIAGONAL_CROSS = "thinDiagCross", | ||
THIN_DIAGONAL_STRIPE = "thinDiagStripe", | ||
THIN_HORIZONTAL_CROSS = "thinHorzCross", | ||
THIN_REVERSE_DIAGONAL_STRIPE = "thinReverseDiagStripe", | ||
THIN_VERTICAL_STRIPE = "thinVertStripe", | ||
VERTICAL_STRIPE = "vertStripe", | ||
} |
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
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