-
Notifications
You must be signed in to change notification settings - Fork 2
/
json.bas
executable file
·1131 lines (890 loc) · 39.6 KB
/
json.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "json导出"
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredaccess&, ByVal bInherithandle&, ByVal dwProcessid&) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpexitcode As Long) As Long
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400
Const isRun = True
'换行开关
Const vbBr = vbCrLf
'数值错误检测开关
Const checkErr = True
Sub SaveOffice()
SaveJsonOneFile "官职", "office\office"
End Sub
Sub SaveMainQuest()
SaveJsonOneFile "主线任务", "mainquest\mainquest"
End Sub
Sub SaveQD()
SaveJson "渠道DATA", "qd\qd_"
End Sub
Public Sub ShellWaitAppLication(ByVal sCommandLine As String)
On Error GoTo Z
If Not isRun Then
GoTo Z
End If
Dim hShell As Long
Dim hProc As Long
Dim lExit As Long
hShell = Shell(sCommandLine, vbHide) 'vbhide
hProc = OpenProcess(&H400, False, hShell)
Do
GetExitCodeProcess hProc, lExit
DoEvents
Loop While lExit = &H103
Z:
End Sub
Sub Package_all()
AutoPackage (0)
End Sub
Sub Package_mdpi()
AutoPackage (1)
End Sub
Sub Package_hdpi()
AutoPackage (2)
End Sub
'自动打包
Sub AutoPackage(dpi)
projectPath = "d:\workspace\sanguo\" '项目路径
sdkToolsPath = "d:\android-sdk-windows\tools\" '安卓工具包路径
toolsPath = "d:\android-sdk-windows\platform-tools\" '安卓工具包路径
androidPath = "d:\android-sdk-windows\platforms\android-8\" '安卓平台路径
javaBinPath = "C:\Program Files\Java\jdk1.6.0_26\bin\"
logoPath = "d:\logo\"
apkPath = "d:\workspace\" '输出路径
apkVer = "9300" '输出版本号,用于生成打包文件名
apkVerStr = "1.4." + apkVer '版本号完整名称
If dpi = 1 Then
dpi_path = " -c mdpi,nodpi"
apkPath = apkPath & "mdpi_"
ElseIf dpi = 2 Then
dpi_path = " -c hdpi,nodpi"
apkPath = apkPath & "hdpi_"
Else
dpi_path = " "
apkPath = apkPath & ""
End If
sheetName = "渠道DATA" '渠道数据表名
intRow = 3
'改版本信息
varFilePath = projectPath + "AndroidManifest.xml"
Set fso = CreateObject("scripting.filesystemobject")
Set fs = fso.OpenTextFile(varFilePath, 1, True)
xmlData = fs.readall
fs.Close
spos = InStr(1, xmlData, "android:versionCode=")
sxml = Mid(xmlData, 1, spos - 1)
sxml = sxml + "android:versionCode=""" + apkVer + """ android:versionName=""" + apkVerStr + """>"
spos = InStr(1, xmlData, """>") + 2
eXml = Mid(xmlData, spos, Len(xmlData) - spos + 1)
xmlData = sxml + eXml
Set fs = fso.OpenTextFile(varFilePath, 2, True)
fs.write xmlData
fs.Close
If dpi = 1 Then
fso.movefolder projectPath & "assets\c_800x480", "d:\c_800x480"
ElseIf dpi = 2 Then
fso.movefolder projectPath & "assets\c_480x320", "d:\c_480x320"
End If
outScript = "#脚本开始" + vbCrLf
Do Until Sheets(sheetName).Cells(intRow, 1).Value = ""
If Sheets(sheetName).Cells(intRow, 5).Value = "已生成!" Then
GoTo ED
End If
'MsgBox projectPath + "bin\classes.dex"
'If fso.FileExists(projectPath + "bin\classes.dex") Then
' fso.deletefile projectPath + "bin\classes.dex", True
' fso.deletefile projectPath + "bin\resources.ap_", True
'End If
jsonData = ""
For r = 1 To 4
If jsonData = "" Then
jsonData = "{"
Else
jsonData = jsonData & ","
End If
If IsNumeric(Sheets(sheetName).Cells(intRow, r).Value) And Sheets(sheetName).Cells(1, r).Value <> "id" Then
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & Sheets(sheetName).Cells(intRow, r).Value
Else
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:""" & Sheets(sheetName).Cells(intRow, r).Value & """"
End If
Next
jsonData = jsonData + "}"
outScript = outScript + vbCrLf + "#生成" & Sheets(sheetName).Cells(intRow, 2).Value & "脚本"
qdInfoPath = projectPath + "\assets\c_common\qd\qd.json"
'生成渠道信息
SaveToFile jsonData, qdInfoPath
'把LOGO拷贝过去
If Sheets(sheetName).Cells(intRow, 4).Value = "1" Then
If fso.FileExists(logoPath + "logo_" + Sheets(sheetName).Cells(intRow, 1).Value + ".png") Then
fso.copyfile logoPath + "logo_" + Sheets(sheetName).Cells(intRow, 1).Value + ".png", projectPath + "res\drawable-hdpi\qd_logo.png", True
End If
End If
Set fs = fso.OpenTextFile(varFilePath, 1, True)
xmlData = fs.readall
fs.Close
tmpStr = "android:name=""UMENG_APPKEY""/>"
spos = InStr(1, xmlData, tmpStr) + Len(tmpStr)
sxml = Mid(xmlData, 1, spos)
spos = InStr(spos, xmlData, "</application>")
eXml = Mid(xmlData, spos, Len(xmlData) - spos + 1)
tmpStr = "<meta-data android:value=""" & Sheets(sheetName).Cells(intRow, 1).Value & """ android:name=""UMENG_CHANNEL""/>" & vbCrLf
xmlData = sxml + tmpStr + eXml
Set fs = fso.OpenTextFile(varFilePath, 2, True)
fs.write xmlData
fs.Close
Sheets(sheetName).Cells(intRow, 5).Value = "10%"
'使用aapt生成R.java类文件
makeScript = toolsPath + "aapt.exe package -f -m -J " + projectPath + "gen -S " + projectPath + "res -I " + androidPath + "android.jar -M " + projectPath + "AndroidManifest.xml -I " + projectPath + "lib\gson-1.7.1.jar -I " + projectPath + "lib\AndroidAnalyticSDK3.2.1.jar"
outScript = outScript + vbCrLf + makeScript
ShellWaitAppLication (makeScript)
Sheets(sheetName).Cells(intRow, 5).Value = "30%"
'第三步 编译.java类文件生成class文件
makeScript = "javac -encoding utf-8 -target 1.5 -classpath " + projectPath + "lib -bootclasspath " + androidPath + "android.jar -d " + projectPath + "bin -sourcepath " + projectPath + "src\ " + projectPath + "gen\com\mango\sanguo\R.java"
ShellWaitAppLication (makeScript)
outScript = outScript + vbCrLf + makeScript
Sheets(sheetName).Cells(intRow, 5).Value = "40%"
'使用android SDK提供的dx.bat命令行脚本生成classes.dex文件,加上第三方的包
makeScript = "" + toolsPath + "dx.bat --dex --output=" + projectPath + "bin\classes.dex " + projectPath + "bin\classes " + projectPath + "lib\gson-1.7.1.jar " + projectPath + "lib\AndroidAnalyticSDK3.2.1.jar"
ShellWaitAppLication (makeScript)
outScript = outScript + vbCrLf + makeScript
Sheets(sheetName).Cells(intRow, 5).Value = "50%"
'使用Android SDK提供的aapt.exe生成资源包文件(包括res、assets、androidmanifest.xml等)
makeScript = toolsPath + "aapt.exe package -f " + dpi_path + " -M " + projectPath + "AndroidManifest.xml -S " + projectPath + "res -A " + projectPath + "assets -I " + androidPath + "android.jar -F " + projectPath + "bin\resources.ap_ -I " + projectPath + "lib\gson-1.7.1.jar -I " + projectPath + "lib\AndroidAnalyticSDK3.2.1.jar"
ShellWaitAppLication (makeScript)
outScript = outScript + vbCrLf + makeScript
Sheets(sheetName).Cells(intRow, 5).Value = "60%"
'生成未签名的apk安装文件
apkName = "fytx_" + Sheets(sheetName).Cells(intRow, 1).Value + "_" + apkVer + ".apk"
makeScript = "" + sdkToolsPath + "apkbuilder.bat " + projectPath + "bin\" + apkName + " -u -z " + projectPath + "bin\resources.ap_ -f " + projectPath + "bin\classes.dex -rf " + projectPath + "src -rj " + projectPath + "lib >>d:\db.log"
ShellWaitAppLication (makeScript)
outScript = outScript + vbCrLf + makeScript
Sheets(sheetName).Cells(intRow, 5).Value = "70%"
'使用jdk的jarsigner对未签名的包进行apk签名
makeScript = javaBinPath & "jarsigner -keystore " + sdkToolsPath + "xasg.key -storepass mango123 -keypass mango123 -digestalg SHA1 -sigalg MD5withRSA -signedjar " + projectPath + "bin\signed_" + apkName + " " + projectPath + "bin\" + apkName + " cert"
ShellWaitAppLication (makeScript)
outScript = outScript + vbCrLf + makeScript
Sheets(sheetName).Cells(intRow, 5).Value = "80%"
'使用android sdk的zipalign工具优化已签名的apk文件
makeScript = sdkToolsPath + "zipalign -v -f 4 " + projectPath + "bin\signed_" + apkName + " " + apkPath + apkName
ShellWaitAppLication (makeScript)
outScript = outScript + vbCrLf + makeScript
Sheets(sheetName).Cells(intRow, 5).Value = "90%"
Sheets(sheetName).Cells(intRow, 5).Value = "已生成!"
If intRow > 4 Then
'Return
End If
ED:
intRow = intRow + 1
Loop
If dpi = 1 Then
fso.movefolder "d:\c_800x480", projectPath & "assets\c_800x480"
ElseIf dpi = 2 Then
fso.movefolder "d:\c_480x320", projectPath & "assets\c_480x320"
End If
SaveToFile outScript, "d:\db.log"
Set fs = Nothing
Set fso = Nothing
End Sub
Sub SaveNPC()
SaveJson "NPC军团", "corps\team\tm_"
End Sub
Sub SaveNPCWarpath()
SaveJsonByFileName "NPC军团部队", "corps\troop\tp_"
End Sub
Sub SaveLegionScience()
SaveJsonOneFile "军团科技数值表", "legion\lg_sc"
End Sub
Sub SaveShop()
SaveJsonOneFile "商店", "shop\itemlist"
End Sub
Sub SaveMerchant()
SaveJson "商人", "merchant\mc_"
End Sub
Sub SaveTax()
SaveJson "征收事件", "tax\ti_"
End Sub
'导出科技JSON数据
Sub SaveScience()
SaveJson "科技", "science\sc_"
End Sub
Private Sub SaveJson(sheetName, filePath)
Set fso = CreateObject("scripting.filesystemobject")
intCol = 1
intRow = 3
jsonData = ""
errData = ""
Do Until Sheets(sheetName).Cells(1, intCol).Value = ""
'Range("M" + intLen).Value = ""
'MsgBox Sheets(sheetName).Cells(1, intCol).Value
intCol = intCol + 1
Loop
'保存数据
folderPath = "e:\data\"
'MsgBox UBound(Split(filePath, "\"))
'MsgBox Split(filePath, "\")(UBound(Split(filePath, "\")) - 1)
tmppath = folderPath & Replace(filePath, "\" & Split(filePath, "\")(UBound(Split(filePath, "\"))), "\")
If Not fso.FolderExists(tmppath) Then
fso.CreateFolder tmppath
End If
Do Until Sheets(sheetName).Cells(intRow, 1).Value = ""
jsonData = ""
If Sheets(sheetName).Cells(intRow, 1) <> "" Then
For r = 1 To intCol - 1
If jsonData = "" Then
jsonData = "{"
Else
jsonData = jsonData & "," & vbBr
End If
'MsgBox Sheets(sheetName).Cells(intRow, r).Value
If IsNumeric(Sheets(sheetName).Cells(intRow, r).Value) Then
t = Trim(CStr(Sheets(sheetName).Cells(intRow, r).Value))
b = Sheets(sheetName).Cells(intRow, r)
If t = "True" Or t = "False" Then
t = LCase(t)
End If
If b = "" And checkErr Then
errData = errData & vbBr & "[" & sheetName & "]" & Sheets(sheetName).Cells(intRow, 2).Value & "中属性" & Sheets(sheetName).Cells(1, r).Value & "值为空"
ElseIf Mid(t, 1, 1) = "." Then
t = "0" + t
End If
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & t
Else
If Mid(Sheets(sheetName).Cells(intRow, r).Value, 1, 1) = "[" Then
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & Sheets(sheetName).Cells(intRow, r).Value
Else
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:""" & Sheets(sheetName).Cells(intRow, r).Value & """"
End If
End If
Next r
jsonData = jsonData + "}"
'Set jsonFile = fso.CreateTextFile(filePath, True)
'jsonFile.WriteLine (jsonData)
'jsonFile.Close
SaveToFile jsonData, folderPath & filePath & Sheets(sheetName).Cells(intRow, 1).Value & ".json"
End If
intRow = intRow + 1
Loop
Set fso = Nothing
MsgBox "操作成功!" & errData
End Sub
Private Sub SaveJsonOneFile(sheetName, filePath)
Set fso = CreateObject("scripting.filesystemobject")
intCol = 1
intRow = 3
jsonData = ""
errData = ""
Do Until Sheets(sheetName).Cells(1, intCol).Value = ""
'Range("M" + intLen).Value = ""
'MsgBox Sheets(sheetName).Cells(1, intCol).Value
intCol = intCol + 1
Loop
'保存数据
folderPath = "e:\data\"
'MsgBox UBound(Split(filePath, "\"))
'MsgBox Split(filePath, "\")(UBound(Split(filePath, "\")) - 1)
tmppath = folderPath & Replace(filePath, "\" & Split(filePath, "\")(UBound(Split(filePath, "\"))), "\")
If Not fso.FolderExists(tmppath) Then
fso.CreateFolder tmppath
End If
Do Until Sheets(sheetName).Cells(intRow, 1).Value = ""
If Sheets(sheetName).Cells(intRow, 1) <> "" Then
If jsonData <> "" Then
jsonData = jsonData & "," & vbBr
End If
jsonData = jsonData & "{"
For r = 1 To intCol - 1
If r > 1 Then
jsonData = jsonData & "," & vbBr
End If
'MsgBox Sheets(sheetName).Cells(intRow, r).Value
If IsNumeric(Sheets(sheetName).Cells(intRow, r).Value) Then
t = Trim(CStr(Sheets(sheetName).Cells(intRow, r).Value))
b = Sheets(sheetName).Cells(intRow, r)
If t = "True" Or t = "False" Then
t = LCase(t)
End If
If b = "" And checkErr Then
errData = errData & vbBr & "[" & sheetName & "]" & Sheets(sheetName).Cells(intRow, 2).Value & "中属性" & Sheets(sheetName).Cells(1, r).Value & "值为空"
ElseIf Mid(t, 1, 1) = "." Then
t = "0" + t
End If
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & t
Else
If Mid(Sheets(sheetName).Cells(intRow, r).Value, 1, 1) = "[" Then
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & Sheets(sheetName).Cells(intRow, r).Value
Else
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:""" & Sheets(sheetName).Cells(intRow, r).Value & """"
End If
End If
Next r
jsonData = jsonData + "}"
End If
intRow = intRow + 1
Loop
jsonData = "[" & jsonData & "]"
SaveToFile jsonData, folderPath & filePath & ".json"
Set fso = Nothing
MsgBox "操作成功!" & errData
End Sub
Private Sub SaveJsonByFileName(sheetName, filePath)
Set fso = CreateObject("scripting.filesystemobject")
intCol = 1
intRow = 5
jsonData = ""
errData = ""
Do Until Sheets(sheetName).Cells(1, intCol).Value = ""
'Range("M" + intLen).Value = ""
'MsgBox Sheets(sheetName).Cells(1, intCol).Value
intCol = intCol + 1
Loop
'保存数据
folderPath = "e:\data\"
'MsgBox UBound(Split(filePath, "\"))
'MsgBox Split(filePath, "\")(UBound(Split(filePath, "\")) - 1)
tmppath = folderPath & Replace(filePath, "\" & Split(filePath, "\")(UBound(Split(filePath, "\"))), "\")
If Not fso.FolderExists(tmppath) Then
fso.CreateFolder tmppath
End If
lastFileName = ""
Do Until Sheets(sheetName).Cells(intRow, 1).Value = ""
If Sheets(sheetName).Cells(intRow, 1) <> "" Then
If jsonData <> "" Then
jsonData = jsonData & "," & vbBr
End If
jsonData = jsonData & "{"
For r = 2 To intCol - 1
If r > 1 Then
jsonData = jsonData & "," & vbBr
End If
'MsgBox Sheets(sheetName).Cells(intRow, r).Value
If IsNumeric(Sheets(sheetName).Cells(intRow, r).Value) Then
t = Trim(CStr(Sheets(sheetName).Cells(intRow, r).Value))
b = Sheets(sheetName).Cells(intRow, r)
If t = "True" Or t = "False" Then
t = LCase(t)
End If
If b = "" And checkErr Then
errData = errData & vbBr & "[" & sheetName & "]" & Sheets(sheetName).Cells(intRow, 2).Value & "中属性" & Sheets(sheetName).Cells(1, r).Value & "值为空"
ElseIf Mid(t, 1, 1) = "." Then
t = "0" + t
End If
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & t
Else
If Mid(Sheets(sheetName).Cells(intRow, r).Value, 1, 1) = "[" Then
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & Sheets(sheetName).Cells(intRow, r).Value
Else
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:""" & Sheets(sheetName).Cells(intRow, r).Value & """"
End If
End If
Next r
jsonData = jsonData + "}"
End If
If lastFileName = "" Then
lastFileName = Sheets(sheetName).Cells(intRow, 1).Value
End If
If lastFileName <> Sheets(sheetName).Cells(intRow, 1).Value Then
jsonData = "[" & jsonData & "]"
SaveToFile jsonData, folderPath & filePath & lastFileName & ".json"
lastFileName = Sheets(sheetName).Cells(intRow, 1).Value
jsonData = ""
End If
intRow = intRow + 1
Loop
SaveToFile jsonData, folderPath & filePath & lastFileName & ".json"
Set fso = Nothing
MsgBox "操作成功!" & errData
End Sub
'导出技能JSON数据
Sub SaveSkill()
SaveJson "技能", "skill\sk_"
End Sub
'导出建筑JSON数据
Sub SaveBuild()
SaveJson "建筑", "build\build_"
End Sub
'导出武将JSON数据
Sub SaveGen()
Attribute SaveGen.VB_ProcData.VB_Invoke_Func = " \n14"
Set fso = CreateObject("scripting.filesystemobject")
intCol = 1
intRow = 3
jsonData = ""
errData = ""
sheetName = "武将"
Do Until Sheets(sheetName).Cells(1, intCol).Value = ""
'Range("M" + intLen).Value = ""
'MsgBox Sheets(sheetName).Cells(1, intCol).Value
intCol = intCol + 1
Loop
Do Until Sheets(sheetName).Cells(intRow, 1).Value = ""
jsonData = ""
If Sheets(sheetName).Cells(intRow, 2) <> "" Then
For r = 1 To intCol - 1
If jsonData = "" Then
jsonData = "{"
Else
jsonData = jsonData & "," & vbBr
End If
'MsgBox Sheets(sheetName).Cells(intRow, r).Value
If IsNumeric(Sheets(sheetName).Cells(intRow, r).Value) Then
t = Trim(CStr(Sheets(sheetName).Cells(intRow, r).Value))
b = Sheets(sheetName).Cells(intRow, r)
If b = "" And checkErr Then
errData = errData & vbBr & "[sheetName]" & Sheets(sheetName).Cells(intRow, 1).Value & "中属性" & Sheets(sheetName).Cells(1, r).Value & "值为空"
ElseIf Mid(t, 1, 1) = "." Then
t = "0" + t
End If
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & t
Else
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:""" & Sheets(sheetName).Cells(intRow, r).Value & """"
End If
Next r
jsonData = jsonData + "}"
'保存数据
folderPath = "e:\data\general"
If Not fso.FolderExists(folderPath) Then
fso.CreateFolder folderPath
End If
filePath = folderPath & "\gen_" & Sheets(sheetName).Cells(intRow, 2).Value & ".json"
'Set jsonFile = fso.CreateTextFile(filePath, True)
'jsonFile.WriteLine (jsonData)
'jsonFile.Close
SaveToFile jsonData, filePath
End If
intRow = intRow + 1
Loop
Set fso = Nothing
MsgBox "操作成功!" & errData
End Sub
'导出城市JSON数据
Sub SaveCity()
SaveJson "城市", "city\ct_"
End Sub
'导出装备JSON数据
Sub SaveEqu()
SaveJson "装备", "equipment\eq_"
End Sub
'导出兵种JSON数据
Sub SaveSoldier()
Set fso = CreateObject("scripting.filesystemobject")
intCol = 1
intRow = 3
jsonData = ""
errData = ""
sheetName = "兵种"
Do Until Sheets(sheetName).Cells(1, intCol).Value = ""
'Range("M" + intLen).Value = ""
'MsgBox Sheets(sheetName).Cells(1, intCol).Value
intCol = intCol + 1
Loop
Do Until Sheets(sheetName).Cells(intRow, 1).Value = ""
jsonData = ""
If Sheets(sheetName).Cells(intRow, 2) <> "" Then
For r = 1 To intCol - 1
If jsonData = "" Then
jsonData = "{"
Else
jsonData = jsonData & "," & vbBr
End If
'MsgBox Sheets(sheetName).Cells(intRow, r).Value
If IsNumeric(Sheets(sheetName).Cells(intRow, r).Value) Then
t = Trim(CStr(Sheets(sheetName).Cells(intRow, r).Value))
If t = "" And checkErr Then
errData = errData & vbBr & "[sheetName]" & Sheets(sheetName).Cells(intRow, 1).Value & " 属性" & Sheets(sheetName).Cells(1, r).Value & "值为空"
ElseIf Mid(t, 1, 1) = "." Then
t = "0" + t
End If
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & t
Else
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:""" & Sheets(sheetName).Cells(intRow, r).Value & """"
End If
Next r
jsonData = jsonData + "}"
'保存数据
folderPath = "e:\data\soldier"
If Not fso.FolderExists(folderPath) Then
fso.CreateFolder folderPath
End If
filePath = folderPath & "\soldier_" & Sheets(sheetName).Cells(intRow, 2).Value & ".json"
'Set jsonFile = fso.CreateTextFile(filePath, True)
'jsonFile.WriteLine (jsonData)
'jsonFile.Close
SaveToFile jsonData, filePath
End If
intRow = intRow + 1
Loop
Set fso = Nothing
MsgBox "操作成功!" & errData
End Sub
'导出部队JSON数据
Sub SaveWarpathMap()
Set fso = CreateObject("scripting.filesystemobject")
intCol = 1
intRow = 3
jsonData = ""
listData = ""
errData = ""
headerData = ""
sheetName = "部队"
Do Until Sheets(sheetName).Cells(1, intCol).Value = ""
'Range("M" + intLen).Value = ""
'MsgBox Sheets(sheetName).Cells(1, intCol).Value
intCol = intCol + 1
Loop
For r = 1 To intCol - 1
If headerData = "" Then
headerData = "{"
Else
headerData = headerData & "," & vbBr
End If
If IsNumeric(Sheets(sheetName).Cells(intRow, r).Value) Or Sheets(sheetName).Cells(intRow, r).Value = "null" Or Mid(Sheets(sheetName).Cells(intRow, r).Value, 1, 1) = "[" Then
t = Trim(CStr(Sheets(sheetName).Cells(intRow, r).Value))
If t = "" And checkErr Then
errData = errData & vbBr & "[sheetName]" & Sheets(sheetName).Cells(intRow, 2).Value & " 属性" & Sheets(sheetName).Cells(1, r).Value & "值为空"
ElseIf Mid(t, 1, 1) = "." Then
t = "0" + t
End If
headerData = headerData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & t
Else
headerData = headerData & """" + Sheets(sheetName).Cells(1, r).Value & """:""" & Sheets(sheetName).Cells(intRow, r).Value & """"
End If
Next r
intRow = 9
intCol = 1
Do Until Sheets(sheetName).Cells(5, intCol).Value = "fid"
'Range("M" + intLen).Value = ""
'MsgBox Sheets(sheetName).Cells(1, intCol).Value
intCol = intCol + 1
Loop
Do Until Sheets(sheetName).Cells(intRow, 1).Value = ""
jsonData = ""
For r = 1 To intCol - 1
If jsonData = "" Then
jsonData = "{"
Else
jsonData = jsonData & "," & vbBr
End If
'MsgBox Sheets(sheetName).Cells(intRow, r).Value
If IsNumeric(Sheets(sheetName).Cells(intRow, r).Value) Then
t = Trim(CStr(Sheets(sheetName).Cells(intRow, r).Value))
If t = "" And checkErr Then
errData = errData & vbBr & "[sheetName]" & Sheets(sheetName).Cells(intRow, 2).Value & " 属性" & Sheets(sheetName).Cells(5, r).Value & "值为空"
ElseIf Mid(t, 1, 1) = "." Then
t = "0" + t
End If
jsonData = jsonData & """" + Sheets(sheetName).Cells(5, r).Value & """:" & t
Else
jsonData = jsonData & """" + Sheets(sheetName).Cells(5, r).Value & """:""" & Sheets(sheetName).Cells(intRow, r).Value & """"
End If
Next r
jsonData = jsonData & ",""trd"":[" & vbBr
childRow = intCol
childList = ""
childData = ""
childFid = ""
'处理小队
Do Until Sheets(sheetName).Cells(5, childRow) = ""
If Sheets(sheetName).Cells(5, childRow).Value = "fid" Then
childFid = Sheets(sheetName).Cells(intRow, childRow)
If childFid = "" Then
childRow = childRow + 14
End If
If childData <> "" Then
If childList <> "" Then
childList = childList & "," & vbBr
End If
childList = childList & childData & "}" & vbBr
End If
childData = ""
End If
If childFid <> "" Then
If childData = "" Then
childData = "{" & vbBr
Else
childData = childData & "," & vbBr
End If
'MsgBox Sheets(sheetName).Cells(intRow, r).Value
If IsNumeric(Sheets(sheetName).Cells(intRow, childRow).Value) Then
t = Trim(CStr(Sheets(sheetName).Cells(intRow, childRow).Value))
If t = "" Then
errData = errData & vbBr & "[sheetName]" & Sheets(sheetName).Cells(intRow, 2).Value & " 属性" & Sheets(sheetName).Cells(5, childRow).Value & "值为空"
ElseIf Mid(t, 1, 1) = "." Then
t = "0" + t
End If
childData = childData & """" + Sheets(sheetName).Cells(5, childRow).Value & """:" & t
Else
childData = childData & """" + Sheets(sheetName).Cells(5, childRow).Value & """:""" & Sheets(sheetName).Cells(intRow, childRow).Value & """"
End If
End If
childRow = childRow + 1
Loop
If childData <> "" Then
If childList <> "" Then
childList = childList & ","
End If
childList = childList & childData & "}" & vbBr
End If
jsonData = jsonData & childList & "]}" & vbBr
If listData <> "" Then
listData = listData & "," & vbBr
End If
listData = listData & jsonData
intRow = intRow + 1
Loop
jsonData = headerData & ",""armyDatas"": [" & listData & "]}"
'保存数据
folderPath = "e:\data\warpathMap"
If Not fso.FolderExists(folderPath) Then
fso.CreateFolder folderPath
End If
filePath = folderPath & "\wm_" & Sheets(sheetName).Cells(3, 1).Value & ".json"
'Set jsonFile = fso.CreateTextFile(filePath, True)
'jsonFile.WriteLine (jsonData)
'jsonFile.Close
Set fso = Nothing
SaveToFile jsonData, filePath
MsgBox "操作成功!" & errData
End Sub
Sub SaveNpcFieldMap()
Set fso = CreateObject("scripting.filesystemobject")
intCol = 1
intRow = 5
jsonData = ""
listData = ""
errData = ""
sheetName = "田矿NPC部队"
'保存数据
folderPath = "e:\data\"
filePath = "res\resNpc_"
tmppath = folderPath & Replace(filePath, "\" & Split(filePath, "\")(UBound(Split(filePath, "\"))), "\")
If Not fso.FolderExists(tmppath) Then
fso.CreateFolder tmppath
End If
Do Until Sheets(sheetName).Cells(1, intCol).Value = "fid"
'Range("M" + intLen).Value = ""
'MsgBox Sheets(sheetName).Cells(1, intCol).Value
intCol = intCol + 1
Loop
lastFileName = ""
Do Until Sheets(sheetName).Cells(intRow, 1).Value = ""
jsonData = ""
For r = 1 To intCol - 1
If jsonData = "" Then
jsonData = "{"
Else
jsonData = jsonData & "," & vbBr
End If
'MsgBox Sheets(sheetName).Cells(intRow, r).Value
If IsNumeric(Sheets(sheetName).Cells(intRow, r).Value) Then
t = Trim(CStr(Sheets(sheetName).Cells(intRow, r).Value))
If t = "" And checkErr Then
errData = errData & vbBr & "[sheetName]" & Sheets(sheetName).Cells(intRow, 2).Value & " 属性" & Sheets(sheetName).Cells(1, r).Value & "值为空"
ElseIf Mid(t, 1, 1) = "." Then
t = "0" + t
End If
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & t
Else
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:""" & Sheets(sheetName).Cells(intRow, r).Value & """"
End If
Next r
jsonData = jsonData & ",""trd"":[" & vbBr
childRow = intCol
childList = ""
childData = ""
childFid = ""
'处理小队
Do Until Sheets(sheetName).Cells(1, childRow) = ""
If Sheets(sheetName).Cells(1, childRow).Value = "fid" Then
childFid = Sheets(sheetName).Cells(intRow, childRow)
If childFid = "" Then
childRow = childRow + 14
End If
If childData <> "" Then
If childList <> "" Then
childList = childList & "," & vbBr
End If
childList = childList & childData & "}" & vbBr
End If
childData = ""
End If
If childFid <> "" Then
If childData = "" Then
childData = "{" & vbBr
Else
childData = childData & "," & vbBr
End If
'MsgBox Sheets(sheetName).Cells(intRow, r).Value
If IsNumeric(Sheets(sheetName).Cells(intRow, childRow).Value) Then
t = Trim(CStr(Sheets(sheetName).Cells(intRow, childRow).Value))
If t = "" Then
errData = errData & vbBr & "[sheetName]" & Sheets(sheetName).Cells(intRow, 2).Value & " 属性" & Sheets(sheetName).Cells(1, childRow).Value & "值为空"
ElseIf Mid(t, 1, 1) = "." Then
t = "0" + t
End If
childData = childData & """" + Sheets(sheetName).Cells(1, childRow).Value & """:" & t
Else
childData = childData & """" + Sheets(sheetName).Cells(1, childRow).Value & """:""" & Sheets(sheetName).Cells(intRow, childRow).Value & """"
End If
End If
childRow = childRow + 1
Loop
If childData <> "" Then
If childList <> "" Then
childList = childList & ","
End If
childList = childList & childData & "}" & vbBr
End If
jsonData = jsonData & childList & "]}" & vbBr
If lastFileName = "" Then
lastFileName = Sheets(sheetName).Cells(intRow, 1).Value
End If
If lastFileName <> Sheets(sheetName).Cells(intRow, 1).Value Then
'MsgBox folderPath & filePath & Sheets(sheetName).Cells(intRow, 1).Value
listData = "[" & listData & "]"
SaveToFile listData, folderPath & filePath & lastFileName & ".json"
lastFileName = Sheets(sheetName).Cells(intRow, 1).Value
listData = jsonData
Else
If listData <> "" Then
listData = listData & "," & vbBr
End If
listData = listData & jsonData
End If
intRow = intRow + 1
Loop
SaveToFile listData, folderPath & filePath & lastFileName & ".json"
Set fso = Nothing
MsgBox "操作成功!" & errData
End Sub
Sub SaveNpcWarpathMap()
Set fso = CreateObject("scripting.filesystemobject")
intCol = 1
intRow = 5
jsonData = ""
listData = ""
errData = ""
sheetName = "NPC军团部队"
'保存数据
folderPath = "e:\data\"
filePath = "corps\troop\tp_"
tmppath = folderPath & Replace(filePath, "\" & Split(filePath, "\")(UBound(Split(filePath, "\"))), "\")
If Not fso.FolderExists(tmppath) Then
fso.CreateFolder tmppath
End If
Do Until Sheets(sheetName).Cells(1, intCol).Value = "fid"
'Range("M" + intLen).Value = ""
'MsgBox Sheets(sheetName).Cells(1, intCol).Value
intCol = intCol + 1
Loop
lastFileName = ""
Do While Sheets(sheetName).Cells(intRow, 1).Value <> ""
jsonData = ""
For r = 2 To intCol - 1
If jsonData = "" Then
jsonData = "{"
Else
jsonData = jsonData & "," & vbBr
End If
'MsgBox Sheets(sheetName).Cells(intRow, r).Value
If IsNumeric(Sheets(sheetName).Cells(intRow, r).Value) Then
t = Trim(CStr(Sheets(sheetName).Cells(intRow, r).Value))
If t = "" And checkErr Then
errData = errData & vbBr & "[sheetName]" & Sheets(sheetName).Cells(intRow, 2).Value & " 属性" & Sheets(sheetName).Cells(1, r).Value & "值为空"
ElseIf Mid(t, 1, 1) = "." Then
t = "0" + t
End If
jsonData = jsonData & """" + Sheets(sheetName).Cells(1, r).Value & """:" & t
Else