Files
wekan/server/lib/teamworkWorkbook.js
T
Lauri Ojansivu 7aa90f7a00 Import and export boards as Teamwork.com Excel task import templates.
Teamwork.com imports tasks into a project from an Excel template (List or
Table view > ... > Import Tasks) whose help article names ten columns:
Tasklist, Task, Description, Assign to, Start date, Due date, Priority,
Estimated time, Tags and Status. Teamwork documents no export in that
layout, so the template is what is read and written. Task lists become
lists and tasks cards; a "-", "#" or ">" before a task name, doubled per
level, makes it a subtask card of the nearest shallower task above, in
its parent's list. Comma-separated Assign to e-mails become the owner and
assignees, Start and Due date the start and due dates (date cells, ISO,
or the site's numeric format with day/month order decided for the whole
file), Tags labels, Priority low/medium/high and Estimated time (25,
01:30, 1h 15m, 1h, 2 hours) the custom fields Priority and Estimated time
(hours), and Status Complete the checkbox field Complete with the due
date marked done. Other columns, unknown values, unreadable dates and
estimates, nameless rows and subtasks without or skipping a parent level
are reported; an .xls file is refused with a request to save it as .xlsx.
Export writes the template with date cells, HH:MM estimates and subtasks
after their parents.

tests/teamworkFormat.test.cjs builds the template with ExcelJS and covers
the subtask levels, every estimate form, the negatives and the round
trip; a Playwright case imports a workbook through the page. New
instruction text is in English, pending Transifex.

Thanks to xet7 !
2026-10-08 21:40:19 +03:00

49 lines
2.1 KiB
JavaScript

// Opens and writes Teamwork.com's Excel task import template; what its rows
// mean is models/lib/teamworkFormat.js. Server only: ExcelJS is a server
// dependency.
const ExcelJS = require('@wekanteam/exceljs');
// The first sheet as { name, rows }: rows at their sheet positions (rows[0] is
// row 1, an empty row is []), so a reported row number is the one Excel
// shows, and a date cell stays a Date, so its day is not lost to
// String(date)'s local time. Teamwork also accepts the older .xls; ExcelJS
// reads only .xlsx, so an .xls file is refused with what to do instead.
async function readTeamworkWorkbook(excelBase64) {
if (typeof excelBase64 !== 'string' || !excelBase64) throw new Error('Teamwork.com workbook is empty');
const buffer = Buffer.from(excelBase64, 'base64');
if (buffer.length >= 4 && buffer.readUInt32BE(0) === 0xd0cf11e0) {
throw new Error('Teamwork.com workbook is an .xls file; save it as .xlsx and import that');
}
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.load(buffer);
const sheet = 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 { name: sheet ? sheet.name : '', rows };
}
// A .xlsx Buffer from formatTeamworkSheet()'s { name, rows }.
async function writeTeamworkWorkbook({ name, rows }) {
const workbook = new ExcelJS.Workbook();
const title = String(name || 'Tasks').replace(/[\\/?*[\]:]/g, ' ').trim().slice(0, 31) || 'Tasks';
const worksheet = workbook.addWorksheet(title);
(rows || []).forEach(cells => worksheet.addRow(cells));
if ((rows || []).length) {
worksheet.getRow(1).font = { bold: true };
// Start date and Due date, as dates Excel shows in the reader's format.
const header = rows[0] || [];
for (const columnName of ['Start date', 'Due date']) {
const index = header.indexOf(columnName);
if (index !== -1) worksheet.getColumn(index + 1).numFmt = 'yyyy-mm-dd';
}
}
return Buffer.from(await workbook.xlsx.writeBuffer());
}
module.exports = { readTeamworkWorkbook, writeTeamworkWorkbook };