ruby-on-rails - xlsx中的文件加密密码
问题描述
目前,我正在使用 gem caxlsx 生成我的 excel'
有没有人在生成excel文件之前尝试提交密码?
这里的目标。是用户点击按钮然后会弹出一些文本来输入excel的密码。然后系统会在浏览器中自动生成excel下载。
解决方案
查看文档,gem 支持密码保护表。
require 'axlsx'
p = Axlsx::Package.new
wb = p.workbook
s = wb.styles
unlocked = s.add_style locked: false
wb.add_worksheet(name: 'Sheet Protection') do |sheet|
sheet.sheet_protection do |protection|
protection.password = 'fish'
protection.auto_filter = false
end
sheet.add_row [1, 2, 3], style: unlocked # These cells won't be locked
sheet.add_row [4, 5, 6]
sheet.add_row [7, 8, 9]
# Set up auto filters
sheet.auto_filter = 'A1:C3'
end
p.serialize 'sheet_protection_example.xlsx'
请参阅https://github.com/caxlsx/caxlsx/blob/master/examples/sheet_protection_example.md
推荐阅读
- c++ - 移动构造函数与移动赋值
- python - 实例变量作为其他实例变量的函数
- php - 根据 POST 请求传递的参数从 MYSQL 数据库中过滤数据
- ubuntu - 如何将 CudNN 安装到 ububntu 18.04?我无法从 cuda.h 获得许可,它是只读的,我无法转换它
- vector - 将 Vector 3D 旋转少量
- bash - 如何从路径中获取子文件夹
- r - 从R闪亮的ui中选择y变量的geom_boxplot
- java - 即使我确定该项目在数组列表中,我的 binarySearch 也会返回负索引
- xml - 来自 excel 的错误 - 列表列表 - 我该如何解决?
- c++ - malloc 在 C++17 中是否返回“无效指针值”?