Files
wekan/server/lib/mondayWorkbook.js
T
Lauri Ojansivu 1ceaad80f4 Import and export boards as monday.com Excel workbooks.
monday's "Export board to Excel" is documented only through its help
article's screenshots and cannot be changed: the board's name in row 1,
then per group its name, a header row starting Name with the board's
own column titles, the items and a summary row; with "+ updates" a
<board>-updates sheet of Item ID, Item Name, User, Created At and Update
Content. Column titles are the board owner's, so they are matched by
meaning: Name is the title, Status the list (groups become swimlanes;
without a Status column the groups are the lists), Person / People /
Owner / Assignee the owner and assignees, Date / Due date / Deadline the
due date, Timeline the start and due dates, Tags labels, Item ID the
reference, Long text / Description / Notes the description, and every
other column a custom field. Updates become comments on the item they
name. Subitems are undocumented; as community reports show them - a
Subitems header row after the parent, its rows indented one column -
they become subtasks. Bad dates, nameless items and updates for unknown
items are reported. Export writes the flat table monday's own Excel
import reads: the first sheet, a header row and ISO dates.

tests/mondayFormat.test.cjs builds the documented layout with ExcelJS,
including updates and subitems, and covers 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:13:39 +03:00

35 lines
1.6 KiB
JavaScript

// Opens and writes monday.com's Excel workbook; what its rows mean is
// models/lib/mondayFormat.js. Server only: ExcelJS is a server dependency.
const ExcelJS = require('@wekanteam/exceljs');
// Every sheet, in order, as { name, rows }: the board sheet first, then the
// "<board>-updates" sheet when the export has one. Rows keep their sheet
// positions (rows[0] is row 1, an empty row is []), and a date cell stays a
// Date, so its day is not lost to String(date)'s local time.
async function readMondayWorkbook(excelBase64) {
if (typeof excelBase64 !== 'string' || !excelBase64) throw new Error('monday.com workbook is empty');
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.load(Buffer.from(excelBase64, 'base64'));
return workbook.worksheets.map(sheet => {
const rows = [];
sheet.eachRow((row, number) => {
while (rows.length < number - 1) rows.push([]);
rows.push(row.values.slice(1));
});
return { name: sheet.name, rows };
});
}
// A .xlsx Buffer from formatMondaySheets()'s { sheets }.
async function writeMondayWorkbook({ sheets }) {
const workbook = new ExcelJS.Workbook();
(sheets || []).forEach((sheet, index) => {
const worksheet = workbook.addWorksheet(String(sheet.name || `sheet${index + 1}`).replace(/[\\/?*[\]:]/g, ' ').slice(0, 31) || `sheet${index + 1}`);
(sheet.rows || []).forEach(cells => worksheet.addRow(cells));
if ((sheet.rows || []).length) worksheet.getRow(1).font = { bold: true };
});
return Buffer.from(await workbook.xlsx.writeBuffer());
}
module.exports = { readMondayWorkbook, writeMondayWorkbook };