Code39BarcodeToExcel.vbs
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 | if WScript.Arguments.Count < 1 Then MsgBox "Run with the folder path as the argument" & vbCRLF & vbCRLF & "Code39BarcodeToExcel.vbs <InputFolder>" WScript.Quit 0 End If Set objFSO = CreateObject( "Scripting.FileSystemObject" ) ' define allowed input images extensions inputImagesExtensions = "JPG,JPEG,PNG,BMP,PDF,TIF" Set reader = CreateObject( "Bytescout.BarCodeReader.Reader" ) ' Set Code39 barcode types for searching reader.BarcodeTypesToFind.Code39 = True ' Set excel document Set document = CreateObject( "Bytescout.Spreadsheet.Spreadsheet" ) ' Set document keys document.RegistrationName = "demo" document.RegistrationKey = "demo" ' Add new worksheet Set worksheet = document.Workbook.Worksheets.Add( "Code39" ) ' Set cell index value Dim CellIndex CellIndex = 0 ' Set Initial Value CellIndex = (CellIndex + 1) Set cell_value = worksheet.Cell_2( "A" + Cstr(CellIndex)) Set cell_filename = worksheet.Cell_2( "B" + Cstr(CellIndex)) cell_value.Value = "Barcode Value" cell_filename.Value = "File Name" Set objInputFolder = objFSO.GetFolder(WScript.Arguments(0)) Call ProcessFolder(objInputFolder) ' delete output file if exists already Set fso = CreateObject( "Scripting.FileSystemObject" ) If (fso.FileExists( "output.xls" )) Then fso.DeleteFile( "output.xls" ) Set fso = nothing ' save document document.SaveAs "output.xls" WScript.Echo "successfully created 'output.xls' file!" ' close Spreadsheet Set document = Nothing WScript.Quit 0 Sub ProcessFolder(folder) Set objFolder = objFSO.GetFolder(folder.Path) Set colFiles = objFolder.Files For Each objFile in colFiles ' Check the file type If inStr(inputImagesExtensions, UCase(objFSO.GetExtensionName(objFile.Name))) > 0 Then reader.ReadFromFile objFile.Path For i = 0 To reader.FoundCount - 1 ' Get cell value CellIndex = (CellIndex + 1) Set cell_value = worksheet.Cell_2( "A" + Cstr(CellIndex)) Set cell_filename = worksheet.Cell_2( "B" + Cstr(CellIndex)) ' set cell value cell_value.Value = reader.GetFoundBarcodeValue(i) cell_filename.Value = objFile.Name ' Write to console WScript.Echo "Extracted barcode '" & reader.GetFoundBarcodeValue(i) & "' from '" & objFile.Name & "' file" Next End If Next For Each subFolder in folder.SubFolders ProcessFolder subFolder Next End Sub |
run.bat
1 2 3 | REM running from the command line cscript.exe Code39BarcodeToExcel.vbs "InputFiles" pause |
Click here to get your Free Trial version of the SDK
also available as: