OSDN Git Service

CompareMSExcelFiles.sct: Enclose the value in double quotation marks If a cell value...
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Thu, 9 Jul 2020 11:48:04 +0000 (20:48 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Thu, 9 Jul 2020 11:48:04 +0000 (20:48 +0900)
Plugins/dlls/CompareMSExcelFiles.sct
Testing/Data/Office/excel.xls

index 7c0756b..4fe3cb0 100644 (file)
@@ -78,17 +78,33 @@ Function writeObjectProperties(fo, items)
        Next
 End Function
 
+Function QuoteIfNeeded(str)
+       Dim fQuote
+       If InStr(str, vbTab) > 0 Then
+               fQuote = True
+       ElseIf InStr(str, """") > 0 Then
+               fQuote = True
+       ElseIf InStr(str, vbLf) > 0 Then
+               fQuote = True
+       End If
+       If fQuote Then
+               QuoteIfNeeded = """" & Replace(str, """", """""") & """"
+       Else
+               QuoteIfNeeded = str
+       End If
+End Function
+
 Function writeCellValues(fo, sht)
        Dim varCells, row, col, ary()
        varCells = sht.UsedRange.Value
        If TypeName(varCells) = "String" Then
-               fo.WriteLine varCells
+               fo.WriteLine QuoteIfNeeded(varCells)
        ElseIf Not IsEmpty(varCells) Then
                ReDim ary(UBound(varCells, 2))
                On Error Resume Next
                For row = 1 To UBound(varCells, 1)
                        For col = 1 To UBound(varCells, 2)
-                               ary(col - 1) = CStr(varCells(row, col))
+                               ary(col - 1) = QuoteIfNeeded(CStr(varCells(row, col)))
                                If Err.Number <> 0 Then
                                        ary(col - 1) = "Error" & Err.Number
                                        Err.Clear
index c514a5c..3404037 100644 (file)
Binary files a/Testing/Data/Office/excel.xls and b/Testing/Data/Office/excel.xls differ