YBFACC / blog

仅记录个人学习使用
3 stars 0 forks source link

excel 相关问题 #51

Open YBFACC opened 7 months ago

YBFACC commented 7 months ago

这里使用 exceljs

特定列设置预设值

sheet.dataValidations.model['A2:A9999'] = {
        type: 'list',
        allowBlank: true,
        formulae: ['"male,female,other"']
};
YBFACC commented 7 months ago

下载

function downloadExcel(workbook: Workbook, fileName: string) {
    const buffer = await workbook.xlsx.writeBuffer()
    const blob = new Blob([buffer], {
        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    })

    const a = document.createElement('a')
    document.body.appendChild(a)
    a.style.display = 'none'
    a.download = `${fileName}.xlsx`

    const url = URL.createObjectURL(blob)
    a.href = url
    a.click()

    await new Promise<void>(res => {
        setTimeout(() => {
            try {
                document.body.removeChild(a)
            } catch (error) {
                console.warn(error)
            }
            window.URL.revokeObjectURL(url)
            res()
        })
    })
}
YBFACC commented 7 months ago

这里使用 exceljs

特定列设置预设值

sheet.dataValidations.model['A2:A9999'] = {
        type: 'list',
        allowBlank: true,
        formulae: ['"male,female,other"']
};

168. Excel表列名称

YBFACC commented 7 months ago

这里使用 exceljs

特定列设置预设值

sheet.dataValidations.model['A2:A9999'] = {
        type: 'list',
        allowBlank: true,
        formulae: ['"male,female,other"']
};

时间预设

sheet.dataValidations.model[`${convertToTitle(index + 1)}2:${convertToTitle(index + 1)}99999`] = {
                    type: 'date',
                    showErrorMessage: true,
                    allowBlank: true,
                    formulae: [],
                    error: '正确例子: 2023/1/1 20:20'
                };