zurmokeeper / officecrypto-tool

officecrypto-tool is a library for js that can be used to decrypt and encrypt office(excel/ppt/word) files.
https://www.npmjs.com/package/officecrypto-tool
MIT License
19 stars 4 forks source link

how to encrypt doc/xls/ppt files? #17

Closed n0rv1n closed 4 months ago

n0rv1n commented 12 months ago

Are there any way to encrypt doc/xls/ppt files?

zurmokeeper commented 11 months ago

@n0rv1n Temporarily does not support the encryption of doc/xls/ppt files, please ask what scenarios need to be used, if it is really necessary, you can consider adding these features later!

Lxxxxxxy commented 4 months ago

202407251344_理货明细1699708443335589888.xls

Lxxxxxxy commented 4 months ago

202407251458_理货明细1699708443335589888.xls

Mark-SS commented 4 months ago

libre_123.xls

Lxxxxxxy commented 4 months ago
    //设置文件名
    String fileName = DateFormatUtils.format(new Date(), "yyyyMMddHHmm") + "_" + sheetName + ".xls";
    //设置输出头
    response.setContentType("application/vnd.ms-excel;charset=UTF-8");
    response.setCharacterEncoding(StandardCharsets.UTF_8.name());
    response.setHeader("Content-Disposition",
            "attachment;filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()));
    //输出文件流
    EasyExcelFactory.write(response.getOutputStream(), objectClass)
            //单元格加密
            .registerWriteHandler(new CustomSheetWriteHandler()).registerWriteHandler(new StyleWriteHandler())
            .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
        .autoCloseStream(Boolean.FALSE)
            //excel文件加密
            .password("123")
            //设置输出格式
            .excelType(ExcelTypeEnum.XLS)
            //设置sheet名
            .sheet(sheetName)
            //输出数据
            .doWrite(list);