style modify

This commit is contained in:
ljcoder 2023-08-26 15:08:44 +08:00
parent 2d80cd9320
commit 6d129ed550
4 changed files with 2166 additions and 410 deletions

2537
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -14,6 +14,7 @@ export class Excel extends MarkdownRenderChild {
onload(): void {
console.log
const sheetEle = this.containerEl.createDiv({
cls: 'sheet-iframe',
attr: {
id: `x-spreadsheet-${this.index}`,
},
@ -23,12 +24,15 @@ export class Excel extends MarkdownRenderChild {
//@ts-ignore
const sheet = new Spreadsheet(sheetEle, {
mode: "read",
showToolbar: false,
showBottomBar: false,
view: {
height: () => this.containerEl.clientHeight,
width: () => 300,
height: () => 300,
width: () => this.containerEl.clientWidth,
},
}).loadData(jsonData); // load data
// @ts-ignore
sheet.validate();
// const sheetIframe = this.containerEl.createEl("iframe", {

View file

@ -1,5 +1,5 @@
import ExcelPlugin from "main";
import { TextFileView, WorkspaceLeaf, Platform } from "obsidian";
import { TextFileView, WorkspaceLeaf, Platform, Notice } from "obsidian";
import Spreadsheet from "x-data-spreadsheet";
import * as XLSX from "xlsx";
import { stox, xtos } from "./utils/xlsxspread";
@ -9,7 +9,7 @@ export const VIEW_TYPE_EXCEL = "excel-view";
export class ExcelView extends TextFileView {
public plugin: ExcelPlugin;
public ownerWindow: Window;
public sheet: any;
public sheet: Spreadsheet;
public importEle: HTMLElement;
public exportEle: HTMLElement;
public sheetEle: HTMLElement;
@ -41,13 +41,17 @@ export class ExcelView extends TextFileView {
handleFile(e: Event) {
//@ts-ignore
const files = e.target?.files;
var f = files[0];
var reader = new FileReader();
var instance = this;
const f = files[0];
const reader = new FileReader();
const instance = this;
reader.onload = (e) => {
const data = e.target?.result;
instance.process_wb(XLSX.read(data));
if (data) {
instance.process_wb(XLSX.read(data));
} else {
new Notice('Read file error')
}
};
reader.readAsArrayBuffer(f);
}
@ -58,17 +62,14 @@ export class ExcelView extends TextFileView {
}
handleExportClick(ev: MouseEvent) {
var new_wb = xtos(this.sheet.getData()) as XLSX.WorkBook;
var title = this.file?.basename ?? "sheet";
//@ts-ignore
const new_wb = xtos(this.sheet.getData()) as XLSX.WorkBook;
const title = this.file?.basename ?? "sheet";
/* write file and trigger a download */
XLSX.writeFile(new_wb, title + ".xlsx", {});
}
onload(): void {
// console.log("onload");
const apiMissing = Boolean(
typeof this.containerEl.onWindowMigrated === "undefined"
);
this.ownerWindow = this.containerEl.win;
// 添加顶部导入按钮
@ -120,6 +121,7 @@ export class ExcelView extends TextFileView {
const jsonData = JSON.parse(this.data || "{}") || {};
//@ts-ignore
this.sheet = new Spreadsheet(this.sheetEle, {
showBottomBar: false,
view: {
height: () => this.contentEl.clientHeight,
width: () => this.contentEl.clientWidth,
@ -134,6 +136,7 @@ export class ExcelView extends TextFileView {
console.log(cell, sri, sci, eri, eci)
})
// @ts-ignore
this.sheet.validate();
}

View file

@ -11,10 +11,6 @@ let plugin: ExcelPlugin;
let vault: Vault;
let metadataCache: MetadataCache;
const getDefaultWidth = (plugin: ExcelPlugin): string => {
return "400";
};
export const initializeMarkdownPostProcessor = (p: ExcelPlugin) => {
plugin = p;
vault = p.app.vault;