PageRenderTime 19ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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