Skip to content

Commit be52121

Browse files
author
m.r
committed
feature: init V7.0.0
1 parent eaabf90 commit be52121

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4648
-4230
lines changed

.github/workflows/manually_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
default: 'main'
99
os:
1010
description: 'Operating System'
11+
type: choice
1112
required: true
1213
default: 'ubuntu-latest'
1314
options:

README.md

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ important functions of library that are defined with specific use cases as follo
3434

3535
<a id="excel-to-node"></a>
3636

37-
- **`🆕 excelToNode`**: This function reads an uploaded Excel file and generates a representation of the tables from its sheets. It can either return the table directly or insert it into a specified container node provided as input.
37+
- **` excelToNode`**: This function reads an uploaded Excel file and generates a representation of the tables from its sheets. It can either return the table directly or insert it into a specified container node provided as input.
3838

3939
<a id="excel-to-json"></a>
4040

41-
- **`🆕 excelToJson`**: This function reads an Excel file and returns a JSON object that represents the data contained in the file.
41+
- **` excelToJson`**: This function reads an Excel file and returns a JSON object that represents the data contained in the file.
42+
43+
<a id="replace-in-excel"></a>
44+
45+
- **`replaceInExcel`**: This function is used to replace data based on a defined flag, such as {{FLAG}}, in Excel.
4246

4347
The example has been moved to a separate repository for easier updates. You can find it in the ["**_`mr-excel-example-gallery`_**"](https://github.com/mohammadrezaeicode/mr-excel-example-gallery)([**_link_**](https://github.com/mohammadrezaeicode/mr-excel-example-gallery))
4448

@@ -88,16 +92,20 @@ The example has been moved to a separate repository for easier updates. You can
8892
- [**`How to use extractExcelData`**](#extract-excel-data-usage)
8993
- [**`generateCSV && generateText`**](#generate-csv-txt)
9094
- [**`How to use generateCSV && generateText`**](#generate-csv-txt-usage)
91-
- [**`🆕 excelToNode`**](#excel-to-node)
92-
- [**`🆕 How to use excelToNode`**](#excel-to-node-usage)
93-
- [**`🆕 excelToJson`**](#excel-to-json)
94-
- [**`🆕 How to use excelToJson`**](#excel-to-json-usage)
95+
- [**` excelToNode`**](#excel-to-node)
96+
- [**` How to use excelToNode`**](#excel-to-node-usage)
97+
- [**` excelToJson`**](#excel-to-json)
98+
- [**` How to use excelToJson`**](#excel-to-json-usage)
99+
- [**`🆕 replaceInExcel`**](#replace-in-excel)
100+
- [**`🆕 How to use replaceInExcel`**](#replace-in-excel-usage)
95101
- [**`interface`**](#interface)
96102
- [**`Migrate Version`**](#migrate)
103+
- [**`Migrating from 6 to 7`**](#migrating-6)
97104
- [**`Migrating from 5 to 6`**](#migrating-5)
98105
- [**`Migrating from 4 to 5`**](#migrating-4)
99106
- [**`Migrating from 3 to 4`**](#migrating-3)
100107
- [**`Migrating from 2 to 3`**](#migrating-2)
108+
- [**`Release note`**](#release-note)
101109

102110

103111
<a id="installation"></a>
@@ -659,9 +667,34 @@ ExcelTable.excelToNode(uri, queryForTable, containerElement, config)
659667

660668
</details>
661669

670+
<a id="replace-in-excel-usage"></a>
671+
672+
### 🆕 How to use replaceInExcel
673+
674+
To use this function, you should provide {{FLAG}} in Excel. Change the relevant cells to represent the flag ({{name}}, e.g.) and pass them to the function. Additionally, you should supply the data that will replace the flag. Here’s an example for clarification:
675+
[Excel that used for example](https://github.com/mohammadrezaeicode/mr-excel-page-repo/blob/main/public/replacer.xlsx?raw=true)
676+
677+
<details>
678+
679+
<summary>Display Code</summary>
680+
681+
```javascript
682+
ExcelTable.excelToNode(Link, Replace Map,Replacer Map)
683+
-----
684+
ExcelTable.replaceInExcel("./replacer.xlsx", {
685+
V: "test Data",
686+
v1: "This is value one",
687+
v2: "This is value two",
688+
});
689+
```
690+
691+
</details>
692+
693+
![result imag](https://github.com/mohammadrezaeicode/mr-excel-page-repo/blob/main/public/img/replacer.png?raw=true)
694+
662695
<a id="excel-to-json-usage"></a>
663696

664-
### 🆕 How to use excelToJson
697+
### How to use excelToJson
665698

666699
<details>
667700

@@ -7156,6 +7189,24 @@ The primary interface of the library is located in the excel-table.d.ts file. [C
71567189

71577190
In this section, we define the significant changes that require migration for the upcoming version.
71587191

7192+
<a id="migrating-6"></a>
7193+
7194+
## Migrating from 6 to 7 [⬆️](#table-of-contents)
7195+
7196+
To successfully migrate from version 6 to version 7, you should update the following options:
7197+
7198+
- change in the interface of `MultiStyleValue`:
7199+
7200+
```
7201+
export interface MapMultiStyleValue {
7202+
[key: string]: MultiStyleValue[];
7203+
}
7204+
export interface MultiStyleValue {
7205+
value: string | number;
7206+
styleId?: string;
7207+
}
7208+
```
7209+
71597210
<a id="migrating-5"></a>
71607211

71617212
## Migrating from 5 to 6 [⬆️](#table-of-contents)
@@ -7226,8 +7277,22 @@ To migrate from Version 2 to Version 3, you need to follow the steps below:
72267277
- Change "backgroundColor" to "backgroundColor."
72277278
- Replace "color" with "color."
72287279

7280+
<a id="release-note"></a>
7281+
72297282
## Release Notes [⬆️](#table-of-contents)
72307283

7284+
#### New Features
7285+
7286+
- A drop-down option (multi-select option) provides the ability to create a cell that contains multiple selectable values.`sheet`->`[n]`->`dropDowns`
7287+
- The `replaceInExcel` functionality in Excel allows you to replace data in an existing file using flags provided within the spreadsheet.
7288+
7289+
#### Bug Fixes
7290+
7291+
- `generateExcel` supports empty objects and will generate an empty Excel file.
7292+
7293+
> [!NOTE]
7294+
> The related interface has not changed, so the sheet needs to be provided in TypeScript.
7295+
72317296
### Version 6.0.1 (2024-08-11)
72327297

72337298
#### New Features

_test_/__mocks__/file-saver.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { jest } from "@jest/globals";
2+
3+
export const saveAs = jest.fn();

_test_/__mocks__/xs.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { jest } from "@jest/globals";
2+
3+
const JSZip = jest.fn();
4+
5+
JSZip.mockImplementation(() => {
6+
return {
7+
loadAsync: jest.fn(),
8+
generateAsync: jest.fn<any>().mockResolvedValue({
9+
slice: jest.fn().mockReturnValue("mockedValue"),
10+
}), // Mocking generateAsync to return a resolved promise
11+
};
12+
});
13+
14+
export default JSZip; // Mocking the default export

_test_/src/functions/excel-to-json.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,63 @@ const mockedExtractExcelData = <jest.Mock<typeof extractExcelData>>(
1212
extractExcelData
1313
);
1414
describe("excel-to-node data tests", () => {
15+
test("excelToJson 2", async () => {
16+
jest.resetAllMocks();
17+
const map = new Map<string, string>();
18+
map.set("sheet1", "Sheet1");
19+
map.set("sheet2", "Sheet2");
20+
mockedExtractExcelData.mockReturnValue(
21+
Promise.resolve({
22+
data: {
23+
sheet1: [
24+
["test value for cell", "3"],
25+
,
26+
,
27+
["7", "6", "5", "4"],
28+
,
29+
,
30+
[, , , , , "h"],
31+
],
32+
Sheet2: [, , ["a"], , , [, , "e"]],
33+
},
34+
sheetName: map.entries(),
35+
sheetNameObject: {
36+
sheet1: "nameSheet",
37+
sheet2: "Sheet2",
38+
},
39+
maxLengthOfColumn: {
40+
sheet1: 5,
41+
Sheet2: 2,
42+
},
43+
} as ReadResult)
44+
);
45+
let result = await excelToJson(
46+
"https://github.com/mohammadrezaeicode/mr-excel-page-repo/blob/main/public/y.xlsx?raw=true"
47+
).catch((e: string) => {
48+
return e;
49+
});
50+
expect(extractExcelData).toBeCalledTimes(1);
51+
expect(result).toEqual({
52+
nameSheet: [
53+
{},
54+
{
55+
"3": "6",
56+
property3: "5",
57+
property4: "4",
58+
"test value for cell": "7",
59+
},
60+
{
61+
property6: "h",
62+
},
63+
],
64+
Sheet2: [
65+
{},
66+
{
67+
property3: "e",
68+
},
69+
],
70+
});
71+
}, 150000);
1572
test("excelToJson", async () => {
1673
jest.resetAllMocks();
1774
const map = new Map<string, string>();

_test_/src/functions/generate-csv-mocked-2.test.ts

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,95 @@ describe("generateCSV", () => {
5454
},
5555
true
5656
);
57-
expect(mockGenerateAsync).toHaveBeenCalledTimes(1);
57+
// expect(mockGenerateAsync).toHaveBeenCalledTimes(1);
5858
expect(saveAs).toHaveBeenCalledTimes(1);
5959
expect(result).toBe("done");
6060
});
61+
test("should create a zip and save it 2", async () => {
62+
let result = await generateCSV(
63+
{
64+
fileName:"test",
65+
sheet: [
66+
{
67+
data: [
68+
{ a: 1, b: "b1" },
69+
{ a: 2, b: "b2" },
70+
],
71+
headers: [
72+
{
73+
label: "a",
74+
text: "a",
75+
},
76+
{
77+
label: "b",
78+
text: "b",
79+
},
80+
],
81+
},
82+
],
83+
},
84+
true
85+
);
86+
// expect(mockGenerateAsync).toHaveBeenCalledTimes(1);
87+
expect(saveAs).toHaveBeenCalledTimes(1);
88+
expect(result).toBe("done");
89+
});
90+
test("should create a blob and save it", async () => {
91+
let result = await generateCSV(
92+
{
93+
sheet: [
94+
{
95+
data: [
96+
{ a: 1, b: "b1" },
97+
{ a: 2, b: "b2" },
98+
],
99+
headers: [
100+
{
101+
label: "a",
102+
text: "a",
103+
},
104+
{
105+
label: "b",
106+
text: "b",
107+
},
108+
],
109+
},
110+
],
111+
},
112+
false
113+
);
114+
// expect(mockGenerateAsync).toHaveBeenCalledTimes(1);
115+
expect(saveAs).toHaveBeenCalledTimes(1);
116+
expect(result).toBe(undefined);
117+
});
118+
test("should create a blob and save it 2", async () => {
119+
let result = await generateCSV(
120+
{
121+
fileName:"test",
122+
sheet: [
123+
{
124+
data: [
125+
{ a: 1, b: "b1" },
126+
{ a: 2, b: "b2" },
127+
],
128+
headers: [
129+
{
130+
label: "a",
131+
text: "a",
132+
},
133+
{
134+
label: "b",
135+
text: "b",
136+
},
137+
],
138+
},
139+
],
140+
},
141+
false,
142+
true
143+
);
144+
// expect(mockGenerateAsync).toHaveBeenCalledTimes(1);
145+
expect(saveAs).toHaveBeenCalledTimes(1);
146+
expect(result).toBe(undefined);
147+
});
61148
});

0 commit comments

Comments
 (0)