From f7d0923c3ce01c03d4a5f09a82aa5c295b042512 Mon Sep 17 00:00:00 2001 From: Gabriele Cannata Date: Wed, 16 Aug 2023 18:45:30 +0200 Subject: [PATCH] README --- README.md | 59 ++++++++++++++++++++++++++++++++- src/Views/SheetView.ts | 4 +-- src/Views/spreadSheetWrapper.ts | 6 ++-- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bc60bf4..1a0bda8 100644 --- a/README.md +++ b/README.md @@ -1 +1,58 @@ -TODO: +# Obsidian Sheets + +This plugin enables to work with tabular data directly in Obsidian: either storing data in the note itself, or on an external Excel or CSV file. +The following files are supported: +- XLSX +- XLS +- CSV + + +## Code Block Parameters + +In order to create a sheet it is enough to create a code block with the `sheet` name + +~~~markdown +```sheet + +``` +~~~ + +Following is the complete list of properties: + +~~~markdown +```sheet +filename: +enableSave: +autoSave: +height: 540, +width: "auto", +rows: 100, +cols: 26, +fontSize: 10, +cellHeight: 25, +cellWidth: 100, +``` +~~~ + + +If `filename` is provided, data is loaded from that file, if already existing. Otherwise it will be created upon save. +If `filename` is not provided, data will be stored in the code block itself. + +Note that by default saving data to external files is disabled because - in general - there will be loss of information. This could be enabled at vault-level via the settings, or code-block level by specifying `enableSave: true` in the code block. +When saving to file, by default it will also autosave after each modification. When saving to the code block in order to save one must click the save icon in the top left. + +## Supported Formats + +When saving to code block, all formatting and changes done to the sheet are perserved. +When saving to `XLSX` most formatting and data will be saved and read back. Note however that when reading an existing `XLSX` file, only a subset of functionality will be supported. +Support of `XLS` is limited to data and cell merges +CSV can, of course, only store data. + + +## Attributions + +This plugin uses the following libraries: + +https://github.com/SheetJS +https://github.com/myliang/x-spreadsheet (forked here: https://github.com/Canna71/x-spreadsheet) +https://github.com/exceljs/exceljs diff --git a/src/Views/SheetView.ts b/src/Views/SheetView.ts index fd109e9..4a07fb3 100644 --- a/src/Views/SheetView.ts +++ b/src/Views/SheetView.ts @@ -63,7 +63,7 @@ export function processCodeBlock( if ((ctx as any).spreadsheet) return; - const options = { ...DEFAULT_OPTIONS, ...parseYaml(source) }; + const options = { ...DEFAULT_OPTIONS, enableSave: settings.enableSaveToFile, autoSave: settings.autoSave, ...parseYaml(source) }; options.height = Math.max(options.height, MINHEIGHT); @@ -145,7 +145,7 @@ export function processCodeBlock( // } }; - if (!filename || settings.enableSaveToFile) { + if (!filename || options.enableSave) { const el = document.createElement("div"); el.innerHTML = saveIcon; spreadsheet_options.extendToolbar = { diff --git a/src/Views/spreadSheetWrapper.ts b/src/Views/spreadSheetWrapper.ts index 4fe42cc..6ea71e8 100644 --- a/src/Views/spreadSheetWrapper.ts +++ b/src/Views/spreadSheetWrapper.ts @@ -57,6 +57,8 @@ function applyStyles(ssdata: any, wb: XLSX.WorkBook) { export interface SheetOptions { filename?: string; data?: any; + enableSave?: boolean; + autoSave?: boolean; } export function createSpreadSheet( @@ -79,11 +81,11 @@ export function createSpreadSheet( prepareDataForLoading(spreadSheet, options.data as SpreadsheetData) - if(settings.autoSave) { + if(options.autoSave) { spreadSheet.change( debounce((_data) => { // save data - if (options.filename && settings.enableSaveToFile) { + if (options.filename && options.enableSave) { saveToFile(spreadSheet, options.filename); } else { // at the moment we avoid since this would cause re-rendering