import ExcelJS from 'exceljs'
function exportData() {
const workbook = new ExcelJS.Workbook()
workbook.creator = pkg.name
const sheet1 = workbook.addWorksheet('todo list')
sheet1.addRow(['内容', '建立时间'])
const todoList = DB.get('todoList')
for (let i in todoList) {
sheet1.addRow([todoList[i].content, todoList[i].todo_datetime])
}
const sheet2 = workbook.addWorksheet('done list')
sheet2.addRow(['内容', '建立时间', '完成时间'])
const doneGroupList = DB.groupby('doneList', 'done_date')
for (let prop in doneGroupList) {
for (let i in doneGroupList[prop]) {
sheet2.addRow([
doneGroupList[prop][i].content,
doneGroupList[prop][i].todo_datetime,
doneGroupList[prop][i].done_datetime
])
}
}
const defaultPath = `/${getNowDateTimeForFlieName()}.xlsx`
dialog
.showSaveDialog({ title: '数据导出', defaultPath: defaultPath })
.then(async result => {
if (result.canceled) return
await workbook.xlsx.writeFile(result.filePath)
showNotification(
{ title: '导出完成', body: `数据已导出到:${result.filePath}` },
() => {
shell.openExternal(result.filePath)
}
)
})
}
export function showNotification(option, clickCallback) {
if (Notification.isSupported()) {
const notification = new Notification(option)
if (clickCallback) {
notification.on('click', () => {
clickCallback()
})
}
notification.show()
}
}