Skip to content

Commit 48748e0

Browse files
Merge branch 'master' into dependabot/npm_and_yarn/eslint-4.18.2
2 parents 6b36af7 + 5037a02 commit 48748e0

File tree

7 files changed

+81
-49
lines changed

7 files changed

+81
-49
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
<a name="0.6.0"></a>
6+
# [0.6.0](https://github.com/securedeveloper/react-data-export/compare/v0.5.0...v0.6.0) (2020-01-20)
7+
8+
9+
### Features
10+
11+
* if the header has style then the style should be used ([855d37a](https://github.com/securedeveloper/react-data-export/commit/855d37a))
12+
13+
14+
515
<a name="0.5.0"></a>
616
# [0.5.0](https://github.com/securedeveloper/react-data-export/compare/v0.4.2...v0.5.0) (2018-09-24)
717

dist/ExcelPlugin/utils/DataUtil.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var excelSheetFromDataSet = function excelSheetFromDataSet(dataSet) {
7171
fixRange(range, 0, 0, rowCount, xSteps, ySteps);
7272
var colTitle = col;
7373
if ((typeof col === 'undefined' ? 'undefined' : _typeof(col)) === 'object') {
74-
colTitle = col.title;
74+
//colTitle = col.title; //moved to getHeaderCell
7575
columnsWidth.push(col.width || { wpx: 80 }); /* wch (chars), wpx (pixels) - e.g. [{wch:6},{wpx:50}] */
7676
}
7777
getHeaderCell(colTitle, cellRef, ws);
@@ -102,8 +102,8 @@ var excelSheetFromDataSet = function excelSheetFromDataSet(dataSet) {
102102

103103
function getHeaderCell(v, cellRef, ws) {
104104
var cell = {};
105-
var headerCellStyle = { font: { bold: true } };
106-
cell.v = v;
105+
var headerCellStyle = v.style ? v.style : { font: { bold: true } }; //if style is then use it
106+
cell.v = v.title;
107107
cell.t = 's';
108108
cell.s = headerCellStyle;
109109
ws[cellRef] = cell;

examples/styled_excel_sheet.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,8 @@ class App extends Component {
6262
```
6363

6464
## Output
65-
![Download Button](http://i64.tinypic.com/2mey8na.jpg)
66-
![Excel File Outpu](http://i63.tinypic.com/2qko404.jpg)
65+
![Download Button](https://blvenglu.sirv.com/github/download_styled_excel_sheet.png)
66+
![Excel File Outpu](https://blvenglu.sirv.com/github/styled_excel_sheet.png)
67+
[Codesandbox](https://codesandbox.io/s/styledexcelsheet-hf5oo "Codesandbox | styled_excel_sheet")
68+
69+

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "react-data-export",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"main": "dist/index.js",
5+
"types": "types/index.d.ts",
56
"description": "A set of tools to export dataset from react to different formats.",
67
"repository": {
78
"type": "git",

src/ExcelPlugin/utils/DataUtil.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const excelSheetFromDataSet = (dataSet) => {
5858
fixRange(range, 0, 0, rowCount, xSteps, ySteps);
5959
var colTitle = col;
6060
if (typeof col === 'object'){
61-
colTitle = col.title;
61+
//colTitle = col.title; //moved to getHeaderCell
6262
columnsWidth.push(col.width || {wpx:80}); /* wch (chars), wpx (pixels) - e.g. [{wch:6},{wpx:50}] */
6363
}
6464
getHeaderCell(colTitle, cellRef, ws);
@@ -89,8 +89,8 @@ const excelSheetFromDataSet = (dataSet) => {
8989

9090
function getHeaderCell(v, cellRef, ws) {
9191
var cell = {};
92-
var headerCellStyle = {font: {bold: true}};
93-
cell.v = v;
92+
var headerCellStyle = v.style ? v.style : { font: { bold: true } }; //if style is then use it
93+
cell.v = v.title;
9494
cell.t = 's';
9595
cell.s = headerCellStyle;
9696
ws[cellRef] = cell;

types/index.d.ts

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,75 @@
11
/* index.d.ts (C) react-data-export */
22

33
// TypeScript Version: 2.2
4+
declare module 'react-data-export' {
5+
import * as React from 'react'
46

5-
export interface ExcelFileProps {
7+
export interface ExcelFileProps {
68
filename?: string;
79
fileExtension?: string;
810
element?: any; //Download Element
9-
children?: Array<ExcelSheetProps>;
10-
}
11+
children?: Array<React.ReactChild> | React.ReactChild; // Array<ExcelSheetProps>;
12+
}
1113

12-
export interface ExcelSheetProps {
14+
export interface ExcelSheetProps {
1315
name: string;
1416
data?: Array<object>;
1517
dataSet?: Array<ExcelSheetData>;
1618
value?: Array<string> | Function;
17-
children?: Array<ExcelColumnProps>
18-
}
19+
children?: Array<React.ReactChild> | React.ReactChild; // Array<ExcelColumnProps>
20+
}
1921

20-
export interface ExcelSheetData {
22+
export interface ExcelSheetData {
2123
xSteps?: number;
2224
ySteps?: number;
2325
columns: Array<string>;
2426
data: Array<ExcelCellData>;
25-
}
27+
}
2628

27-
export type ExcelCellData = ExcelValue | ExcelCell;
28-
export type ExcelValue = string | number | Date | boolean;
29+
export type ExcelCellData = ExcelValue | ExcelCell | Array<ExcelValue>;
30+
export type ExcelValue = string | number | Date | boolean;
2931

30-
export interface ExcelCell {
32+
export interface ExcelCell {
3133
value: ExcelCell;
3234
style: ExcelStyle;
33-
}
35+
}
3436

35-
export interface ExcelColumnProps {
37+
export interface ExcelColumnProps {
3638
label: string;
3739
value: number | boolean | string | Function;
38-
}
40+
}
3941

40-
export interface ExcelStyle {
42+
export interface ExcelStyle {
4143
fill?: ExcelCellFillType;
4244
font?: ExcelFont;
4345
numFmt?: ExcelNumFormat;
4446
alignment?: ExcelAlignment;
4547
border?: ExcelBorder;
46-
}
48+
}
4749

48-
/* ExcelCell Fill Type */
49-
export type ExcelCellPatternType = "solid" | "none";
50+
/* ExcelCell Fill Type */
51+
export type ExcelCellPatternType = "solid" | "none";
5052

51-
export interface ExcelColorSpec {
53+
export interface ExcelColorSpec {
5254
auto?: number; //default 1
5355
rgb?: string; //hex ARGB color
5456
theme?: ExcelTheme;
5557
indexed?: number;
56-
}
58+
}
5759

58-
export interface ExcelTheme {
60+
export interface ExcelTheme {
5961
theme: string;
6062
tint: string;
61-
}
63+
}
6264

63-
export interface ExcelCellFillType {
65+
export interface ExcelCellFillType {
6466
patternType?: ExcelCellPatternType;
6567
fgColor?: ExcelColorSpec;
6668
bgColor?: ExcelColorSpec;
67-
}
69+
}
6870

69-
/* Excel Font */
70-
export interface ExcelFont {
71+
/* Excel Font */
72+
export interface ExcelFont {
7173
name?: string; // default `"Calibri"`
7274
sz?: number; //font size in points default 11
7375
color?: ExcelColorSpec;
@@ -78,33 +80,33 @@ export interface ExcelFont {
7880
outline?: boolean;
7981
shadow?: boolean;
8082
vertAlign?: boolean;
81-
}
83+
}
8284

83-
/* ExcelNumFormat */
84-
export type ExcelNumFormat = "0" | "0.00%" | "0.0%" | "0.00%;\\(0.00%\\);\\-;@" | "m/dd/yy" | string;
85+
/* ExcelNumFormat */
86+
export type ExcelNumFormat = "0" | "0.00%" | "0.0%" | "0.00%;\\(0.00%\\);\\-;@" | "m/dd/yy" | string;
8587

86-
/* ExcelAlignment */
87-
export interface ExcelAlignment {
88+
/* ExcelAlignment */
89+
export interface ExcelAlignment {
8890
vertical?: ExcelAlignmentType;
8991
horizontal?: ExcelAlignmentType;
9092
wrapText?: boolean;
9193
readingOrder?: ExcelReadingOrder;
9294
textRotation?: ExcelTextRotation;
93-
}
95+
}
9496

95-
export type ExcelTextRotation = 0 | 45 | 90 | 135 | 180 | 255;
97+
export type ExcelTextRotation = 0 | 45 | 90 | 135 | 180 | 255;
9698

97-
export enum ExcelReadingOrder { LeftToRight = 1, RightToLeft}
99+
export enum ExcelReadingOrder { LeftToRight = 1, RightToLeft}
98100

99-
export type ExcelAlignmentType = "bottom" | "center" | "top";
101+
export type ExcelAlignmentType = "bottom" | "center" | "top";
100102

101-
/* ExcelBorder */
102-
export interface ExcelBorder {
103+
/* ExcelBorder */
104+
export interface ExcelBorder {
103105
style: ExcelBorderStyle;
104106
color: ExcelColorSpec;
105-
}
107+
}
106108

107-
export type ExcelBorderStyle =
109+
export type ExcelBorderStyle =
108110
"thin"
109111
| "medium"
110112
| "thick"
@@ -117,3 +119,19 @@ export type ExcelBorderStyle =
117119
| "dashDotDot"
118120
| "mediumDashDotDot"
119121
| "slantDashDot";
122+
123+
export class ExcelColumn extends React.Component<ExcelColumnProps, any> {
124+
}
125+
126+
export class ExcelSheet extends React.Component<ExcelSheetProps, any> {
127+
}
128+
129+
export class ExcelFile extends React.Component<ExcelFileProps, any> {
130+
}
131+
132+
export namespace ReactExport {
133+
export class ExcelFile extends React.Component<ExcelFileProps, any> {
134+
}
135+
}
136+
export default ReactExport
137+
}

0 commit comments

Comments
 (0)