Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(demo): demo data

dushusire7e74592b326
diff --git a/.github/contributing-zh.md b/.github/contributing-zh.md
index a1b4698bc8..aaaee9cec1 100644
--- a/.github/contributing-zh.md
+++ b/.github/contributing-zh.md
@@ -152,7 +152,28 @@ pnpm install
}
```
-3. 变量名、方法名等取名字应该遵循的规则是,在表达清楚含义的前提下尽量简洁。推荐使用完整的单词,切勿使用汉字、拼音,如果想不到好的单词,可以到 [codelf](https://unbug.github.io/codelf/) 搜索下。
+3. 如果一个私有方法 `_funcUse`调用了另一个私有方法 `_func`,但是后续开发中需要公开 `_func` 提供的功能,我们建议另外包装一个公共方法出来,比如
+
+ ```ts
+ class MyClass {
+ // 私有
+ private _func() {}
+
+ // 公用
+ func() {
+ this._func()
+ }
+
+ private _funcUse() {
+ // 私有的方法调用私有的方法
+ this._func()
+
+ // 其它逻辑
+ }
+ }
+ ```
+
+4. 变量名、方法名等取名字应该遵循的规则是,在表达清楚含义的前提下尽量简洁。推荐使用完整的单词,切勿使用汉字、拼音,如果想不到好的单词,可以到 [codelf](https://unbug.github.io/codelf/) 搜索下。
### 语言特性
@@ -272,6 +293,8 @@ pnpm install
5. Action 默认情况下需要加入撤销重做栈、发送后台、修改本地数据,但是有的操作可能不需要撤销重做或者发送协同后台,这时候要配置 operationType。比如:切换 sheet 页,不需要发送协同;切换选区功能,不需要进撤销重做栈。
+6. 不要直接使用 `console.log` 原生方法,推荐使用 `Logger` 静态类提供的方法来打印日志,便于我们对日志进行更精细的控制。
+
## 能力扩展
核心能力的扩展,依靠 Plugin、Registry 和 Register 来提供
diff --git a/examples/univer-preact-ts/index.html b/examples/univer-preact-ts/index.html
index 89009a3eaf..90f44663a3 100644
--- a/examples/univer-preact-ts/index.html
+++ b/examples/univer-preact-ts/index.html
@@ -16,7 +16,8 @@
<body>
<div id="app" style="z-index: 1; position: fixed; font-size: 20px; color: green;"></div>
- <div id="universheet-demo" style="height: 100%;"></div>
+ <div id="universheet-demo" style="height: 50vh;"></div>
+ <div id="universheet-demo-down" style="height: 50vh;"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
diff --git a/examples/univer-preact-ts/package.json b/examples/univer-preact-ts/package.json
index b345e7e577..80df7e61ea 100644
--- a/examples/univer-preact-ts/package.json
+++ b/examples/univer-preact-ts/package.json
@@ -44,6 +44,7 @@
"vite-plugin-external": "1.2.3"
},
"dependencies": {
+ "@univer/base-component": "workspace:^0.0.1",
"@univer/base-docs": "workspace:^0.0.1",
"@univer/base-render": "workspace:^0.0.1",
"@univer/base-sheets": "workspace:^0.0.1",
@@ -52,6 +53,7 @@
"@univer/core": "workspace:^0.0.1",
"@univer/sheets-plugin-clipboard": "workspace:^0.0.1",
"@univer/sheets-plugin-formula": "workspace:^0.0.1",
+ "@univer/sheets-plugin-import-xlsx": "workspace:^0.0.1",
"@univer/sheets-plugin-numfmt": "workspace:^0.0.1",
"@univer/style-universheet": "workspace:^0.0.1",
"preact": "^10.5.14"
diff --git a/examples/univer-preact-ts/src/index.ts b/examples/univer-preact-ts/src/index.ts
index cd9ca71e00..b7665c920e 100644
--- a/examples/univer-preact-ts/src/index.ts
+++ b/examples/univer-preact-ts/src/index.ts
@@ -1,6 +1,6 @@
import { IDocumentData, ISlideData, IWorkbookConfig, UniverDoc, UniverSheet, UniverSlide } from '@univer/core';
-import * as UniverCore from '@univer/core';
import { RenderEngine } from '@univer/base-render';
+import { BaseComponentPlugin } from '@univer/base-component';
import { UniverComponentSheet } from '@univer/style-universheet';
import { ISheetPluginConfig, SheetPlugin } from '@univer/base-sheets';
import { IDocPluginConfig, DocPlugin } from '@univer/base-docs';
@@ -9,6 +9,7 @@ import { DEFAULT_WORKBOOK_DATA } from '@univer/common-plugin-data';
import { DEFAULT_FORMULA_DATA, FormulaPlugin, IFormulaConfig } from '@univer/sheets-plugin-formula';
import { INumfmtPluginConfig, NumfmtPlugin } from '@univer/sheets-plugin-numfmt';
import { ClipboardPlugin } from '@univer/sheets-plugin-clipboard';
+import { ImportXlsxPlugin } from '@univer/sheets-plugin-import-xlsx';
interface ISheetPropsCustom {
coreConfig?: Partial<IWorkbookConfig>;
@@ -28,10 +29,12 @@ class UniverSheetCustom {
universheet.installPlugin(new RenderEngine());
universheet.installPlugin(new UniverComponentSheet());
universheet.installPlugin(new SheetPlugin(config.baseSheetsConfig));
+ universheet.installPlugin(new BaseComponentPlugin());
universheet.installPlugin(new NumfmtPlugin(config.numfmtConfig));
FormulaPlugin.create(config.formulaConfig).installTo(universheet);
universheet.installPlugin(new ClipboardPlugin());
+ universheet.installPlugin(new ImportXlsxPlugin());
return universheet;
}
@@ -103,4 +106,17 @@ const univerSlideCustom = function (config?: ISlidePropsCustom) {
return new UniverSlideCustom().init(config);
};
-export { UniverCore, univerSheetCustom, univerDocCustom, univerSlideCustom, DEFAULT_WORKBOOK_DATA, DEFAULT_FORMULA_DATA };
+export { univerSheetCustom, univerDocCustom, univerSlideCustom };
+
+export * as UniverCore from '@univer/core';
+export * as BaseRender from '@univer/base-render';
+export * as BaseComponent from '@univer/base-component';
+export * as StyleUniver from '@univer/style-universheet';
+export * as BaseSheets from '@univer/base-sheets';
+export * as BaseDocs from '@univer/base-docs';
+export * as BaseSlides from '@univer/base-slides';
+export * as CommonPluginData from '@univer/common-plugin-data';
+export * as SheetsPluginFormula from '@univer/sheets-plugin-formula';
+export * as SheetsPluginNumfmt from '@univer/sheets-plugin-numfmt';
+export * as SheetsPluginClipboard from '@univer/sheets-plugin-clipboard';
+export * as SheetsPluginImportXlsx from '@univer/sheets-plugin-import-xlsx';
diff --git a/examples/univer-preact-ts/src/main.tsx b/examples/univer-preact-ts/src/main.tsx
index 9c7bcc946a..12ea03d16a 100644
--- a/examples/univer-preact-ts/src/main.tsx
+++ b/examples/univer-preact-ts/src/main.tsx
@@ -1,38 +1,178 @@
-import { univerSheetCustom, DEFAULT_WORKBOOK_DATA } from '.';
+import { DEFAULT_WORKBOOK_DATA, DEFAULT_WORKBOOK_DATA_DOWN } from '@univer/common-plugin-data';
+import { IWorkbookConfig, IWorksheetConfig, SheetTypes, Tools } from '@univer/core';
+import { univerSheetCustom } from '.';
-const sheetConfig = {
- container: 'universheet-demo',
- layout: {
- innerRight: false,
- outerLeft: false,
- toolBarConfig: {
- paintFormat: false,
- currencyFormat: false,
- percentageFormat: false,
- numberDecrease: false,
- numberIncrease: false,
- moreFormats: false,
+ const sheetConfig = {
+ container:'universheet-demo',
+ layout: {
+ sheetContainerConfig:{
+ infoBar:false,
+ formulaBar:false,
+ toolBar:false,
+ sheetBar:false,
+ countBar:false,
+ rightMenu:false,
+ },
},
- },
- selections: {
- 'sheet-01': [
- {
- selection: {
- startRow: 0,
- endRow: 0,
- startColumn: 3,
- endColumn: 3,
- },
- cell: {
- row: 0,
- column: 3,
+ selections: {
+ 'sheet-01': [
+ {
+ selection: {
+ startRow: 0,
+ endRow: 0,
+ startColumn: 3,
+ endColumn: 3,
+ },
+ cell: {
+ row: 0,
+ column: 3,
+ },
},
+ ],
+ },
+ };
+
+ let columnCount = 8
+ if(window.innerWidth < 1366){
+ columnCount = 5;
+ }
+ const defaultWorkbookData = Tools.deepClone(DEFAULT_WORKBOOK_DATA);
+ defaultWorkbookData.id = 'workbook-01';
+ defaultWorkbookData.styles = null;
+ defaultWorkbookData.namedRanges = null;
+ defaultWorkbookData.sheets = {
+ 'sheet-01':{
+ type: 0,
+ id: 'sheet-01',
+ name: 'sheet1',
+ columnCount,
+ status:1,
+ cellData:{
+ '0':{
+ '0':{
+ m:'',
+ v:''
+ }
+ }
+ }
+ }
+ };
+
+ // univerSheetCustom({
+ // coreConfig:defaultWorkbookData,
+ // baseSheetsConfig: sheetConfig,
+ // });
+
+ const sheetConfigDown = {
+ container:'universheet-demo-down',
+ layout: {
+ sheetContainerConfig:{
+ infoBar:false,
+ formulaBar:false,
+ toolBar:false,
+ sheetBar:true,
+ countBar:false,
+ rightMenu:false,
},
- ],
- },
-};
+ },
+ selections: {
+ 'sheet-001': [
+ {
+ selection: {
+ startRow: 0,
+ endRow: 0,
+ startColumn: 0,
+ endColumn: 0,
+ },
+ cell: {
+ row: 0,
+ column: 0,
+ },
+ },
+ ],
+ },
+ };
+
+ const defaultWorkbookDataDown = Tools.deepClone(DEFAULT_WORKBOOK_DATA_DOWN);
+ defaultWorkbookDataDown.id = 'workbook-02';
+ defaultWorkbookDataDown.styles = null;
+ defaultWorkbookDataDown.namedRanges = null;
+ defaultWorkbookDataDown.sheets = {
+ 'sheet-001':{
+ type: 0,
+ id: 'sheet-001',
+ name: 'sheet001',
+ columnCount,
+ status:1
+ },
+ 'sheet-002':{
+ type: 0,
+ id: 'sheet-002',
+ name: 'sheet002',
+ columnCount:columnCount+10,
+ }
+ };
+
+ univerSheetCustom({
+ coreConfig:defaultWorkbookDataDown,
+ baseSheetsConfig: sheetConfigDown,
+ });
-univerSheetCustom({
- coreConfig: DEFAULT_WORKBOOK_DATA,
- baseSheetsConfig: sheetConfig,
-});
\ No newline at end of file
+// run('universheet-demo')
+// run('universheet-demo-down')
+// function run(container:string) {
+// const sheetConfig = {
+// container,
+// layout: {
+// innerRight: false,
+// outerLeft: false,
+// toolBarConfig: {
+// paintFormat: false,
+// currencyFormat: false,
+// percentageFormat: false,
+// numberDecrease: false,
+// numberIncrease: false,
+// moreFormats: false,
+// },
+// },
+// selections: {
+// 'sheet-01': [
+// {
+// selection: {
+// startRow: 0,
+// endRow: 0,
+// startColumn: 3,
+// endColumn: 3,
+// },
+// cell: {
+// row: 0,
+// column: 3,
+// },
+// },
+// ],
+// },
+// };
+
+// let columnCount = 8
+// if(window.innerWidth < 1366){
+// columnCount = 5;
+// }
+// const defaultWorkbookData = Tools.deepClone(DEFAULT_WORKBOOK_DATA);
+// defaultWorkbookData.id = Tools.generateRandomId();
+// defaultWorkbookData.styles = null;
+// defaultWorkbookData.namedRanges = null;
+// defaultWorkbookData.sheets = {
+// 'sheet-01':{
+// type: 0,
+// id: 'sheet-01',
+// name: 'sheet1',
+// columnCount,
+// status:1
+// }
+// };
+
+// univerSheetCustom({
+// coreConfig:defaultWorkbookData,
+// baseSheetsConfig: sheetConfig,
+// });
+// }
diff --git a/packages/base-formula-engine/src/FormulaEnginePlugin.tsx b/packages/base-formula-engine/src/FormulaEnginePlugin.tsx
index f66747903d..bc8a0b202c 100644
--- a/packages/base-formula-engine/src/FormulaEnginePlugin.tsx
+++ b/packages/base-formula-engine/src/FormulaEnginePlugin.tsx
@@ -16,7 +16,7 @@ interface FormulaEngineConfig {}
export class FormulaEnginePlugin extends Plugin<FormulaEnginePluginObserver> {
constructor(config?: IFormulaEnginePlugin) {
- super('pluginFormulaEngine');
+ super('formulaEngine');
}
/**
*
diff --git a/packages/base-sheets/src/SheetPlugin.tsx b/packages/base-sheets/src/SheetPlugin.tsx
index 72a99f40bf..a0923cfeca 100644
--- a/packages/base-sheets/src/SheetPlugin.tsx
+++ b/packages/base-sheets/src/SheetPlugin.tsx
@@ -342,11 +342,11 @@ export class SheetPlugin extends Plugin<SheetPluginObserve, SheetContext> {
}
addRightMenu(item: RightMenuProps[] | RightMenuProps) {
- this._rightMenuControl.addItem(item);
+ this._rightMenuControl && this._rightMenuControl.addItem(item);
}
addToolButton(config: IToolBarItemProps) {
- this._toolBarControl.addToolButton(config);
+ this._toolBarControl && this._toolBarControl.addToolButton(config);
}
registerComponent(name: string, component: any, props?: any) {
diff --git a/packages/base-sheets/src/View/Render/Views/SheetView.ts b/packages/base-sheets/src/View/Render/Views/SheetView.ts
index 94326a4b95..8f6dcee418 100644
--- a/packages/base-sheets/src/View/Render/Views/SheetView.ts
+++ b/packages/base-sheets/src/View/Render/Views/SheetView.ts
@@ -62,8 +62,10 @@ export class SheetView extends BaseView {
scene.addObjects([spreadsheet], 0);
scene.addObjects([spreadsheetRowTitle, spreadsheetColumnTitle, SpreadsheetLeftTopPlaceholder], 2);
scene.transformByState({
- width: this._columnWidthByTitle(worksheet) + columnTotalWidth + 100,
- height: this._rowHeightByTitle(worksheet) + rowTotalHeight + 200,
+ width: this._columnWidthByTitle(worksheet),
+ height: this._rowHeightByTitle(worksheet) + rowTotalHeight,
+ // width: this._columnWidthByTitle(worksheet) + columnTotalWidth + 100,
+ // height: this._rowHeightByTitle(worksheet) + rowTotalHeight + 200,
});
this._updateViewport(rowTitleWidth, columnTitleHeight);
@@ -114,8 +116,10 @@ export class SheetView extends BaseView {
});
scene.transformByState({
- width: this._columnWidthByTitle(worksheet) + columnTotalWidth + 100,
- height: this._rowHeightByTitle(worksheet) + rowTotalHeight + 200,
+ width: this._columnWidthByTitle(worksheet),
+ height: this._rowHeightByTitle(worksheet)+rowTotalHeight,
+ // width: this._columnWidthByTitle(worksheet) + columnTotalWidth + 100,
+ // height: this._rowHeightByTitle(worksheet) + rowTotalHeight + 200,
});
this._updateViewport(rowTitleWidth, columnTitleHeight);
this._selectionManager.updateToSheet(worksheet);
diff --git a/packages/base-sheets/src/main.tsx b/packages/base-sheets/src/main.tsx
index d6f970974a..b0cf28093a 100644
--- a/packages/base-sheets/src/main.tsx
+++ b/packages/base-sheets/src/main.tsx
@@ -9,15 +9,13 @@ import { SheetPlugin } from './SheetPlugin';
const uiDefaultConfigUp = {
container: 'universheet-demo-up',
layout: {
- innerRight: false,
- outerLeft: false,
- toolBarConfig: {
- paintFormat: false,
- currencyFormat: false,
- percentageFormat: false,
- numberDecrease: false,
- numberIncrease: false,
- moreFormats: false,
+ sheetContainerConfig:{
+ infoBar:true,
+ formulaBar:true,
+ toolBar:true,
+ sheetBar:true,
+ countBar:true,
+ rightMenu:true,
},
},
@@ -36,58 +34,6 @@ const uiDefaultConfigUp = {
},
},
],
- // 'sheet-01': [
- // {
- // selection: {
- // startRow: 13,
- // endRow: 14,
- // startColumn: 1,
- // endColumn: 2,
- // },
- // },
- // {
- // selection: {
- // startRow: 16,
- // endRow: 18,
- // startColumn: 1,
- // endColumn: 2,
- // },
- // cell: {
- // row: 16,
- // column: 1,
- // },
- // },
- // ],
- // 'sheet-02': [
- // {
- // selection: {
- // startRow: 17,
- // endRow: 20,
- // startColumn: 1,
- // endColumn: 2,
- // },
- // },
- // {
- // selection: {
- // startRow: 22,
- // endRow: 23,
- // startColumn: 1,
- // endColumn: 2,
- // },
- // },
- // {
- // selection: {
- // startRow: 25,
- // endRow: 27,
- // startColumn: 4,
- // endColumn: 6,
- // },
- // cell: {
- // row: 25,
- // column: 4,
- // },
- // },
- // ],
},
};
@@ -105,6 +51,16 @@ FormulaPlugin.create(DEFAULT_FORMULA_DATA).installTo(univerSheetUp);
const uiDefaultConfigDown = {
container: 'universheet-demo-down',
+ layout:{
+ sheetContainerConfig:{
+ infoBar:true,
+ formulaBar:true,
+ toolBar:true,
+ sheetBar:true,
+ countBar:true,
+ rightMenu:true,
+ },
+ },
selections: {
'sheet-0001': [
{
diff --git a/packages/core/src/Shared/Migrate/Migrate.ts b/packages/core/src/Shared/Migrate/Migrate.ts
index a3cbac1293..deaedd9121 100644
--- a/packages/core/src/Shared/Migrate/Migrate.ts
+++ b/packages/core/src/Shared/Migrate/Migrate.ts
@@ -45,7 +45,7 @@ export function migrate(config: any): Partial<IWorkbookConfig> {
// 是否激活
if (sheet.hasOwnProperty('status')) {
- newSheet.status = sheet.status;
+ newSheet.status = parseInt(sheet.status);
}
// sheet 名称
diff --git a/packages/core/src/Shared/Tools.ts b/packages/core/src/Shared/Tools.ts
index 200215d770..c2faa4c89a 100644
--- a/packages/core/src/Shared/Tools.ts
+++ b/packages/core/src/Shared/Tools.ts
@@ -664,4 +664,15 @@ export class Tools {
return resultJsonObject as unknown as T;
}
+
+ static arrayToObject(array:IKeyValue[][]){
+ const obj = {}
+ array.forEach((row,i)=>{
+ obj[i] = {}
+ row.forEach((column,j)=>{
+ obj[i][j] =column
+ })
+ })
+ return obj
+ }
}
diff --git a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
index 5f7c78ef77..5db4d5711f 100644
--- a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
+++ b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
@@ -35,7 +35,7 @@ export class FormulaPlugin extends Plugin<FormulaPluginObserve, SheetContext> {
universheetInstance.installPlugin(this);
const context = this.getContext();
- let formulaEngine = context.getPluginManager().getPluginByName<FormulaEnginePlugin>('pluginFormulaEngine');
+ let formulaEngine = context.getPluginManager().getPluginByName<FormulaEnginePlugin>('formulaEngine');
if (!formulaEngine) {
formulaEngine = new FormulaEnginePlugin();
universheetInstance.installPlugin(formulaEngine);
diff --git a/packages/sheets-plugin-import-xlsx/src/Basic/Register/DragAndDropExtension.ts b/packages/sheets-plugin-import-xlsx/src/Basic/Register/DragAndDropExtension.ts
index 93a24fd128..cb821a9325 100644
--- a/packages/sheets-plugin-import-xlsx/src/Basic/Register/DragAndDropExtension.ts
+++ b/packages/sheets-plugin-import-xlsx/src/Basic/Register/DragAndDropExtension.ts
@@ -3,8 +3,6 @@ import { ImportXlsxPlugin } from '../../ImportXlsxPlugin';
export class DragAndDropExtension extends BaseDragAndDropExtension<ImportXlsxPlugin> {
execute() {
- console.log('this._data----', this._data);
-
this._plugin.getImportXlsxController().handleFiles(this._data);
}
}