本帖最后由 zaqmlp 于 2020-4-15 19:10 编辑
- /*&cls
- @echo off
- cd /d "%~dp0"
- where *.xls *.xlsx 2>nul|cscript -nologo -e:jscript "%~f0"
- pause&exit
- */
- var fso=new ActiveXObject('Scripting.FileSystemObject');
-
- var excel=null;
- try{
- excel=new ActiveXObject('Excel.Application');
- }catch(e){
- WSH.StdErr.WriteLine('MS Excel is not install');
- WSH.Quit();
- }
- excel.Visible=true;
- excel.DisplayAlerts=false;
-
- var Password='12345'; //密码
-
- var Structure=true; //保护工作薄结构
- var Windows=true; //保护工作薄窗口
-
- var DrawingObjects=true; //保护形状
- var Contents=true; //保护内容
- var Scenarios=true; //保护方案
- var UserInterfaceOnly=false; //保护用户界面
- var AllowFormattingCells=true; //单元格格式
- var AllowFormattingColumns=true; //列格式
- var AllowFormattingRows=true; //行格式
- var AllowInsertingColumns=true; //插入列
- var AllowInsertingRows=true; //插入行
- var AllowInsertingHyperlinks=true; //插入超链接
- var AllowDeletingColumns=true; //删除列
- var AllowDeletingRows=true; //删除行
- var AllowSorting=true; //排序
- var AllowFiltering=true; //自动筛选
- var AllowUsingPivotTables=true; //数据透视表
-
- while(!WSH.StdIn.AtEndOfStream){
- var line=WSH.StdIn.ReadLine();
- var xlsfile=fso.GetFile(line);
- var book=excel.Workbooks.Open(xlsfile.Path);
- var sheetcount=book.Worksheets.Count;
- WSH.echo(xlsfile.Name);
- book.Protect(Password,Structure,Windows);
- for(var i=1;i<=sheetcount;i++){
- book.Worksheets(i).Protect(
- Password,
- DrawingObjects,
- Contents,
- Scenarios,
- UserInterfaceOnly,
- AllowFormattingCells,
- AllowFormattingColumns,
- AllowFormattingRows,
- AllowInsertingColumns,
- AllowInsertingRows,
- AllowInsertingHyperlinks,
- AllowDeletingColumns,
- AllowDeletingRows,
- AllowSorting,
- AllowFiltering,
- AllowUsingPivotTables
- );
- }
- book.Save();
- book.Close();
- }
- excel.Quit();
复制代码
|