mirror of
https://github.com/ljcoder2015/obsidian-excel.git
synced 2026-07-22 08:30:28 +00:00
Compare commits
32 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9df140382 | ||
|
|
04dc273d80 | ||
|
|
5e149efaa7 | ||
|
|
583c46a828 | ||
|
|
5397aade29 | ||
|
|
82a6a7d1f9 | ||
|
|
56ca68dde1 | ||
|
|
5380c7a6e9 | ||
|
|
b018f956a7 | ||
|
|
ff08a53c06 | ||
|
|
05ea79123b | ||
|
|
2135848b38 | ||
|
|
8d2a44df50 | ||
|
|
34f35f9822 | ||
|
|
42cbe19ad0 | ||
|
|
6dc364519b | ||
|
|
9898398afc | ||
|
|
ae4426b24f | ||
|
|
0346ab7ca3 | ||
|
|
63c041ba05 | ||
|
|
a1c620d4e2 | ||
|
|
578a3388c6 | ||
|
|
1bb57398d2 | ||
|
|
4d784ac627 | ||
|
|
2e8ee0f5ac | ||
|
|
231ab55de6 | ||
|
|
8908dd9da4 | ||
|
|
5e98093f49 | ||
|
|
3aa557087a | ||
|
|
8bbebb9a6f | ||
|
|
ed685da21c | ||
|
|
2457eff3d1 |
14 changed files with 2461 additions and 561 deletions
1
.github/workflows/release.yml
vendored
1
.github/workflows/release.yml
vendored
|
|
@ -19,6 +19,7 @@ jobs:
|
|||
|
||||
- name: Build plugin
|
||||
run: |
|
||||
npm config set strict-ssl false
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
> ### The Obsidian-Excel plugin will no longer be maintained or updated. To download Obsidian-Sheet-Plus, please visit [https://github.com/ljcoder2015/obsidian-sheet-plus](https://github.com/ljcoder2015/obsidian-sheet-plus)
|
||||
> ### Obsidian-Excel插件不再更新维护,旧功能不满足可以尝试使用新插件Obsidian-Sheet-Plus。下载地址 [https://github.com/ljcoder2015/obsidian-sheet-plus](https://github.com/ljcoder2015/obsidian-sheet-plus)
|
||||
|
||||
# Obsidian Excel Plugin
|
||||
|
||||
## Excel
|
||||
|
|
@ -49,4 +52,7 @@ embed link rule:
|
|||
|
||||
- ljcoder@163.com
|
||||
|
||||
### buy a Coffee
|
||||
|
||||
[https://ko-fi.com/ljcoder](https://ko-fi.com/ljcoder)
|
||||
|
||||
|
|
|
|||
2
main.css
2
main.css
File diff suppressed because one or more lines are too long
|
|
@ -1,10 +1,11 @@
|
|||
{
|
||||
"id": "excel",
|
||||
"name": "Excel",
|
||||
"version": "1.3.15",
|
||||
"version": "1.3.24",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Create spreadsheets and easily embed them in Markdown",
|
||||
"author": "ljcoder",
|
||||
"authorUrl": "https://github.com/ljcoder2015",
|
||||
"fundingUrl": "https://ko-fi.com/ljcoder",
|
||||
"isDesktopOnly": false
|
||||
}
|
||||
|
|
|
|||
2771
package-lock.json
generated
2771
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -28,7 +28,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"monkey-around": "^2.3.0",
|
||||
"x-data-spreadsheet": "git+ssh://git@github.com:ljcoder2015/x-spreadsheet.git#1.1.1",
|
||||
"x-data-spreadsheet": "git+ssh://git@github.com:ljcoder2015/x-spreadsheet.git#1.1.4",
|
||||
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,5 +114,46 @@ export class ExcelSettingTab extends PluginSettingTab {
|
|||
this.plugin.saveSettings()
|
||||
})
|
||||
)
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("DEFAULT_ROWS_LEN"))
|
||||
.setDesc(t("DEFAULT_ROWS_LEN_DESC"))
|
||||
.addText((text) =>
|
||||
text
|
||||
.setPlaceholder("100")
|
||||
.setValue(this.plugin.settings.defaultRowsLen)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.defaultRowsLen = value
|
||||
this.plugin.saveSettings()
|
||||
})
|
||||
)
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("DEFAULT_COLS_LEN"))
|
||||
.setDesc(t("DEFAULT_COLS_LEN_DESC"))
|
||||
.addText((text) =>
|
||||
text
|
||||
.setPlaceholder("26")
|
||||
.setValue(this.plugin.settings.defaultColsLen)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.defaultColsLen = value
|
||||
this.plugin.saveSettings()
|
||||
})
|
||||
)
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("SHOW_SHEET_BUTTON"))
|
||||
.setDesc(t("SHOW_SHEET_BUTTON_DESC"))
|
||||
.addDropdown((dropdown) =>
|
||||
dropdown
|
||||
.addOption("true","True")
|
||||
.addOption("false","False")
|
||||
.setValue(this.plugin.settings.showSheetButton)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.showSheetButton = value
|
||||
this.plugin.saveSettings()
|
||||
}),
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import ExcelPlugin from "src/main";
|
||||
import { TextFileView, WorkspaceLeaf, Platform, Notice, moment } from "obsidian";
|
||||
import { TextFileView, WorkspaceLeaf, Platform, Notice, moment, TFile } from "obsidian";
|
||||
import Spreadsheet from "x-data-spreadsheet";
|
||||
import * as XLSX from "xlsx";
|
||||
import { stox, xtos } from "./utils/xlsxspread";
|
||||
|
|
@ -49,6 +49,13 @@ export class ExcelView extends TextFileView {
|
|||
saveData(data: string) {
|
||||
this.data = this.headerData() + data;
|
||||
// console.log("saveData", this.data)
|
||||
this.save(false)
|
||||
.then(() => {
|
||||
console.log("save data success", this.file)
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log("save data error", e)
|
||||
})
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
|
|
@ -59,8 +66,8 @@ export class ExcelView extends TextFileView {
|
|||
this.data = data;
|
||||
|
||||
this.app.workspace.onLayoutReady(async () => {
|
||||
// console.log('setViewData')
|
||||
await this.refresh();
|
||||
// console.log('setViewData', this.file)
|
||||
this.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -79,11 +86,12 @@ export class ExcelView extends TextFileView {
|
|||
}
|
||||
const f = files[0];
|
||||
const reader = new FileReader();
|
||||
const self = this
|
||||
reader.onload = (e) => {
|
||||
const data = e.target?.result;
|
||||
|
||||
console.log('handleFile', self.file)
|
||||
if (data) {
|
||||
this.process_wb(XLSX.read(data));
|
||||
self.process_wb(XLSX.read(data));
|
||||
} else {
|
||||
new Notice(t("READ_FILE_FAILED"));
|
||||
}
|
||||
|
|
@ -94,8 +102,16 @@ export class ExcelView extends TextFileView {
|
|||
process_wb(wb: XLSX.WorkBook) {
|
||||
const sheetData = stox(wb);
|
||||
if (sheetData) {
|
||||
this.sheet.loadData(sheetData);
|
||||
this.saveData(JSON.stringify(sheetData));
|
||||
sheetData.forEach((sheet) => {
|
||||
var sheetAny = sheet as any
|
||||
if (sheetAny.rows) {
|
||||
const last = Object.keys(sheetAny.rows).last() || "100"
|
||||
const max = parseInt(this.plugin.settings.defaultRowsLen)
|
||||
sheetAny.rows.len = Math.max(max, parseInt(last) + 20)
|
||||
}
|
||||
})
|
||||
this.saveData(JSON.stringify(sheetData))
|
||||
this.refresh()
|
||||
} else {
|
||||
new Notice(t("DATA_PARSING_ERROR"));
|
||||
}
|
||||
|
|
@ -129,6 +145,7 @@ export class ExcelView extends TextFileView {
|
|||
|
||||
onload(): void {
|
||||
this.ownerWindow = this.containerEl.win;
|
||||
console.log("onload", this.file)
|
||||
|
||||
// 添加顶部导入按钮
|
||||
this.importEle = this.addAction("download", t("IMPORT_XLSX_FILE"), (ev) =>
|
||||
|
|
@ -180,6 +197,7 @@ export class ExcelView extends TextFileView {
|
|||
|
||||
// 初始化 sheet
|
||||
const jsonData = JSON.parse(getExcelData(this.data) || "{}") || {};
|
||||
// console.log("refresh", jsonData, this.file)
|
||||
|
||||
// 设置多语言
|
||||
if (moment.locale() === 'zh-cn') {
|
||||
|
|
@ -231,11 +249,11 @@ export class ExcelView extends TextFileView {
|
|||
width: () => this.contentEl.clientWidth - 32,
|
||||
},
|
||||
row: {
|
||||
len: 100,
|
||||
len: parseInt(this.plugin.settings.defaultRowsLen),
|
||||
height: parseInt(this.plugin.settings.rowHeight),
|
||||
},
|
||||
col: {
|
||||
len: 26,
|
||||
len: parseInt(this.plugin.settings.defaultColsLen),
|
||||
width: parseInt(this.plugin.settings.colWidth),
|
||||
indexWidth: 60,
|
||||
minWidth: 60,
|
||||
|
|
@ -248,7 +266,6 @@ export class ExcelView extends TextFileView {
|
|||
.change(() => {
|
||||
// save data to db
|
||||
const data = this.sheet.getData();
|
||||
// console.log("save data to db", data);
|
||||
this.saveData(JSON.stringify(data));
|
||||
})
|
||||
.onAddSheet(() => {
|
||||
|
|
|
|||
|
|
@ -208,23 +208,24 @@ const createEditSheetHtml = (
|
|||
): HTMLDivElement => {
|
||||
const sheetDiv = createDiv();
|
||||
|
||||
// <div class="internal-embed file-embed mod-generic is-loaded" tabindex="-1" src="Excel 2023-09-07 17.18.19.sheet" alt="Excel 2023-09-07 17.18.19.sheet" contenteditable="false"><div class="file-embed-title"><span class="file-embed-icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-file"><path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"></path><polyline points="14 2 14 8 20 8"></polyline></svg></span> Excel 2023-09-07 17.18.19.sheet</div></div>
|
||||
const fileEmbed = sheetDiv.createDiv({
|
||||
cls: "internal-embed file-embed mod-generic is-loaded",
|
||||
text: file.basename,
|
||||
attr: {
|
||||
src: file.basename,
|
||||
alt: file.basename,
|
||||
contenteditable: false,
|
||||
tabindex: -1,
|
||||
},
|
||||
});
|
||||
|
||||
// 点击按钮打开 sheet
|
||||
fileEmbed.onClickEvent((e) => {
|
||||
e.stopPropagation();
|
||||
plugin.app.workspace.getLeaf().openFile(file);
|
||||
});
|
||||
if (plugin.settings.showSheetButton == "true") {
|
||||
const fileEmbed = sheetDiv.createDiv({
|
||||
cls: "internal-embed file-embed mod-generic is-loaded",
|
||||
text: file.basename,
|
||||
attr: {
|
||||
src: file.basename,
|
||||
alt: file.basename,
|
||||
contenteditable: false,
|
||||
tabindex: -1,
|
||||
},
|
||||
});
|
||||
|
||||
// 点击按钮打开 sheet
|
||||
fileEmbed.onClickEvent((e) => {
|
||||
e.stopPropagation();
|
||||
plugin.app.workspace.getLeaf().openFile(file);
|
||||
});
|
||||
}
|
||||
|
||||
var table = getExcelAreaHtml(excelData, sheet, cells);
|
||||
|
||||
|
|
@ -255,22 +256,24 @@ const createSheetHtml = (
|
|||
): HTMLDivElement => {
|
||||
const sheetDiv = createDiv();
|
||||
|
||||
const fileEmbed = sheetDiv.createDiv({
|
||||
cls: "internal-embed file-embed mod-generic is-loaded",
|
||||
text: file.basename,
|
||||
attr: {
|
||||
src: file.basename,
|
||||
alt: file.basename,
|
||||
contenteditable: false,
|
||||
tabindex: -1,
|
||||
},
|
||||
});
|
||||
|
||||
// 点击按钮打开 sheet
|
||||
fileEmbed.onClickEvent((e) => {
|
||||
e.stopPropagation();
|
||||
plugin.app.workspace.getLeaf().openFile(file);
|
||||
});
|
||||
if (plugin.settings.showSheetButton == "true") {
|
||||
const fileEmbed = sheetDiv.createDiv({
|
||||
cls: "internal-embed file-embed mod-generic is-loaded",
|
||||
text: file.basename,
|
||||
attr: {
|
||||
src: file.basename,
|
||||
alt: file.basename,
|
||||
contenteditable: false,
|
||||
tabindex: -1,
|
||||
},
|
||||
});
|
||||
|
||||
// 点击按钮打开 sheet
|
||||
fileEmbed.onClickEvent((e) => {
|
||||
e.stopPropagation();
|
||||
plugin.app.workspace.getLeaf().openFile(file);
|
||||
});
|
||||
}
|
||||
|
||||
const sheetEl = createDiv({
|
||||
attr: {
|
||||
|
|
@ -295,23 +298,26 @@ const createSheetEl = (
|
|||
): HTMLDivElement => {
|
||||
const sheetDiv = createDiv();
|
||||
|
||||
if (plugin.settings.showSheetButton == "true") {
|
||||
const fileEmbed = sheetDiv.createDiv({
|
||||
cls: "internal-embed file-embed mod-generic is-loaded",
|
||||
text: file.basename,
|
||||
attr: {
|
||||
src: file.basename,
|
||||
alt: file.basename,
|
||||
contenteditable: false,
|
||||
tabindex: -1,
|
||||
},
|
||||
});
|
||||
|
||||
// 点击按钮打开 sheet
|
||||
fileEmbed.onClickEvent((e) => {
|
||||
e.stopPropagation();
|
||||
plugin.app.workspace.getLeaf().openFile(file);
|
||||
});
|
||||
}
|
||||
// <div class="internal-embed file-embed mod-generic is-loaded" tabindex="-1" src="Excel 2023-09-07 17.18.19.sheet" alt="Excel 2023-09-07 17.18.19.sheet" contenteditable="false"><div class="file-embed-title"><span class="file-embed-icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-file"><path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"></path><polyline points="14 2 14 8 20 8"></polyline></svg></span> Excel 2023-09-07 17.18.19.sheet</div></div>
|
||||
const fileEmbed = sheetDiv.createDiv({
|
||||
cls: "internal-embed file-embed mod-generic is-loaded",
|
||||
text: file.basename,
|
||||
attr: {
|
||||
src: file.basename,
|
||||
alt: file.basename,
|
||||
contenteditable: false,
|
||||
tabindex: -1,
|
||||
},
|
||||
});
|
||||
|
||||
// 点击按钮打开 sheet
|
||||
fileEmbed.onClickEvent((e) => {
|
||||
e.stopPropagation();
|
||||
plugin.app.workspace.getLeaf().openFile(file);
|
||||
});
|
||||
|
||||
|
||||
const sheetEl = createDiv({
|
||||
cls: "sheet-iframe",
|
||||
|
|
@ -369,11 +375,11 @@ const createSheetEl = (
|
|||
width: () => width - 10,
|
||||
},
|
||||
row: {
|
||||
len: 100,
|
||||
len: parseInt(plugin.settings.defaultRowsLen),
|
||||
height: parseInt(plugin.settings.rowHeight),
|
||||
},
|
||||
col: {
|
||||
len: 26,
|
||||
len: parseInt(plugin.settings.defaultColsLen),
|
||||
width: parseInt(plugin.settings.colWidth),
|
||||
indexWidth: 60,
|
||||
minWidth: 60,
|
||||
|
|
|
|||
|
|
@ -42,4 +42,10 @@ export default {
|
|||
ROW_HEIGHT_DESC: "Default row height",
|
||||
COLUMN_WIDTH: "Column Width",
|
||||
COLUMN_WIDTH_DESC: "Default column width",
|
||||
DEFAULT_ROWS_LEN: 'Default render rows',
|
||||
DEFAULT_ROWS_LEN_DESC: 'Default number of render rows',
|
||||
DEFAULT_COLS_LEN: 'Default render columns',
|
||||
DEFAULT_COLS_LEN_DESC: 'Default number of rendered columns',
|
||||
SHOW_SHEET_BUTTON: "Show Sheet Button",
|
||||
SHOW_SHEET_BUTTON_DESC: "Show Sheet Button",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -41,4 +41,10 @@ export default {
|
|||
ROW_HEIGHT_DESC: "设置表格的默认行高",
|
||||
COLUMN_WIDTH: "列宽",
|
||||
COLUMN_WIDTH_DESC: "设置表格的默认列宽",
|
||||
DEFAULT_ROWS_LEN: '默认渲染行数',
|
||||
DEFAULT_ROWS_LEN_DESC: '创建表格时默认渲染最大行数',
|
||||
DEFAULT_COLS_LEN: '默认渲染列数',
|
||||
DEFAULT_COLS_LEN_DESC: '创建表格时默认渲染最大列数',
|
||||
SHOW_SHEET_BUTTON: "显示标题按钮",
|
||||
SHOW_SHEET_BUTTON_DESC: "是否显示标题按钮",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -49,10 +49,12 @@ export const getExcelAreaData = (
|
|||
newData.set("validations", sheetData.validations);
|
||||
newData.set("merges", sheetData.merges);
|
||||
|
||||
console.log("------", jsonData, cells, sheetData);
|
||||
var sri = 0;
|
||||
var sci = 0;
|
||||
var eri = sheetData.rows.len - 1;
|
||||
var eci = sheetData.cols.len - 1;
|
||||
var eri = 100;
|
||||
var eci = 26;
|
||||
|
||||
if (cells.includes(":")) {
|
||||
var cellArray = cells.split(":");
|
||||
const start = cellArray[0].split("-");
|
||||
|
|
@ -62,8 +64,15 @@ export const getExcelAreaData = (
|
|||
const end = cellArray[1].split("-");
|
||||
var eri = parseInt(end[0]); // 结束行
|
||||
var eci = parseInt(end[1]); // 结束列
|
||||
} else {
|
||||
if (sheetData.rows && sheetData.rows.len) {
|
||||
eri = sheetData.rows.len - 1;
|
||||
}
|
||||
if (sheetData.cols && sheetData.cols.len) {
|
||||
eci = sheetData.cols.len - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var rowLen = eri - sri + 1;
|
||||
// 用来存储新数据
|
||||
var rows = new Map<string, any>();
|
||||
|
|
@ -157,8 +166,8 @@ export const getExcelAreaHtml = (
|
|||
if (sheetData) {
|
||||
var sri = 0;
|
||||
var sci = 0;
|
||||
var eri = sheetData.rows.len - 1;
|
||||
var eci = sheetData.cols.len - 1;
|
||||
var eri = 100;
|
||||
var eci = 26;
|
||||
if (cells.includes(":")) {
|
||||
var cellArray = cells.split(":");
|
||||
const start = cellArray[0].split("-");
|
||||
|
|
@ -168,6 +177,13 @@ export const getExcelAreaHtml = (
|
|||
const end = cellArray[1].split("-");
|
||||
var eri = parseInt(end[0]); // 结束行
|
||||
var eci = parseInt(end[1]); // 结束列
|
||||
} else {
|
||||
if (sheetData.rows && sheetData.rows.len) {
|
||||
eri = sheetData.rows.len - 1;
|
||||
}
|
||||
if (sheetData.cols && sheetData.cols.len) {
|
||||
eci = sheetData.cols.len - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// console.log("getExcelAreaHtml", cells, sri, sci, eri, eci);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ export interface ExcelSettings {
|
|||
sheetHeight: string,
|
||||
rowHeight: string,
|
||||
colWidth: string,
|
||||
theme: string
|
||||
theme: string,
|
||||
showSheetButton: string,
|
||||
defaultRowsLen: string,
|
||||
defaultColsLen: string,
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: ExcelSettings = {
|
||||
|
|
@ -15,5 +18,8 @@ export const DEFAULT_SETTINGS: ExcelSettings = {
|
|||
sheetHeight: "300",
|
||||
rowHeight: "25",
|
||||
colWidth: "100",
|
||||
theme: "light"
|
||||
theme: "light",
|
||||
showSheetButton: "true",
|
||||
defaultRowsLen: "100",
|
||||
defaultColsLen: "26",
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue