clc;clear;close all;
folderPath = '.\data';
password = '1111';
files = dir(fullfile(folderPath, '*.xlsx'));
% 创建 Excel COM 服务器
excel = actxserver('Excel.Application');
excel.DisplayAlerts = false; % 关闭警告
for i = 1:length(files)
filePath = fullfile(folderPath, files(i).name);
try
workbook = excel.Workbooks.Open(filePath);
workbook.SaveAs(filePath, [], password);
workbook.Close(false);
fprintf('已加密: %s\n', files(i).name);
catch ME
fprintf('加密失败: %s - %s\n', files(i).name, ME.message);
end
end
excel.Quit();
delete(excel);
matlab批量给excel添加密码
最新推荐文章于 2025-09-10 18:08:14 发布