/Data/generator/export.vbs

http://awoe.googlecode.com/ · Visual Basic · 73 lines · 40 code · 19 blank · 14 comment · 2 complexity · 26c38a68c9f30934967fa7fce2b012f1 MD5 · raw file

  1. ' the Excel Application
  2. Dim objExcel
  3. ' the path to the excel file
  4. Dim excelPath
  5. Dim ouputPath
  6. ' how many worksheets are in the current excel file
  7. Dim worksheetCount
  8. Dim counter
  9. ' the worksheet we are currently getting data from
  10. Dim currentWorkSheet
  11. ' the value of the current row and column of the current worksheet we are reading
  12. Dim word
  13. If wscript.arguments.Count <2 Then
  14. wscript.echo "Not Enought Parameters"
  15. wscript.exit(1)
  16. Else
  17. excelPath = wscript.arguments(0)
  18. outputPath = wscript.arguments(1)
  19. if wscript.arguments.count>2 then
  20. worksheetCount = wscript.arguments(2)
  21. else
  22. worksheetCount = 0
  23. end if
  24. End If
  25. Wscript.Echo "Reading Data from " & excelPath
  26. ' Create an invisible version of Excel
  27. Set objExcel = CreateObject("Excel.Application")
  28. ' don't display any messages about documents needing to be converted
  29. ' from old Excel file formats
  30. objExcel.DisplayAlerts = 0
  31. ' open the excel document as read-only
  32. ' open (path, confirmconversions, readonly)
  33. objExcel.Workbooks.open excelPath, false, true
  34. ' How many worksheets are in this Excel documents
  35. if workSheetCount=0 then
  36. worksheetCount = objExcel.Worksheets.Count
  37. end if
  38. Wscript.Echo "We have " & workSheetCount & " worksheets"
  39. const xlCurrentPlatformText = 6
  40. ' Loop through each worksheet
  41. For counter = 1 to workSheetCount
  42. Wscript.Echo "-----------------------------------------------"
  43. Set currentWorkSheet = objExcel.ActiveWorkbook.Worksheets(counter)
  44. Wscript.Echo "Reading data from worksheet " & currentWorkSheet.Name '& vbCRLF
  45. wscript.echo "Save As:" & outputPath & currentWorkSheet.Name & ".csv" '& vbCRLF
  46. currentWorkSheet.saveas outputPath & currentWorkSheet.Name & ".csv", xlCurrentPlatformText
  47. ' We are done with the current worksheet, release the memory
  48. Set currentWorkSheet = Nothing
  49. Next
  50. objExcel.Workbooks(1).Close
  51. objExcel.Quit
  52. Set currentWorkSheet = Nothing
  53. ' We are done with the Excel object, release it from memory
  54. Set objExcel = Nothing