Skip to content

Commit a660528

Browse files
committed
init
1 parent 7954b41 commit a660528

File tree

14 files changed

+1164
-78
lines changed

14 files changed

+1164
-78
lines changed

.DS_Store

10 KB
Binary file not shown.

.github/workflows/publish.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Publish Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-node@v3
13+
with:
14+
node-version: '18.x'
15+
registry-url: 'https://registry.npmjs.org'
16+
17+
- name: Install dependencies
18+
run: npm ci
19+
20+
- name: Run tests
21+
run: npm test
22+
23+
publish-npm:
24+
needs: test
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v3
28+
- uses: actions/setup-node@v3
29+
with:
30+
node-version: '18.x'
31+
registry-url: 'https://registry.npmjs.org'
32+
33+
- name: Install dependencies
34+
run: npm ci
35+
36+
- name: Build
37+
run: npm run build
38+
39+
- name: Publish to NPM
40+
run: npm publish --access public
41+
env:
42+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
43+
44+
publish-gpr:
45+
needs: test
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v3
49+
- uses: actions/setup-node@v3
50+
with:
51+
node-version: '18.x'
52+
registry-url: 'https://npm.pkg.github.com'
53+
54+
- name: Install dependencies
55+
run: npm ci
56+
57+
- name: Build
58+
run: npm run build
59+
60+
- name: Publish to GitHub Packages
61+
run: npm publish
62+
env:
63+
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,6 @@ dist
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130130
.pnp.*
131+
132+
133+
result/*

README.md

Lines changed: 91 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,98 @@
1-
# Template node typescript
1+
# Excel Cursor
22

3-
## Getting Started
4-
Instructions for installing dependencies and running the app locally.
3+
Thư viện TypeScript giúp thao tác với file Excel một cách dễ dàng thông qua API dạng con trỏ (cursor).
4+
5+
## Cài đặt
56

67
```bash
7-
npm install
8-
npm run dev
8+
npm install excel-cursor
9+
# hoặc
10+
yarn add excel-cursor
911
```
1012

11-
## Project Structure
12-
Overview of the project files and directories.
13+
## Tính năng
1314

15+
- Di chuyển con trỏ linh hoạt trong file Excel
16+
- Đọc/ghi dữ liệu vào ô
17+
- Định dạng ô (font, màu sắc, căn lề)
18+
- Merge ô
19+
- Thêm/xóa hàng
20+
- Chuyển đổi giữa các worksheet
21+
- Hỗ trợ công thức Excel
22+
- Định dạng có điều kiện
23+
24+
## Sử dụng
25+
26+
```typescript
27+
import { Workbook } from 'exceljs';
28+
import { ExcelCursor } from 'excel-cursor';
29+
30+
// Khởi tạo workbook và cursor
31+
const workbook = new Workbook();
32+
const cursor = new ExcelCursor(workbook);
33+
34+
// Di chuyển và nhập dữ liệu
35+
cursor
36+
.move('A1')
37+
.setData('Hello')
38+
.nextRow()
39+
.setData('World')
40+
.formatCell({
41+
font: { bold: true },
42+
alignment: { vertical: 'middle', horizontal: 'center' }
43+
});
44+
45+
// Lưu file
46+
await workbook.xlsx.writeFile('output.xlsx');
1447
```
15-
src/ - TypeScript source code
16-
dist/ - Compiled JavaScript output
17-
test/ - Unit tests
18-
```
19-
## Scripts
20-
Explanation of the main NPM scripts for development.
21-
22-
dev - Starts the app in development mode with live reloading
23-
build - Compiles TypeScript to JavaScript
24-
start - Runs the compiled app
25-
test - Runs unit tests
26-
Deployment
27-
Notes on how to deploy the app to production.
28-
29-
# Built With
30-
Node.js - JavaScript runtime
31-
TypeScript - Typed superset of JavaScript
32-
# License
33-
Overview of license used for the project.
34-
35-
# Acknowledgments
36-
Shoutouts to tutorials, libraries, and resources that were helpful.
37-
38-
Let me know if you would like me to expand or modify this suggested README. I aimed to provide a high-level overview based on the context provided.
48+
49+
## API
50+
51+
### Di chuyển con trỏ
52+
53+
- `move(address: string)`: Di chuyển đến địa chỉ ô cụ thể (vd: 'A1')
54+
- `moveTo(row: number, col: number)`: Di chuyển đến vị trí hàng và cột
55+
- `nextRow(n = 1)`: Di chuyển xuống n hàng
56+
- `prevRow(n = 1)`: Di chuyển lên n hàng
57+
- `nextCol(n = 1)`: Di chuyển sang phải n cột
58+
- `prevCol(n = 1)`: Di chuyển sang trái n cột
59+
60+
### Thao tác dữ liệu
61+
62+
- `setData(data: any, address?: string)`: Ghi dữ liệu vào ô hiện tại hoặc ô chỉ định
63+
- `setFormula(formula: string, address?: string)`: Đặt công thức cho ô
64+
- `formatCell(format: CellFormat, address?: string)`: Định dạng ô
65+
66+
### Định dạng
67+
68+
- `colSpan(n: number, address?: string)`: Merge n cột từ vị trí hiện tại
69+
- `rowSpan(n: number, address?: string)`: Merge n hàng từ vị trí hiện tại
70+
- `setColWidth(width: number, colOrAddress?: number | string)`: Đặt độ rộng cột
71+
- `setRowHeight(height: number, rowOrAddress?: number | string)`: Đặt chiều cao hàng
72+
73+
### Worksheet
74+
75+
- `switchSheet(sheetName: string)`: Chuyển sang worksheet khác
76+
- `createSheet(sheetName: string)`: Tạo worksheet mới
77+
78+
## Đóng góp
79+
80+
Mọi đóng góp đều được hoan nghênh! Vui lòng:
81+
82+
1. Fork dự án
83+
2. Tạo branch cho tính năng (`git checkout -b feature/amazing-feature`)
84+
3. Commit thay đổi (`git commit -m 'Add some amazing feature'`)
85+
4. Push lên branch (`git push origin feature/amazing-feature`)
86+
5. Tạo Pull Request
87+
88+
## Giấy phép
89+
90+
Dự án này được phân phối dưới giấy phép MIT. Xem file `LICENSE` để biết thêm chi tiết.
91+
92+
## Tác giả
93+
94+
Nguyễn Văn A - [@nguyenvana](https://github.com/nguyenvana)
95+
96+
## Hỗ trợ
97+
98+
Nếu bạn gặp vấn đề hoặc có câu hỏi, vui lòng tạo issue trong repository.

example/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { stream } from 'exceljs';
2+
3+
import { ExcelCursor } from '../src/index';
4+
5+
async function main() {
6+
// construct a streaming XLSX workbook writer with styles and shared strings
7+
const options = {
8+
filename: './result/streamed-workbook.xlsx',
9+
useStyles: true,
10+
useSharedStrings: true,
11+
};
12+
const workbook = new stream.xlsx.WorkbookWriter(options);
13+
14+
const cursor = new ExcelCursor(workbook, 'Sheet1');
15+
16+
cursor.move('A1').setData('Hello, World!');
17+
18+
cursor.move('B2').setData('ExcelJS Cursor Example');
19+
20+
cursor.move('C3').setData('This is a test.');
21+
22+
for (let i = 0; i < 1000; i++) {
23+
cursor
24+
.move('A' + (i + 4))
25+
.setData('Row ' + (i + 1))
26+
.addComment('This is a comment')
27+
.nextCol(1)
28+
// .setData('Column ' + (i + 1))
29+
.setFormula('=1+2');
30+
}
31+
32+
cursor.commit();
33+
}
34+
35+
main();

package.json

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "template-nodejs-typescript",
2+
"name": "excel-cursor",
33
"version": "1.0.0",
4-
"description": "",
4+
"description": "A powerful and flexible Excel manipulation library with cursor-based navigation",
55
"main": "./dist/cjs/index.js",
66
"types": "./dist/esm/index.d.ts",
77
"module": "./dist/esm/index.js",
@@ -17,49 +17,51 @@
1717
},
1818
"scripts": {
1919
"build": "npm run clean && tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json",
20+
"build:watch": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json --watch",
2021
"clean": "rimraf dist/",
21-
"dev": "nodemon --quiet",
22+
"dev": "nodemon",
2223
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
2324
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
24-
"start": "node ./dist/cjs/index.js",
25-
"start:dev": "yarn build && node ./dist/cjs/index.js",
26-
"test:cov": "jest --coverage",
25+
"test": "jest",
2726
"test:watch": "jest --watch",
28-
"test": "jest"
27+
"test:cov": "jest --coverage",
28+
"prepare": "npm run build",
29+
"example": "ts-node ./example/index.ts"
2930
},
31+
"keywords": [
32+
"excel",
33+
"exceljs",
34+
"spreadsheet",
35+
"cursor",
36+
"excel-manipulation",
37+
"typescript"
38+
],
3039
"author": "npv2k1",
3140
"license": "MIT",
3241
"dependencies": {
33-
"dotenv": "^16.3.1",
42+
"exceljs": "^4.4.0",
3443
"lodash": "^4.17.21"
3544
},
3645
"devDependencies": {
37-
"@swc/cli": "^0.1.62",
38-
"@swc/core": "^1.3.74",
39-
"@swc/helpers": "^0.5.1",
4046
"@types/jest": "28.1.6",
4147
"@types/lodash": "^4.14.197",
4248
"@types/node": "^18.16.19",
4349
"@typescript-eslint/eslint-plugin": "5.30.7",
4450
"@typescript-eslint/parser": "5.30.7",
45-
"concurrently": "^7.6.0",
46-
"copyfiles": "^2.4.1",
4751
"cross-env": "^7.0.3",
4852
"eslint": "8.20.0",
4953
"eslint-config-prettier": "8.5.0",
5054
"eslint-plugin-prettier": "4.2.1",
51-
"eslint-plugin-simple-import-sort": "^10.0.0",
5255
"jest": "28.1.3",
5356
"nodemon": "^2.0.22",
5457
"prettier": "2.7.1",
55-
"regenerator-runtime": "^0.13.11",
5658
"rimraf": "^3.0.2",
5759
"ts-jest": "28.0.7",
5860
"ts-node": "^10.9.1",
59-
"ts-node-dev": "^2.0.0",
6061
"tsconfig-paths": "^4.2.0",
61-
"tslib": "^2.6.0",
62-
"typescript": "4.7.4",
63-
"unbuild": "^1.2.1"
62+
"typescript": "4.7.4"
63+
},
64+
"peerDependencies": {
65+
"exceljs": "^4.4.0"
6466
}
6567
}

0 commit comments

Comments
 (0)