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

feat: add the min rowCount & columnCount of the default workbookData #59

Merged
merged 3 commits into from
Apr 19, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@univerjs/engine-render": "^0.1.7",
"@univerjs/facade": "^0.1.7",
"@univerjs/find-replace": "^0.1.7",
"@univerjs/protocol": "^0.1.17",
"@univerjs/protocol": "^0.1.18",
"@univerjs/rpc": "^0.1.7",
"@univerjs/sheets": "^0.1.7",
"@univerjs/sheets-conditional-formatting-ui": "^0.1.7",
Expand Down
28 changes: 14 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/modals/chooseType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { App } from 'obsidian'
import { Modal } from 'obsidian'
import type { UniverPluginSettings } from '@/types/setting'
import { createNewFile } from '@/utils/createFile'
import { createNewFile } from '@/utils/file'

interface ModalText {
title: string
Expand Down
33 changes: 0 additions & 33 deletions src/utils/createFile.ts

This file was deleted.

33 changes: 33 additions & 0 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
import JSZip from 'jszip'
import { type App, Notice } from 'obsidian'
import { Type as DocType } from '@/views/udoc'
import { Type as SheetType } from '@/views/usheet'

export async function createNewFile(app: App, suffix: string, folderPath?: string, fileNum?: number): Promise<void> {
if (folderPath) {
try {
await app.vault.createFolder(folderPath)
}
catch (err) {
console.error(err)
}
}
const fileName = `Untitled${fileNum !== undefined ? `-${fileNum}` : ''}.${suffix}`
const filePath = folderPath !== undefined ? `${folderPath}/${fileName}` : fileName
try {
await app.vault.create(filePath, '')
await app.workspace.getLeaf(true).setViewState({
type: suffix === 'udoc' ? DocType : SheetType,
active: true,
state: {
file: filePath,
},
})

new Notice(`Created new ${suffix} file: ${filePath}`)
}
catch (err) {
const error = err
if (error.message.includes('File already exists'))
return await createNewFile(app, suffix, folderPath, (fileNum || 0) + 1)
}
}

export function transformToExcelBuffer(data: Record<string, any>): Promise<ArrayBuffer> {
return new Promise((resolve, reject) => {
Expand Down
17 changes: 14 additions & 3 deletions src/views/xlsx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { IWorkbookData, Univer, Workbook } from '@univerjs/core'
import { Tools } from '@univerjs/core'
import type { TFile, WorkspaceLeaf } from 'obsidian'
import { TextFileView } from 'obsidian'
import { FUniver } from '@univerjs/facade'
Expand Down Expand Up @@ -60,8 +59,20 @@ export class XlsxTypeView extends TextFileView {
const transformData = await window.univerProExchangeImport(raw)
const jsonData = JSON.parse(transformData)
let workbookData = transformSnapshotJsonToWorkbookData(jsonData.snapshot, jsonData.sheetBlocks)
if (!workbookData)
workbookData = Tools.deepClone({}) as IWorkbookData

workbookData = workbookData || {} as IWorkbookData

if (workbookData.sheets) {
const sheets = workbookData.sheets
Object.keys(sheets).forEach((sheetId) => {
const sheet = sheets[sheetId]
if (sheet.columnCount)
sheet.columnCount = Math.max(36, sheet.columnCount)

if (sheet.rowCount)
sheet.rowCount = Math.max(99, sheet.rowCount)
})
}

this.workbook = this.univer.createUniverSheet(workbookData)
}
Expand Down
Loading