Java处理压缩包里的excel,如何密码保护Java中的压缩Excel文件?

I have a question about password protecting an Excel file.

The situation is that, I have a zip file, that has an Excel file in it. I need to write a Java program, to password protect the Excel file. Hence, the user should be able to unzip the file (the zip file need not be password protected). But, the Excel needs to be password-protected. When the user tries to unzip the file, he should be able to do so.

And when he tries to open the Excel file (which is inside the unzipped folder), it must ask for a password. The question is similar to Protect excel file with java, with the added complexity that, the Excel file is zipped.

I have code, that password protects only the zip file, but this is not what I want.

import java.io.File;

import java.util.ArrayList;

import net.lingala.zip4j.core.ZipFile;

import net.lingala.zip4j.exception.ZipException;

import net.lingala.zip4j.model.ZipParameters;

import net.lingala.zip4j.util.Zip4jConstants;

/**

* Demonstrates adding files to zip file with standard Zip Encryption

*/

public class AddFilesWithStandardZipEncryption

{

public AddFilesWithStandardZipEncryption()

{

try {

// Initiate ZipFile object with the path/name of the zip file.

//ZipFile zipFile = new ZipFile("c:\\ZipTest\\AddFilesWithStandardZipEncryption.zip");

ZipFile zipFile = new ZipFile("C:\\homepage\\workspace\\PasswordProtectedFiles\\new.zip");

// Build the list of files to be added in the array list

// Objects of type File have to be added to the ArrayList

ArrayList filesToAdd = new ArrayList();

//filesToAdd.add(new File("C:\\homepage\\workspace\\passwordprotectedzipfile\\profile\\profile.txt"));

filesToAdd.add(new File("C:\\homepage\\workspace\\PasswordProtectedFiles\\new.xlsx"));

//filesToAdd.add(new File("c:\\ZipTest\\myvideo.avi"));

//filesToAdd.add(new File("c:\\ZipTest\\mysong.mp3"));

// Initiate Zip Parameters which define various properties such

// as compression method, etc.

ZipParameters parameters = new ZipParameters();

parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to store compression

// Set the compression level

parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

// Set the encryption flag to true

// If this is set to false, then the rest of encryption properties are ignored

parameters.setEncryptFiles(true);

// Set the encryption method to Standard Zip Encryption

parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);

// Set password

parameters.setPassword("test123!");

// Now add files to the zip file

// Note: To add a single file, the method addFile can be used

// Note: If the zip file already exists and if this zip file is a split file

// then this method throws an exception as Zip Format Specification does not

// allow updating split zip files

zipFile.addFiles(filesToAdd, parameters);

}

catch (ZipException e)

{

e.printStackTrace();

}

}

public static void main(String[] args)

{

new AddFilesWithStandardZipEncryption();

}

}

解决方案

Without uncompressing, Its impossible to password protect excel which is inside a zip file.

Here is what you can do

内容概要:本文详细介绍了如何使用Hugging Face Transformers库进行大模型推理,涵盖环境配置、模型下载、缓存管理、离线使用、文本生成、推理pipeline及模型量化技术。重点讲解了使用LLMs进行自回归生成的核心流程,包括token选择策略、生成参数配置(如max_new_tokens、do_sample)、填充方式(左填充的重要性)以及常见陷阱的规避方法。同时深入探讨了多种量化技术(如GPTQ、AWQ、bitsandbytes的4位/8位量化),并通过实例演示了如何加载本地模型、应用聊天模板、结合Flash Attention优化性能,并实现CPU-GPU混合卸载以应对显存不足的问题。; 适合人群:具备Python编程基础和深度学习基础知识,熟悉Transformer架构,从事NLP或大模型相关工作的研究人员、工程师和技术爱好者;尤其适合需要在资源受限环境下部署大模型的开发者。; 使用场景及目标:①掌握Hugging Face Transformers库的核心API,实现大模型的本地加载与高效推理;②理解和避免大模型生成过程中的常见问题(如输出过短、重复生成、填充错误等);③应用量化技术降低大模型内存占用,实现在消费级GPU或CPU上的部署;④构建支持批量处理和多模态任务的推理流水线。; 阅读建议:此资源理论与实践紧密结合,建议读者边阅读边动手实践,复现文中的代码示例,并尝试在不同模型和硬件环境下进行调优。重点关注生成配置、量化参数和设备映射策略,结合具体应用场景灵活调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值