mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
A CSV, TSV or Excel import now shows which column is which card field before importing, pre-filled from the header names - English names and WeKan's own export column names in every language - and asks for what is missing: a file with no list column gets one list, named on the page, instead of one list per row. Unused columns can be kept as text custom fields. The choice goes to the server as csvMapping, checked before anything is written, and the REST import and api.py take one too. The Owner column is applied, as are swimlane, received date, parent card, spent time, overtime and archived. A TSV value containing a comma stays one value. A dropdown custom field value that is not one of its items is skipped instead of failing the import. An Excel workbook is read sheet by sheet, its header found in row 1 or where WeKan's export puts it, in any language; formula cells are read as their results and rich text as text. WeKan's own Excel export imports, and a workbook with many boards - each on its own sheet, as Export all boards writes it - imports as many boards; the Activity sheet is skipped. Thanks to xet7 !
20 lines
1.1 KiB
JavaScript
20 lines
1.1 KiB
JavaScript
// Opens the workbook of an Excel import and finds the boards in it; which row
|
|
// is the header and which sheet is a board is decided in
|
|
// models/lib/csvImportMapping.js. Server only: ExcelJS is a server dependency.
|
|
import { worksheetRows, excelSheetsToBoards } from '/models/lib/csvImportMapping';
|
|
import { importHeaderNames } from './importHeaderNames';
|
|
|
|
const ExcelJS = require('@wekanteam/exceljs');
|
|
|
|
// { boards: [{ title, sheet, rows }], skipped: [sheet names] } - rows[0] of a
|
|
// board is its header, every cell text (dates as ISO 8601).
|
|
export async function readExcelBoards(excelBase64) {
|
|
if (typeof excelBase64 !== 'string' || !excelBase64) throw new Error('The workbook is empty');
|
|
const workbook = new ExcelJS.Workbook();
|
|
await workbook.xlsx.load(Buffer.from(excelBase64, 'base64'));
|
|
const sheets = workbook.worksheets.map(worksheet => ({ name: worksheet.name, rows: worksheetRows(worksheet) }));
|
|
const result = excelSheetsToBoards(sheets, await importHeaderNames());
|
|
if (!result.boards.length) throw new Error('The workbook has no rows');
|
|
return result;
|
|
}
|