mirror of
https://github.com/wekan/wekan.git
synced 2026-11-26 14:45:11 -05:00
Planner's "Export plan to Excel" writes one sheet, Tasks: plan name, plan ID and export date on rows 1-3, then Task ID, Task Name, Bucket Name, Progress, Priority, Assigned To, Created By, the created, start, due and completed dates, Late, Completed By, Description, Completed Checklist Items, Checklist Items and Labels. Columns are matched by name, as newer exports add Is Recurring. Buckets become lists and tasks cards, with the Task ID as source reference, the ;-separated assignees as owner and assignees, Created By as Requested by, the checklist and labels, and Progress, Priority and Completed By as custom fields. Dates are text in the exporting user's locale: day/month order is decided for the whole file, and reported when every date could be read either way; date cells keep their day. Which checklist items were done (Planner exports only a count), a recurring task's repeat and unknown values are reported. Export writes the same workbook as .xlsx. The layout follows a real Planner export, the MIT-licensed test data of the plannr package, added under tests/fixtures/planner/ with its licence. tests/plannerFormat.test.cjs imports it, round-trips an export through ExcelJS and covers the negatives; Playwright cases import the file through the page and download the export. New instruction text is in English, pending Transifex. Thanks to xet7 !
36 lines
1.6 KiB
JavaScript
36 lines
1.6 KiB
JavaScript
// Opens and writes Microsoft Planner's Excel workbook; what its rows mean is
|
|
// models/lib/plannerFormat.js. Server only: ExcelJS is a server dependency.
|
|
const ExcelJS = require('@wekanteam/exceljs');
|
|
|
|
// The rows of the "Tasks" sheet (the first sheet when there is no "Tasks"), as
|
|
// arrays of raw cell values, at their sheet positions: rows[0] is row 1 and an
|
|
// empty row is [], so a reported row number is the one Excel shows. Unlike
|
|
// the generic Excel import, a date cell stays a Date, so its day is not lost
|
|
// to String(date)'s local time.
|
|
async function readPlannerWorkbook(excelBase64) {
|
|
if (typeof excelBase64 !== 'string' || !excelBase64) throw new Error('Planner workbook is empty');
|
|
const workbook = new ExcelJS.Workbook();
|
|
await workbook.xlsx.load(Buffer.from(excelBase64, 'base64'));
|
|
const sheet = workbook.getWorksheet('Tasks') || workbook.worksheets[0];
|
|
const rows = [];
|
|
if (sheet) {
|
|
sheet.eachRow((row, number) => {
|
|
while (rows.length < number - 1) rows.push([]);
|
|
rows.push(row.values.slice(1));
|
|
});
|
|
}
|
|
return rows;
|
|
}
|
|
|
|
// A .xlsx Buffer from formatPlannerRows()'s { sheet, rows }.
|
|
async function writePlannerWorkbook({ sheet, rows }) {
|
|
const workbook = new ExcelJS.Workbook();
|
|
const worksheet = workbook.addWorksheet(sheet || 'Tasks');
|
|
(rows || []).forEach(cells => worksheet.addRow(cells));
|
|
const header = (rows || []).findIndex(cells => Array.isArray(cells) && cells.includes('Task Name'));
|
|
if (header !== -1) worksheet.getRow(header + 1).font = { bold: true };
|
|
return Buffer.from(await workbook.xlsx.writeBuffer());
|
|
}
|
|
|
|
module.exports = { readPlannerWorkbook, writePlannerWorkbook };
|