Skip to content

Commit

Permalink
Merge pull request #31 from zurmokeeper/bugfix/rich_text_error
Browse files Browse the repository at this point in the history
fix rich text tags bug and add type definitions
  • Loading branch information
CTyrannosaurus committed Oct 20, 2023
2 parents 0120757 + 79a0191 commit aa16b15
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 14.x, 16.x, 18.x, 20.x]
node-version: [10.x, 12.x, 14.x, 16.x, 18.x, 20.x, 21.x]
os: [ubuntu-latest, macOS-latest, windows-latest]
runs-on: ${{ matrix.os }}

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ Options supported when reading CSV files.
| dateFormats | N | Array | Specify the date encoding format of dayjs. |
| map | N | Function | Custom Array.prototype.map() callback function for processing data. |
| sheetName | N | String | Specify worksheet name. |
| parserOptions | N | Object | [parseOptions options](https://c2fo.io/fast-csv/docs/parsing/options) @fast-csv/format module to write csv data. |
| parserOptions | N | Object | [parseOptions options](https://c2fo.github.io/fast-csv/docs/parsing/options) @fast-csv/format module to write csv data. |

```javascript
// read from a file
Expand Down Expand Up @@ -2388,7 +2388,7 @@ const options = {
return parseFloat(value);
}
},
// https://c2fo.io/fast-csv/docs/parsing/options
// https://c2fo.github.io/fast-csv/docs/parsing/options
parserOptions: {
delimiter: '\t',
quote: false,
Expand Down Expand Up @@ -2424,7 +2424,7 @@ Options supported when writing to a CSV file.
| map | N | Function | Custom Array.prototype.map() callback function for processing row values. |
| sheetName | N | String | Specify worksheet name. |
| sheetId | N | Number | Specify worksheet ID. |
| formatterOptions | N | Object | [formatterOptions options](https://c2fo.io/fast-csv/docs/formatting/options/) @fast-csv/format module to write csv data. |
| formatterOptions | N | Object | [formatterOptions options](https://c2fo.github.io/fast-csv/docs/formatting/options/) @fast-csv/format module to write csv data. |

```javascript

Expand Down Expand Up @@ -2465,7 +2465,7 @@ const options = {
return value;
}
},
// https://c2fo.io/fast-csv/docs/formatting/options
// https://c2fo.github.io/fast-csv/docs/formatting/options
formatterOptions: {
delimiter: '\t',
quote: false,
Expand Down
8 changes: 4 additions & 4 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ const buffer = await workbook.xlsx.writeBuffer({password: '123456'});
| dateFormats | N | Array | 指定 dayjs 的日期编码格式。 |
| map | N | Function | 自定义`Array.prototype.map()` 回调函数,用于处理数据。 |
| sheetName | N | String | 指定工作表名称。 |
| parserOptions | N | Object | [parseOptions 选项](https://c2fo.io/fast-csv/docs/parsing/options) @fast-csv/format 模块以写入 csv 数据。 |
| parserOptions | N | Object | [parseOptions 选项](https://c2fo.github.io/fast-csv/docs/parsing/options) @fast-csv/format 模块以写入 csv 数据。 |

```javascript
// 从文件读取
Expand Down Expand Up @@ -2279,7 +2279,7 @@ const options = {
return parseFloat(value);
}
},
// https://c2fo.io/fast-csv/docs/parsing/options
// https://c2fo.github.io/fast-csv/docs/parsing/options
parserOptions: {
delimiter: '\t',
quote: false,
Expand Down Expand Up @@ -2312,7 +2312,7 @@ CSV 解析器使用 [fast-csv](https://www.npmjs.com/package/fast-csv) 读取CSV
| map | N | Function | 自定义`Array.prototype.map()` 回调函数,用于处理行值。 |
| sheetName | N | String | 指定工作表名称。 |
| sheetId | N | Number | 指定工作表 ID。 |
| formatterOptions | N | Object | [formatterOptions 选项](https://c2fo.io/fast-csv/docs/formatting/options/) @fast-csv/format 模块写入csv 数据。 |
| formatterOptions | N | Object | [formatterOptions 选项](https://c2fo.github.io/fast-csv/docs/formatting/options/) @fast-csv/format 模块写入csv 数据。 |

```javascript

Expand Down Expand Up @@ -2352,7 +2352,7 @@ const options = {
return value;
}
},
// https://c2fo.io/fast-csv/docs/formatting/options
// https://c2fo.github.io/fast-csv/docs/formatting/options
formatterOptions: {
delimiter: '\t',
quote: false,
Expand Down
18 changes: 10 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export interface Font {
}

export type BorderStyle =
| 'thin' | 'dotted' | 'hair' | 'medium' | 'double' | 'thick' | 'dashDot'
| 'thin' | 'dotted' | 'hair' | 'medium' | 'double' | 'thick' | 'dashed' | 'dashDot'
| 'dashDotDot' | 'slantDashDot' | 'mediumDashed' | 'mediumDashDotDot' | 'mediumDashDot';

export type ColorIndexes = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Expand Down Expand Up @@ -371,6 +371,7 @@ export interface Alignment {

export interface Protection {
locked: boolean;
hidden: boolean;
}

export interface Style {
Expand Down Expand Up @@ -426,19 +427,20 @@ export interface CellRichTextValue {
export interface CellHyperlinkValue {
text: string;
hyperlink: string;
tooltip?: string;
}

export interface CellFormulaValue {
formula: string;
result?: number | string | Date | { error: CellErrorValue };
date1904: boolean;
result?: number | string | boolean | Date | CellErrorValue;
date1904?: boolean;
}

export interface CellSharedFormulaValue {
sharedFormula: string;
readonly formula?: string;
result?: number | string | Date | { error: CellErrorValue };
date1904: boolean;
result?: number | string | boolean | Date | CellErrorValue;
date1904?: boolean;
}

export declare enum ValueType {
Expand Down Expand Up @@ -1234,7 +1236,7 @@ export interface Worksheet {
/**
* Get the last column in a worksheet
*/
readonly lastColumn: Column;
readonly lastColumn: Column | undefined;

/**
* A count of the number of columns that have values.
Expand Down Expand Up @@ -1667,7 +1669,7 @@ export interface Xlsx {
write(stream: import('stream').Stream, options?: Partial<XlsxWriteOptions>): Promise<void>;
}

// https://c2fo.io/fast-csv/docs/parsing/options
// https://c2fo.github.io/fast-csv/docs/parsing/options

type HeaderArray = (string | undefined | null)[];
type HeaderTransformFunction = (headers: HeaderArray) => HeaderArray;
Expand Down Expand Up @@ -1708,7 +1710,7 @@ interface RowTransformFunction {
(row: Rows): Rows;
}

// https://c2fo.io/fast-csv/docs/formatting/options/
// https://c2fo.github.io/fast-csv/docs/formatting/options/
export interface FastCsvFormatterOptionsArgs {
objectMode: boolean;
delimiter: string;
Expand Down
3 changes: 3 additions & 0 deletions lib/xlsx/xform/strings/shared-string-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class SharedStringXform extends BaseXform {
case 'r': {
let rt = this.model.richText;
if (!rt) {
if (!this.model) {
this.model = {};
}
rt = this.model.richText = [];
}
rt.push(this.parser.model);
Expand Down
1 change: 1 addition & 0 deletions lib/xlsx/xform/style/border-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class EdgeXform extends BaseXform {

EdgeXform.validStyleValues = [
'thin',
'dashed',
'dotted',
'dashDot',
'hair',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zurmokeeper/exceljs",
"version": "4.4.6",
"version": "4.4.7",
"description": "Excel Workbook Manager - Read and Write xlsx and csv Files.",
"private": false,
"license": "MIT",
Expand Down
Binary file added spec/integration/data/rich-text-parse-test.xlsx
Binary file not shown.
9 changes: 9 additions & 0 deletions spec/integration/workbook-xlsx-reader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,13 @@ describe('WorkbookReader', () => {
);
});
});

describe('with rich text to describe a hyperlink', () => {
it('should parse with no errors', () => {
const workbook = new ExcelJS.Workbook();
return workbook.xlsx.read(
fs.createReadStream('./spec/integration/data/rich-text-parse-test.xlsx')
);
});
});
});

0 comments on commit aa16b15

Please sign in to comment.