XML比較ツール

xml
①control
②work
③difflist
④old
⑤new

MODULE1

Public Const titol_max = 100

Sub タイトル抽出()

    Dim csh As Worksheet
    Dim tsh As Worksheet
    Dim titols_area As Range
   
    Dim dirname As String
    Dim filename As String
   
    Dim ci As Long
    Dim ss As String
    Dim s As String
    Dim k As Long
    Dim N As Long
    Dim ti As Long
    Dim tj As Long
    Dim tj_max As Long

    Dim val
   
    Const chk_string0 = "title"
    Dim chk_len0 As Long
    chk_len0 = Len(chk_string0)

    Const chk_string1 = "resultHeading"
    Dim chk_len1 As Long
    chk_len1 = Len(chk_string1)
   
    Const chk_string2 = "resultName"
    Dim chk_len2 As Long
    chk_len2 = Len(chk_string2)
   
    Dim line_cnt(2) As Long
    Dim ttop As Long
    Dim body As Boolean
    Dim titol As String
    Dim resultHead As String
    Dim resultName As String
   
    Dim oldj As Long
    Dim newj As Long
    Dim oldend_j As Long
    Dim newend_j As Long
    Dim titol_unmatch As Long
   
    Application.ScreenUpdating = False
   
    Set csh = Worksheets("control")
    For ci = 1 To 100
        If csh.Cells(ci, 1).Value = "●" Then GoTo mark_found
    Next ci
    Stop  '●指定が無い
   
mark_found:
    Set titols_area = csh.Range(Cells(ci + 5, 5), Cells(ci + 7, titol_max + 4))
    titols_area.Cells.ClearContents
    line_cnt(1) = 0
    line_cnt(2) = 0
       
    For N = 1 To 2  '(N=1:旧、N=2:新)
        ti = 1
        ttop = 1
       
        dirname = csh.Cells(ci + N, 3).Value
        filename = csh.Cells(ci + N, 7).Value
        Open dirname & filename For Input As #1
           
        If N = 1 Then
            Set tsh = Worksheets("old")
        Else
            Set tsh = Worksheets("new")
        End If
       
        tsh.Select
        tsh.Cells.ClearContents
       
        tsh.Cells(1, 1).Value = chk_string0
        tsh.Cells(1, 2).Value = chk_string1
        tsh.Cells(1, 3).Value = chk_string2
        titols_area.Cells(N, 1).Value = chk_string0
        titols_area.Cells(N, 2).Value = chk_string1
        titols_area.Cells(N, 3).Value = chk_string2

        While Not EOF(1)
       
'表タイトル識別、抽出
            body = False
            Line Input #1, ss
            line_cnt(N) = line_cnt(N) + 1
'---------------------------------------------進捗状況表示
            If line_cnt(N) Mod 100 = 1 Then
                csh.Select
                csh.Cells(5, 6).Value = "旧:" & CStr(line_cnt(1)) & " 新:" & CStr(line_cnt(2))
                Application.ScreenUpdating = True
                Application.ScreenUpdating = False
            End If
'---------------------------------------------------------
            k = InStr(ss, chk_string0)
            If k > 0 Then
                resultHead = Mid(ss, chk_len0 + k + 1) '=の次の文字から取得
   
                Line Input #1, ss
                line_cnt(N) = line_cnt(N) + 1
                k = InStr(ss, chk_string1)
                If k > 0 Then
                    resultName = Mid(ss, chk_len1 + k + 1) '=の次の文字から取得
                   
                    Line Input #1, ss
                    line_cnt(N) = line_cnt(N) + 1
                    k = InStr(ss, chk_string2)
                    If k > 0 Then
                        resultName = Mid(ss, chk_len2 + k + 1) '=の次の文字から取得
                    Else
                        Stop  'resultHeadの次の行は、resultNameが期待値
                    End If
                Else
                    Stop  'resultHeadの次の行は、resultNameが期待値
                End If
            End If
           
'レコード開始チェック
            If Trim(ss) = "<z:row" Then
                body = True
                ti = ti + 1
            End If

'レコード内処理中
            While body
                Line Input #1, ss
                line_cnt(N) = line_cnt(N) + 1
'---------------------------------------------進捗状況表示
                If line_cnt(N) Mod 100 = 1 Then
                    csh.Select
                    csh.Cells(5, 6).Value = "旧:" & CStr(line_cnt(1)) & " 新:" & CStr(line_cnt(2))
                    Application.ScreenUpdating = True
                    Application.ScreenUpdating = False
                End If
'---------------------------------------------------------
                k = InStr(ss, "=")
                If k > 0 Then
                    titol = Trim(Left(ss, k - 1))
                    val = Trim(Mid(ss, k + 1))
                    tj = 3
                    While titols_area.Cells(N, tj).Value <> ""
                        If titols_area.Cells(N, tj).Value = titol Then
                            GoTo found
                        End If
                        tj = tj + 1
                    Wend
'titol not found
                    titols_area.Cells(N, tj).Value = titol
                    tsh.Cells(1, tj).Value = titol
                    tj_max = tj
found:
                    tsh.Cells(ti, 1).Value = resultHead
                    tsh.Cells(ti, 2).Value = resultName
                    tsh.Cells(ti, tj).Value = val
                Else
                    body = False
                End If
            Wend
        Wend
        Close #1
       
        csh.Cells(ci + N, 12).Value = line_cnt(N)
        csh.Cells(ci + N, 13).Value = ti
        csh.Cells(ci + N, 14).Value = tj_max
    Next N
   
'項目列マッチング
    csh.Select
    titol_unmatch = 0
    oldend_j = csh.Cells(ci + 1, 14).Value
    newend_j = csh.Cells(ci + 2, 14).Value
    csh.Cells(ci + 5, 4).Value = oldend_j
    csh.Cells(ci + 6, 4).Value = newend_j
   
    For newj = 1 To newend_j
        titol = titols_area.Cells(2, newj).Value
       
        For oldj = 1 To oldend_j
            If titols_area.Cells(1, oldj).Value = titol Then
                titols_area.Cells(3, newj).Value = oldj
                GoTo titol_found
            End If
        Next oldj
'oldにない
        titols_area.Cells(3, newj).Value = ""
        titol_unmatch = titol_unmatch + 1
titol_found:
    Next newj
   
    csh.Cells(ci + 9, 4).Value = titol_unmatch
   
    csh.Select
    Application.ScreenUpdating = False
    Set csh = Nothing
    Set tsh = Nothing
    Set titols_area = Nothing
   
End Sub

 

 

MODULE2

Sub 新旧シートの比較()
   
    Dim csh As Worksheet
    Dim wsh As Worksheet
    Dim dsh As Worksheet
    Dim oldsh As Worksheet
    Dim newsh As Worksheet
    Dim titols_area As Range
    Dim unmatch_area As Range
   
    Dim ci As Long
    Dim wi As Long
    Dim di As Long

    Dim oldend_i As Long
    Dim newend_i As Long
    Dim oldend_j As Long
    Dim newend_j As Long
   
    Dim oldi As Long
    Dim newi As Long
    Dim oldj As Long
    Dim newj As Long
   
    Dim oldkeyj As Long 'マッチングkeyの列No
    Dim newkeyj As Long
    Dim oldkeysj(5) As Long '最大5ケのkey指定可能
    Dim newkeysj(5) As Long
    Dim key_cnt As Long  '指定key数
    Dim key_val As String
    Dim k As Long
   
    Dim keymatch_rec_cnt As Long
    Dim record_match As Boolean
    Dim record_match_cnt As Long
    Dim work As String
    Dim unmatch_titol As String
   
    Dim i As Long
    Dim i2 As Long
    Dim j As Long
    Dim j2 As Long
    Dim old_col(titol_max) As Long
    Dim unmatch(titol_max) As Boolean   '新旧で一致ならtrue,不一致ならばfalse(行単位)
    Dim checkType(titol_max) As String  'controlシートでの特殊処理指定

    Dim titol As String
    Dim titol_unmatch As Long
    Dim key
    Dim color_val As Long
   
    Dim date02_y As String
    Dim date02_m As String
    Dim date02_d As String
   
    Application.ScreenUpdating = False
    Set csh = Worksheets("control")
    Set wsh = Worksheets("work")
    Set dsh = Worksheets("difflist")
    Set oldsh = Worksheets("old")
    Set newsh = Worksheets("new")
   
   
    dsh.Cells.Clear
   
    For ci = 1 To 100
        If csh.Cells(ci, 1).Value = "●" Then GoTo mark_found
    Next ci
    Stop  '●指定が無い
   
mark_found:
'有効エリアを抽出したoldsh.newshの最終行列の取得
    oldend_i = csh.Cells(ci + 1, 13).Value
    newend_i = csh.Cells(ci + 2, 13).Value
    oldend_j = csh.Cells(ci + 1, 14).Value
    newend_j = csh.Cells(ci + 2, 14).Value
    csh.Cells(ci + 12, 5).Value = oldend_i - 1
    csh.Cells(ci + 13, 5).Value = newend_i - 1
           
    Set titols_area = csh.Range(Cells(ci + 5, 5), Cells(ci + 8, titol_max + 4))
    Set unmatch_area = csh.Range(Cells(ci + 15, 5), Cells(ci + 17, titol_max + 4))
           
'新旧項目対応の配列初期化
    For newj = 1 To newend_j
        old_col(newj) = titols_area.Cells(3, newj).Value
        checkType(newj) = titols_area.Cells(4, newj).Value
    Next newj
'controlシートのアンマッチサマリエリア初期化
    For i = 1 To 3
        For j = 1 To titol_max
            unmatch_area.Cells(i, j).Value = ""
        Next j
    Next i

'diffシートにヘッダ情報セット
    di = di + 1
    dsh.Cells(di, 1).Value = "'" & String(100, "=")
    dsh.Cells(di + 1, 1).Value = "旧ファイル" & csh.Cells(ci + 1, 7).Value
    dsh.Cells(di + 2, 1).Value = "新ファイル" & csh.Cells(ci + 2, 7).Value
    di = di + 3
    dsh.Cells(di, 1).Value = "項目名"
    For j = 1 To newend_j
        dsh.Cells(di, j + 1).Value = titols_area.Cells(2, j).Value
    Next j

'マッチングkey
    For k = 1 To 5
        oldkeysj(k) = 0   'oldkeysj,newkeysjは、有効アリア内の相対列番号
        newkeysj(k) = 0
    Next k
           
    key_cnt = 0
    For j = 1 To newend_j
        If checkType(j) = "key" Then
            newkeyj = j
            key_cnt = key_cnt + 1
            If key_cnt > 5 Then Stop 'key指定が多すぎる
            newkeysj(key_cnt) = j
            oldkeyj = old_col(j)
            If oldkeyj < 1 Then Stop
            oldkeysj(key_cnt) = oldkeyj
        End If
    Next j
    If key_cnt = 0 Then Stop  'key指定が無い

    keymatch_rec_cnt = 0
    record_match_cnt = 0
           
'key対応用ワークシート(wsh)の設定
    wsh.Activate
    wsh.Cells.Clear
    wsh.Cells(1, 1).Value = "旧ファイル"
    wsh.Cells(1, 3).Value = "旧key"
    For i = 2 To oldend_i
        wsh.Cells(i, 2).Value = i
        key_val = oldsh.Cells(i, oldkeysj(1)).Value
        For k = 2 To key_cnt
            key_val = key_val & "|" & oldsh.Cells(i, oldkeysj(k)).Value
        Next k
        wsh.Cells(i, 3).NumberFormatLocal = "@"
        wsh.Cells(i, 3).Value = key_val
    Next i
    wsh.Cells(1, 6).Value = "新ファイル"
    wsh.Cells(1, 8).Value = "新key"
    For i = 2 To newend_i
        wsh.Cells(i, 7).Value = i
        key_val = newsh.Cells(i, newkeysj(1)).Value
        For k = 2 To key_cnt
            key_val = key_val & "|" & newsh.Cells(i, newkeysj(k)).Value
        Next k
        wsh.Cells(i, 8).NumberFormatLocal = "@"
        wsh.Cells(i, 8).Value = key_val
'newshのkeyを元に、oldshで同じkeyのレコードを探す

        For i2 = 2 To oldend_i
            If wsh.Cells(i2, 3).Value = key_val Then
                wsh.Cells(i2, 4).Value = i
                wsh.Cells(i, 9).Value = i2
                keymatch_rec_cnt = keymatch_rec_cnt + 1
                GoTo key_found
            End If
        Next i2
'key_not found
'               特に処理はない(new olny)
key_found:
    Next i
'キーマッチ行数表示
    csh.Cells(ci + 12, 6).Value = csh.Cells(ci + 12, 5).Value - keymatch_rec_cnt
    csh.Cells(ci + 13, 6).Value = csh.Cells(ci + 13, 5).Value - keymatch_rec_cnt
    csh.Cells(ci + 12, 7).Value = keymatch_rec_cnt
           
'相手のkeyの無い行のみ色替(最初に全体の色を消す)
'      旧
    oldsh.Activate
    oldsh.Cells.Interior.Color = RGB(255, 255, 255)
    For oldi = 2 To oldend_i
        If wsh.Cells(oldi, 4).Value = "" Then
            oldsh.Rows(CStr(oldi) & ":" & CStr(oldi)).Interior.Color = RGB(0, 255, 255)
        End If
    Next oldi
'       新
    newsh.Activate
    newsh.Cells.Interior.Color = RGB(255, 255, 255)
    For newi = 2 To newend_i
        If wsh.Cells(newi, 9).Value = "" Then
            newsh.Rows(CStr(newi) & ":" & CStr(newi)).Interior.Color = RGB(0, 255, 255)
        End If
    Next newi

    For newi = 2 To newend_i
'---------------------------------------------進捗状況表示
        If (newi Mod 10 = 2) Or (newi = newend_i) Then
            csh.Activate
            Application.ScreenUpdating = True
            csh.Cells(6, 6).Value = "'" & CStr(newi) & " / " & CStr(newend_i)
            Application.ScreenUpdating = False
        End If
'---------------------------------------------
        oldi = CLng(wsh.Cells(newi, 9).Value)
        If oldi > 0 Then   ' keyマッチ
'           項目単位チェック
            record_match = True
                   
            For newj = 1 To newend_j
                unmatch(newj) = True
                If old_col(newj) = 0 Then GoTo next_col
                oldj = old_col(newj)

'突合パターン別項目比較
                Select Case checkType(newj)
                Case "key", "skip" '無視
                    GoTo cell_match
                Case ""  'そのままの値でチェック
                    If newsh.Cells(newi, newj).Value = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                Case "date01"
                    work = Replace(oldsh.Cells(oldi, oldj).Value, "-", "/", 1, 2, vbTextCompare)
                    If newsh.Cells(newi, newj).Value = work Then GoTo cell_match
                Case "BZ"    '旧の0と新のNullは同一とみなす
                    If oldsh.Cells(oldi, oldj).Value = 0 Then
                        If newsh.Cells(newi, newj).Value = "" Then GoTo cell_match
                    End If
                    If newsh.Cells(newi, newj).Value = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
'***************************特殊な突合パターンがあれば、ここに追加する**********************
                Case "date02"
                    date02_y = "20" & Mid(newsh.Cells(newi, newj), 6, 2)
                    date02_m = Mid(newsh.Cells(newi, newj), 3, 3)
                    date02_d = Mid(newsh.Cells(newi, newj), 1, 2)
                    Select Case date02_m
                    Case "JAN"
                        If date02_y & "-01-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case "FEB"
                        If date02_y & "-02-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case "MAR"
                        If date02_y & "-03-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case "APR"
                        If date02_y & "-04-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case "MAY"
                        If date02_y & "-05-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case "JUN"
                        If date02_y & "-06-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case "JUL"
                        If date02_y & "-07-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case "AUG"
                        If date02_y & "-08-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case "SEP"
                        If date02_y & "-09-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case "OCT"
                        If date02_y & "-10-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case "NOV"
                        If date02_y & "-11-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case "DEC"
                        If date02_y & "-12-" & date02_d = oldsh.Cells(oldi, oldj).Value Then GoTo cell_match
                    Case Else
                        Stop
                    End Select
                   
                Case "date03"
                    work = Replace(oldsh.Cells(oldi, oldj).Value, "-", "", 1, 2, vbTextCompare)
                    work = Replace(work, "T00:00:00", "", 1, 2, vbTextCompare)
                    If newsh.Cells(newi, newj).Value = work Then GoTo cell_match
                   
                Case "case"
                    If UCase(newsh.Cells(newi, newj).Value) = UCase(oldsh.Cells(oldi, oldj).Value) Then GoTo cell_match
'******************************ここまで追加した突合パターン*********************************
                Case Else
                    Stop
                End Select
'cell unmatch
                record_match = False
                unmatch(newj) = False
                       
'controlシートへのアンマッチサマリ反映
                unmatch_titol = titols_area.Cells(2, newj).Value
                j2 = 1
                While unmatch_area.Cells(1, j2).Value <> ""
                    If unmatch_area.Cells(1, j2).Value = unmatch_titol Then GoTo already_set
                    j2 = j2 + 1
                Wend
'アンマッチ項目名未登録
                unmatch_area.Cells(1, j2).Value = unmatch_titol
                unmatch_area.Cells(2, j2).Value = "旧=" & CStr(oldj) & " ,新=" & CStr(newj)
already_set:
                unmatch_area.Cells(3, j2).Value = unmatch_area.Cells(3, j2).Value + 1
                GoTo next_col
cell_match:
next_col:
            Next newj
            GoTo record_check_end
        Else
'new_rec_only(旧が見つからない)
            record_match = False
        End If

record_check_end:
        If record_match Then
            record_match_cnt = record_match_cnt + 1
        ElseIf oldi > 0 Then
'アンマッチがあるので、diffシートに 旧、新のレコードを表示
            dsh.Cells(di + 1, 1).Value = "旧"
            dsh.Cells(di + 2, 1).Value = "新"

'           旧色替
            oldsh.Activate
            For newj = 1 To newend_j
                If unmatch(newj) = False Then
                    oldj = old_col(newj)
                    oldsh.Range(Cells(oldi, oldj), Cells(oldi, oldj)).Interior.Color = RGB(0, 255, 255)
                End If
            Next newj
'           新色替
            newsh.Activate
            For newj = 1 To newend_j
                If unmatch(newj) = False Then
                    newsh.Range(Cells(newi, newj), Cells(newi, newj)).Interior.Color = RGB(0, 255, 255)
                End If
            Next newj
'           diffシート色替&値セット
            dsh.Activate
            For newj = 1 To newend_j
                If old_col(newj) = 0 Then
                    dsh.Cells(di + 1, newj + 1).Value = "<対象なし>"
                Else
                    oldj = old_col(newj)
                    dsh.Cells(di + 1, newj + 1).Value = "'" & CStr(oldsh.Cells(oldi, oldj).Value)
                    If unmatch(newj) = False Then
                        dsh.Range(Cells(di + 1, newj + 1), Cells(di + 1, newj + 1)).Interior.Color = RGB(0, 255, 255)
                    End If
                End If                        '文字列に変換してセット
                dsh.Cells(di + 2, newj + 1).Value = "'" & CStr(newsh.Cells(newi, newj).Value)
            Next newj
            di = di + 2
                   
        End If
    Next newi
           
'ファイル突合サマリ表示(全項目一致したレコード件数)
    csh.Cells(ci + 12, 8).Value = record_match_cnt

    csh.Select
    Application.ScreenUpdating = True
   
    Set csh = Nothing
    Set oldsh = Nothing
    Set newsh = Nothing
    Set titols_area = Nothing
    Set unmatch_area = Nothing
End Sub

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值