Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: migrate luckysheet guide #124

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The complete cell information is as follows.
| p | Rich text, also a 📝 Univer Doc |
| f | Formula |
| si | Formula id |
| custom | Custom field |

Check out the type information of each field of [ICellData](/api/core/interfaces/ICellData.html).

Expand Down Expand Up @@ -420,7 +421,7 @@ If the cell is a boolean type, the value of `cellData.v` is stored as `0` or `1`
cellData: {
0: {
0: {
f: '=SUM(A1:B1)' // Sum formula
f: '=SUM(A1:B1)' // function SUM
},
},
}
Expand All @@ -432,7 +433,7 @@ If the cell is a boolean type, the value of `cellData.v` is stored as `0` or `1`
`cellData.si` is a string that represents the formula ID. Univer Sheet supports reference optimization for formulas. After the current formula is associated with `si` in the cell, other cells can refer to the current formula through `si`.

```typescript
// IWorkbookData
// IWorksheetData
{
cellData: {
0: {
Expand All @@ -447,3 +448,22 @@ If the cell is a boolean type, the value of `cellData.v` is stored as `0` or `1`
}
}
```

### Custom Field

`cellData.custom` is an object that represents a custom field. You can put any data that complies with the JSON format into it to customize the storage of some additional information.

```typescript
// IWorksheetData
{
cellData: {
0: {
0: {
custom: {
key: 'value'
}
},
},
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: Migrate Luckysheet
sidebar:
order: 3
---

Compared with Luckysheet, our newly designed Univer has made great improvements in terms of architecture, data structure and API, so Luckysheet can no longer be migrated 1:1 to Univer.

However, basic data types or APIs can be found in Univer. In view of this, if you still want to migrate Luckysheet data to Univer, you can do some targeted adaptation work according to your needs.

Here is a migration guide for everyone.

## Analysis

### Configuration

The core work of the conversion is to adapt the workbook configuration, worksheet configuration and cell information. You can refer to the Univer interface and Luckysheet data structure.

| | Univer | Luckysheet |
|-------|----------------|------------|
| Workbook configuration | [IWorkbookData](/api/core/interfaces/IWorkbookData.html) | [Overall Configuration](https://dream-num.github.io/LuckysheetDocs/guide/config.html) |
| Worksheet configuration | [IWorksheetData](/api/core/interfaces/IWorksheetData.html) | [Sheet Configuration](https://dream-num.github.io/LuckysheetDocs/guide/sheet.html) |
| Cell | [ICellData](/api/core/interfaces/ICellData.html) | [Cell Attributes](https://dream-num.github.io/LuckysheetDocs/guide/cell.html) |

### Plugin

Luckysheet is initialized through a JSON configuration, while Univer is split, the enhanced functions are implemented with plugins, so some functions need to be dispersed into plugin configurations, such as

| | Univer | Luckysheet |
|-------|----------------|------------|
| Conditional formatting | [@univerjs/sheets-conditional-formatting](/api/sheets-conditional-formatting/) | [luckysheet_conditionformat_save](https://dream-num.github.io/LuckysheetDocs/guide/sheet.html#luckysheet-conditionformat-save) |
| Data validation | [@univerjs/sheets-data-validation](/api/sheets-data-validation/) | [dataverification](https://dream-num.github.io/LuckysheetDocs/zh/guide/sheet.html#dataverification) |

More plugins [Reference](/api/)

### API

For the API part, Luckysheet API is uniformly mounted on `window.luckysheet`, there are two ways to use Univer API

- Call the encapsulated [Facade API](/guides/facade/)
- Use Univer's dependency injection system to inject the plugin's service capabilities into the current Class. Refer to our [Plugin Tutorial](/guides/tutorials/csv-import-plugin/) to easily access the Univer dependency injection system

## Summary

For some commonly used basic data, you can refer to [Migrate Luckysheet Demo](/playground?title=Migrate%20Luckysheet) and customize it according to project requirements.

If Univer's existing functions do not meet your needs, you can also develop your own plugin for adaptation.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Univer Sheet 中的单元格数据存储在 [IWorksheetData](/api/core/interface
| p | 富文本,同时也是一个 📝 Univer Doc |
| f | 公式 |
| si | 公式 ID |
| custom | 自定义字段 |

详细了解 [ICellData](/api/core/interfaces/ICellData.html) 每个字段的类型信息。

Expand Down Expand Up @@ -430,7 +431,7 @@ Univer Sheet 中的单元格数据存储在 [IWorksheetData](/api/core/interface
`cellData.si` 是一个字符串,表示公式 ID。Univer Sheet 支持对公式做引用优化,单元格中用 si 关联上当前公式后,其他单元格可以通过 si 引用到当前公式。

```typescript
// IWorkbookData
// IWorksheetData
{
cellData: {
0: {
Expand All @@ -445,3 +446,22 @@ Univer Sheet 中的单元格数据存储在 [IWorksheetData](/api/core/interface
}
}
```

### 自定义字段

`cellData.custom` 是一个对象,表示自定义字段。其中可以放入任何符合 JSON 格式的数据,用于自定义存储一些额外的信息。

```typescript
// IWorksheetData
{
cellData: {
0: {
0: {
custom: {
key: 'value'
}
},
},
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: 迁移 Luckysheet
sidebar:
order: 3
---

我们新设计的 Univer,相比较 Luckysheet,从架构、数据结构以及 API 等方面做了很大改进设计,所以 Luckysheet 已经无法 1 比 1 迁移到 Univer。

不过基本的数据类型或者 API 都可以在 Univer 中找到,鉴于此,如果您仍然想要将 Luckysheet 的数据要迁移到 Univer,可以根据自己的需求,有针对性的做一些适配工作。

这里给大家提供一个迁移指导方案。

## 分析

### 配置

转换最核心的工作是对工作簿配置、工作表配置以及单元格信息进行适配,可以参考 Univer 的接口和 Luckysheet 的数据结构。

| | Univer | Luckysheet |
|-------|----------------|------------|
| 工作簿配置 | [IWorkbookData](/api/core/interfaces/IWorkbookData.html) | [总体配置](https://dream-num.github.io/LuckysheetDocs/zh/guide/config.html) |
| 工作表配置 | [IWorksheetData](/api/core/interfaces/IWorksheetData.html) | [工作表配置](https://dream-num.github.io/LuckysheetDocs/zh/guide/sheet.html) |
| 单元格 | [ICellData](/api/core/interfaces/ICellData.html) | [单元格](https://dream-num.github.io/LuckysheetDocs/zh/guide/cell.html) |

### 插件

Luckysheet 的初始化通过一个 JSON 配置来完成,而 Univer 做了拆分,将增强功能用插件来实现,所以部分功能需要分散到插件配置,比如

| | Univer | Luckysheet |
|-------|----------------|------------|
| 条件格式 | [@univerjs/sheets-conditional-formatting](/zh-cn/api/sheets-conditional-formatting/) | [luckysheet_conditionformat_save](https://dream-num.github.io/LuckysheetDocs/zh/guide/sheet.html#luckysheet-conditionformat-save) |
| 数据验证 | [@univerjs/sheets-data-validation](/zh-cn/api/sheets-data-validation/) | [dataverification](https://dream-num.github.io/LuckysheetDocs/zh/guide/sheet.html#dataverification) |

更多插件 [参考](/api/)

### API

对于 API 部分,Luckysheet API 统一挂载在 `window.luckysheet`,使用 Univer API 有两种方式

- 调用封装好的 [Facade API](/zh-cn/guides/facade/)
- 采用 Univer 的依赖注入系统,将插件的 service 能力注入到当前 Class 中,参考我们的 [插件教程](/zh-cn/guides/tutorials/csv-import-plugin/) 可以轻松的接入 Univer 依赖注入系统

## 总结

针对部分常用的基础数据,可以参考下 [Migrate Luckysheet Demo](/playground?title=Migrate%20Luckysheet),再根据项目需求做定制。

如果 Univer 现有功能不满足您的需要,还可以自行开发插件进行适配。
8 changes: 8 additions & 0 deletions packages/community/src/pages/playground.astro
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ const children: IEmbedProps[] = [
openFile: 'src/main.ts',
},
},
{
title: 'Migrate Luckysheet',
type: 'StackBlitz',
repoPath: 'awesome-univer/migrate-luckysheet',
openOptions: {
openFile: 'src/main.ts',
},
},
]

const demo = [
Expand Down
Loading
Loading