From 86ea0c135cdd91f287c1a6bc29b7a279bbf6b99b Mon Sep 17 00:00:00 2001 From: Tim Gerundt Date: Thu, 28 Feb 2008 22:42:28 +0000 Subject: [PATCH] PATCH: [ 1510293 ] A new Excel plugin - better error handling. - Add first parts --- .../CompareMSExcelFiles/CompareMSExcelFiles.vbp | 4 +-- .../src_VB/CompareMSExcelFiles/WinMergeScript.cls | 33 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Plugins/src_VB/CompareMSExcelFiles/CompareMSExcelFiles.vbp b/Plugins/src_VB/CompareMSExcelFiles/CompareMSExcelFiles.vbp index dac36cc69..bacf4edaa 100644 --- a/Plugins/src_VB/CompareMSExcelFiles/CompareMSExcelFiles.vbp +++ b/Plugins/src_VB/CompareMSExcelFiles/CompareMSExcelFiles.vbp @@ -13,10 +13,10 @@ CompatibleMode="1" CompatibleEXE32="CompareMSExcelFiles.dll" MajorVer=1 MinorVer=0 -RevisionVer=2 +RevisionVer=3 AutoIncrementVer=0 ServerSupportFiles=0 -VersionFileDescription="WinMerge Plugin for MS-Excel flies" +VersionFileDescription="WinMerge Plugin for MS-Excel files" VersionLegalCopyright="WinMerge" VersionProductName="WinMerge CompareMSExcelFiles Plugin" CompilationType=0 diff --git a/Plugins/src_VB/CompareMSExcelFiles/WinMergeScript.cls b/Plugins/src_VB/CompareMSExcelFiles/WinMergeScript.cls index 3aafedde6..03001ae09 100644 --- a/Plugins/src_VB/CompareMSExcelFiles/WinMergeScript.cls +++ b/Plugins/src_VB/CompareMSExcelFiles/WinMergeScript.cls @@ -15,6 +15,7 @@ Attribute VB_Exposed = True ' This is a plugin for WinMerge. ' It will display the text content of MS Excel files. ' Copyright (C) 2005 Christian List +' Portions contributed by March Hare Software Ltd February 2006 ' ' This program is free software; you can redistribute it and/or modify ' it under the terms of the GNU General Public License as published by @@ -68,6 +69,7 @@ End Property Public Property Get LastErrorNumber() As Long LastErrorNumber = myLastErrorNumber End Property + Public Property Get LastErrorString() As String LastErrorString = myLastErrorString End Property @@ -75,7 +77,12 @@ Private Function GetComponentCount(objDoc As Object) ' Returns 0 if there is a problem accessing VBComponents On Error GoTo ErrHandler - GetComponentCount = objDoc.VBProject.VBComponents.Count + GetComponentCount = 0 + If Not objDoc.VBProject Is Nothing Then + If Not objDoc.VBProject.VBComponents Is Nothing Then + GetComponentCount = objDoc.VBProject.VBComponents.Count + End If + End If Exit Function @@ -83,6 +90,20 @@ ErrHandler: GetComponentCount = 0 End Function +Private Function GetDocProperty(objDoc As Object, pName As String) + On Error GoTo ErrHandler + + GetDocProperty = "" + If Not objDoc.BuiltinDocumentProperties.Item(pName) Is Nothing Then + GetDocProperty = objDoc.BuiltinDocumentProperties.Item(pName).Value + End If + + Exit Function + +ErrHandler: + GetDocProperty = "" +End Function + Public Function UnpackFile(fileSrc As String, fileDst As String, ByRef bChanged As Boolean, ByRef subcode As Long) As Boolean On Error GoTo CleanUp @@ -135,12 +156,11 @@ Public Function UnpackFile(fileSrc As String, fileDst As String, ByRef bChanged For Each p In objDoc.BuiltinDocumentProperties oTextToSave = oTextToSave + p.Name oTextToSave = oTextToSave & " = " - itemValue = "?" - itemValue = objDoc.BuiltinDocumentProperties.Item(p.Name).Value + itemValue = GetDocProperty(objDoc, p.Name) If itemValue <> "" Then oTextToSave = oTextToSave + itemValue End If - oTextToSave = oTextToSave + vbCrLf + oTextToSave = oTextToSave + vbCrLf Next On Error GoTo 0 oTextToSave = oTextToSave & vbCrLf @@ -186,10 +206,12 @@ Public Function UnpackFile(fileSrc As String, fileDst As String, ByRef bChanged End If ' Names - oTextToSave = oTextToSave & "Names in document" & vbCrLf On Error Resume Next Dim nms As Object Set nms = objDoc.Names + If nms.Count > 0 Then + oTextToSave = oTextToSave & "Names in document" & vbCrLf + End If Dim iCountNames As Integer For iCountNames = 1 To nms.Count oTextToSave = oTextToSave + nms(iCountNames).Name @@ -244,7 +266,6 @@ Public Function UnpackFile(fileSrc As String, fileDst As String, ByRef bChanged iCountSheets = iCountSheets + 1 Next - ' Save the collected text hFile = FreeFile Open fileDst For Output Shared As #hFile -- 2.11.0