douzhuo2722 2019-06-23 11:25
浏览 117

开始-是否可以加密Excel工作簿

I have checked the excelize package, there's the ProtectSheet function. However this only protects the sheet from changes etc not protecting from the unauthorised access.

I have look for several other options/packages and they don't seem to offer such capabilities.

I know that ultimately I could still zip-password protect the excel file, but being able to protect the workbook itself is much preferable.

  • 写回答

1条回答 默认 最新

  • douchuifk90315 2019-07-06 14:53
    关注

    After some research it seems there's no Go packages that can achieve this. However I've come across a npm package - secure-spreadsheet that is able to password protect an excel file.

    As I needed to program the password protect operation in Go, what i did was to trigger an os command in the Go code to invoke the npm package to password protect the file.

    The Go program is deployed & executed in an alpine container, which i can install the node-npm and have access to npx command.

    code sample:

    func passProtectExcelWorkbook(filename, outFilename string) error {
        passwd := "password"
        cat := exec.Command("cat", filename)
        excel := exec.Command("npx", "secure-spreadsheet", "--password", passwd, "--input-format", excelExt)
    
        file, err := os.Create(outFilename)
        if err != nil {
            return fmt.Errorf("error when creating excel file: %v err: %v", outFilename, err)
        }
    
        defer file.Close()
    
        excel.Stdin, err = cat.StdoutPipe()
        if err != nil {
            return fmt.Errorf("error when reading from cat command output: %v", err)
        }
    
        excel.Stdout = file
    
        if err := excel.Start(); err != nil {
            return fmt.Errorf("error when starting npx command: %v", err)
        }
    
        if err := cat.Run(); err != nil {
            return fmt.Errorf("error when running cat command: %v", err)
        }
    
        return excel.Wait()
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算