使用bat运行diff-xls.js文件

bat代码
@echo off

Cscript "路径\diff-xls.js" %1 %2
JS代码
// extensions: xls;xlsx;xlsm;xlsb;xlam
//
// TortoiseSVN Diff script for Excel files
//
// Copyright (C) 2004-2008, 2012-2016, 2019 the TortoiseSVN team
// This file is distributed under the same license as TortoiseSVN
//
// Last commit by:
// $Author: stefankueng $
// $Date: 2019-08-04 12:31:04 +0200 (So., 04 Aug 2019) $
// $Rev: 28647 $
//
// Authors:
// Hiroki Najima <h.najima at gmail.com>, 2013
// Michael Joras <michael@joras.net>, 2008
// Suraj Barkale, 2006
// // ----- configuration -----
// Fast mode switch
// Fast mode does not copy Worksheets but require opened base document at the same time.
var bFastMode = false; // ----- constants -----
var vbCritical = 0x10;
var vbExclamation = 0x30;
//var vbInformation = 0x40; var xlNone = -4142;
var xlMaximized = -4137;
var xlArrangeStyleHorizontal = -4128;
var xlCellValue = 1;
//var xlExpression = 2;
//var xlEqual = 3;
var xlNotEqual = 4; //var vOffice95 = 7;
//var vOffice97 = 8;
//var vOffice2000 = 9;
//var vOffice2002 = 10;
var vOffice2003 = 11;
//var vOffice2007 = 12;
//var vOffice2010 = 14;
//var vOffice2013 = 15; // ----- main ----- var aWarningMessages = []; var objArgs = WScript.Arguments;
if (objArgs.length < 2)
{
Abort("Usage: [CScript | WScript] diff-xls.js base.xls new.xls", "Invalid arguments");
} var sBaseDoc = objArgs(0);
var sNewDoc = objArgs(1); var objScript = new ActiveXObject("Scripting.FileSystemObject"); if (objScript.GetBaseName(sBaseDoc) === objScript.GetBaseName(sNewDoc))
{
Abort("File '" + sBaseDoc + "' and '" + sNewDoc + "' is same file name.\nCannot compare the documents.", "Same file name");
} if (!objScript.FileExists(sBaseDoc))
{
Abort("File '" + sBaseDoc + "' does not exist.\nCannot compare the documents.", "File not found");
} if (!objScript.FileExists(sNewDoc))
{
Abort("File '" + sNewDoc + "' does not exist.\nCannot compare the documents.", "File not found");
} sBaseDoc = objScript.GetAbsolutePathName(sBaseDoc);
sNewDoc = objScript.GetAbsolutePathName(sNewDoc);
objScript = null; var objExcelApp;
try
{
objExcelApp = WScript.CreateObject("Excel.Application");
}
catch (e)
{
Abort("You must have Excel installed to perform this operation.", "Excel Instantiation Failed");
} // disable all macros
objExcelApp.AutomationSecurity = 3; //msoAutomationSecurityForceDisable var fExcelVersion = parseInt(objExcelApp.Version, 10); // Open base Excel book
var objBaseWorkbook;
try
{
objBaseWorkbook = objExcelApp.Workbooks.Open(sBaseDoc, null, true);
}
catch (e)
{
Abort("Failed to open '" + sBaseDoc + "'\nIt might not be a valid Excel file.", "File open error");
} // Open new Excel book
var objNewWorkbook;
try
{
objNewWorkbook = objExcelApp.Workbooks.Open(sNewDoc, null, true);
}
catch (e)
{
Abort("Failed to open '" + sNewDoc + "'\nIt might not be a valid Excel file.", "File open error");
} // Show Excel window
objExcelApp.Visible = true; // Arrange windows
if (objBaseWorkbook.ProtectWindows || objNewWorkbook.ProtectWindows)
{
StoreWarning("Unable to arrange windows because one or both Workbooks are protected.");
}
else
{
// Make windows a compare side by side view
if (fExcelVersion >= vOffice2003)
{
objExcelApp.Windows.CompareSideBySideWith(objExcelApp.Windows(2).Caption);
}
objExcelApp.Application.WindowState = xlMaximized;
objExcelApp.Windows.Arrange(xlArrangeStyleHorizontal);
} if (!bFastMode && objNewWorkbook.ProtectWindows)
{
StoreWarning("Fall back to fast mode because " + objNewWorkbook.Name + " is protected.");
bFastMode = true;
} // Create a special workbook for formula conversion.
var objSpecialWorkbook = objExcelApp.Workbooks.Add; // Mark differences in sNewDoc red
var length = objNewWorkbook.Worksheets.Count;
for (var i = 1; i <= length; i++)
{
var objBaseWorksheet = null;
if (i <= objBaseWorkbook.Worksheets.Count) {
objBaseWorksheet = objBaseWorkbook.Worksheets(i);
}
var objNewWorksheet = objNewWorkbook.Worksheets(i); if (objBaseWorksheet !== null) {
UnhideWorksheet(objBaseWorksheet);
}
UnhideWorksheet(objNewWorksheet); if (!bFastMode && objBaseWorksheet !== null)
{
objBaseWorkbook.Sheets(i).Copy(null, objNewWorkbook.Sheets(objNewWorkbook.Sheets.Count));
var objDummyWorksheet = objNewWorkbook.Sheets(objNewWorkbook.Sheets.Count);
objDummyWorksheet.Name = "Dummy_for_Comparison" + i;
objDummyWorksheet.Visible = true;
if (fExcelVersion >= vOffice2003)
{
objDummyWorksheet.Tab.ColorIndex = 16; // 16: Dark gray RGB(128,128,128)
}
} if (objNewWorksheet.ProtectContents)
{
StoreWarning("Unable to mark differences to " +
ToAbsoluteReference(objNewWorksheet) +
" because the Worksheet is protected.");
}
else
{
objNewWorksheet.Cells.FormatConditions.Delete();
var sFormula;
if (bFastMode && objBaseWorksheet !== null)
{
sFormula = "=INDIRECT(\"" + ToAbsoluteReference(objBaseWorksheet) + "!\"&ADDRESS(ROW(),COLUMN()))";
}
else
{
sFormula = "=INDIRECT(\"Dummy_for_Comparison" + i + "!\"&ADDRESS(ROW(),COLUMN()))";
}
sFormula = convertFormula(sFormula);
objNewWorksheet.Cells.FormatConditions.Add(xlCellValue, xlNotEqual, sFormula);
objNewWorksheet.Cells.FormatConditions(1).Interior.ColorIndex = 3; // 3:Red RGB(128,0,0)
}
} // Close the special workbook quietly
objSpecialWorkbook.Saved = true;
objSpecialWorkbook.Close(); // Activate first Worksheet
objBaseWorkbook.Sheets(1).Activate();
objNewWorkbook.Sheets(1).Activate(); // Suppress save dialog if nothing changed
objBaseWorkbook.Saved = true;
objNewWorkbook.Saved = true; // Show warnings if exist
ShowWarning(); WScript.Quit(0); // ----- functions ----- // Show Message Dialog
// VBcript's MsgBox emulation
function MsgBox(sMessage, iButtons, sTitle)
{
var objShell = new ActiveXObject("WScript.Shell");
objShell.popup(sMessage, 0, sTitle, iButtons);
} // Show an error message and quit script with cleanup Excel Application Object.
function Abort(sMessage, sTitle)
{
MsgBox(sMessage, vbCritical, sTitle);
if (objExcelApp)
{
objExcelApp.Quit();
}
WScript.Quit(1);
} // Unhide the Worksheet if it is hidden.
// This also sets color to the tab, if Office2003 or later.
// - 46 (Orange) : Hidden Worksheet
// - xlNone (default) : Not hidden Worksheet
function UnhideWorksheet(objWorksheet)
{
if (objWorksheet.Visible)
{
if (fExcelVersion >= vOffice2003)
{
if (objWorksheet.Tab.ColorIndex !== xlNone)
{
if (objWorksheet.Parent.ProtectStructure)
{
StoreWarning("Unable to set tab color to " +
ToAbsoluteReference(objWorksheet) +
" because the Workbook's structure is protected.");
}
else
{
objWorksheet.Tab.ColorIndex = xlNone;
}
}
}
}
else if (objWorksheet.Parent.ProtectStructure)
{
StoreWarning("Unable to unhide " +
ToAbsoluteReference(objWorksheet) +
" because the Workbook's structure is protected.");
}
else
{
objWorksheet.Visible = true;
if (fExcelVersion >= vOffice2003)
{
objWorksheet.Tab.ColorIndex = 10; // 10:Green RGB(0,128,0)
}
} } // Generate Absolute Reference Formula of Worksheet.
function ToAbsoluteReference(objWorksheet)
{
return "[" + objWorksheet.Parent.Name + "]" + objWorksheet.Name;
} // Convert a formula for workaround in some situation.
// Actually I don't know what will be changed between sFormula and FormulaLocal.
function convertFormula(sFormula)
{
var worksheet = objSpecialWorkbook.Sheets(1);
var originalContent = worksheet.Cells(1, 1).Formula;
worksheet.Cells(1, 1).Formula = sFormula;
sFormula = worksheet.Cells(1, 1).FormulaLocal;
worksheet.Cells(1, 1).Formula = originalContent;
return sFormula;
} // Accumulate a warning message.
function StoreWarning(sMessage)
{
aWarningMessages[aWarningMessages.length] = sMessage;
} // Show accumulated warning messages if exist.
// To avoid make huge message dialog, this limits message count to show.
function ShowWarning()
{
var aWarningMessagesLength = aWarningMessages.length;
if (aWarningMessagesLength === 0)
{
return;
} var sMessage = "The following warnings occurred while processing.\n";
for (var j = 0; j < aWarningMessagesLength; j++)
{
if (j >= 10)
{
sMessage += "... And more " + (aWarningMessagesLength - j) + " messages";
break;
}
sMessage += "[" + (j + 1) + "] " + aWarningMessages[j] + "\n";
}
MsgBox(sMessage, vbExclamation, "Warning");
}

比对xls文件的更多相关文章

  1. [数据科学] 从csv, xls文件中提取数据

    在python语言中,用丰富的函数库来从文件中提取数据,这篇博客讲解怎么从csv, xls文件中得到想要的数据. 点击下载数据文件http://seanlahman.com/files/databas ...

  2. 用DataGridView导入TXT文件,并导出为XLS文件

    使用 DataGridView 控件,可以显示和编辑来自多种不同类型的数据源的表格数据.也可以导出.txt,.xls等格式的文件.今天我们就先介绍一下用DataGridView把导入txt文件,导出x ...

  3. sharepoint2013爬xls文件:Error initializing IFilter for extension的解决方案

    最近sharepoint2013爬网出现: error initializing IFilter for extension '.xls' (Error code is 0x80030002). Th ...

  4. java上传xls文件

    using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System. ...

  5. Python中,添加写入数据到已经存在的Excel的xls文件,即打开excel文件,写入新数据

    背景 Python中,想要打开已经存在的excel的xls文件,然后在最后新的一行的数据. 折腾过程 1.找到了参考资料: writing to existing workbook using xlw ...

  6. Excel的文件打开特别慢,xls文件特别大解决一例

    Excel的文件打开特别慢,xls文件特别大解决一例 打开Excel的xls文件打开特别慢,而且操作也非常慢,动辄需要10几20分钟,很不正常.一个简单的Excel的xls文件有10几兆,甚至几百兆的 ...

  7. Excel 关于新建xls文件 新建sheet 合并sheet的VBA操作代码

    Sub 合并一个文件夹下全部xls文件中sheet到一个xls的sheet()workDir = ThisWorkbook.Path '当前xls文件所在的目录绝对路径'MsgBox workDir, ...

  8. poi excel文件上传并解析xls文件

    1.jsp页面 <form action="hw/pe_xls_upload" method="post" enctype="multipart ...

  9. php中使用PHPExcel操作excel(xls)文件

    读取中文的xls.csv文件会有问题,网上找了下资料,发现PHPExcel类库好用,官网地址:http://phpexcel.codeplex.com/ 1.读取xls文件内容  代码如下 复制代码 ...

  10. java poi导入EXCEL xls文件代码

    /** * */ package com.bn.car.common.report.excel; import java.io.FileInputStream; import java.io.IOEx ...

随机推荐

  1. 基于Web3.0的区块链图片上传

    开始前,我们先简单了解一下基本的概念,我大致归纳为以下几个点 什么是Web3.0,和区块链又有什么关系?(上回的文章不就派上用场了) 需求:开发一个基于Python的Web 3.0图片上传系统.这个系 ...

  2. 新浪微博动态 RSA 分析图文+登录

    Tips:当你看到这个提示的时候,说明当前的文章是由原emlog博客系统搬迁至此的,文章发布时间已过于久远,编排和内容不一定完整,还请谅解` 新浪微博动态 RSA 分析图文+登录 日期:2016-10 ...

  3. 掌握 Nuxt 3 中的状态管理:实践指南

    title: 掌握 Nuxt 3 中的状态管理:实践指南 date: 2024/6/22 updated: 2024/6/22 author: cmdragon excerpt: 摘要:该文指南详述了 ...

  4. 利用 device_map、torch.dtype、bitsandbytes 压缩模型参数控制使用设备

    为了更好的阅读体验,请点击这里 device_map 以下内容参考 Huggingface Accelerate文档:超大模型推理方法 在 HuggingFace 中有个重要的关键字是 device_ ...

  5. 背包DP——多重背包

    多重背包也是 0-1 背包的一个变式.与 0-1 背包的区别在于每种物品有 k 个,而非一个. 朴素 直接把相同的每个物品视作各个单独的物品,没有关联,仅条件相同: 转换后直接用01背包的状态转移方程 ...

  6. WPF在.NET9中的重大更新:Windows 11 主题

    在2023年的2月20日,在WPF的讨论区,WPF团队对路线的优先级发起了一次讨论. 对三个事项发起了投票. 第一个是Windows 11 主题 第二个是更新的控件 第三个是可空性注释 最终Windo ...

  7. 统信 UOS 重置Root账号密码 获取 Root 权限

    统信服务器默认无法用root 账号登入系统,用普通管理员登入后在切换至root账户下即可,初次使用系统时 切换至root账户前需要做很多配置 1.同信切换root账户首先要激活下系统,可以选择试用期激 ...

  8. SQLCel匹配原数据信息,更新原数据所有信息并插入新数据的过程

    使用SQLCel高效率(速度快,数据完整)的解决了我领导提的问题 "如何更新数据库中原有的数据并插入新的订单数据" 过程如下: 思路:使用字段匹配和修改字段即可解决问题,用时3分钟 ...

  9. 2.上传hdfs系统:将logs目录下的日志文件每隔十分钟上传一次 要求:上传后的文件名修为:2017111513xx.log_copy

    先在hdfs系统创建文件夹logshadoop fs -mkdir /logs 编辑shell脚本 filemv.sh #!/bin/bashPATH=/usr/local/bin:/bin:/usr ...

  10. VulnHub-DC-7渗透流程

    DC-7 kali:192.168.157.131 靶机:192.168.157.151 信息收集 nmap -sV -A -p- 192.168.157.151 虽然有robots.txt等敏感文件 ...