Ask a Question

Exporting data to an Excel or other file

kmp2x
New Contributor

Exporting data to an Excel or other file

I've been looking around and cannot find how to do this.  My test generates some data at a certain point that I need to store, preferably in a file and not as a variable, so as to access it later with a different script.  However I can't find how to do this - the DDT help files talk a lot about retrieving input data, but not writing output data.  I was hoping to find some examples of this before I started mucking about on my own, are there any?  I was thinking it might be as simple as inverting the assignments - for example, instead of



[jscript]

var drv2 = DDT.ExcelDriver(Files.FileNameByName(DriverFile), 'TestDriver', false);

TestData = drv2.Value("TestDataCol");



to read in, I would just do



drv2.Value("TestDataCol") = TestData;



to write out.  Will that work?  What about creating columns in the spreadsheet as I go?  It doesn't have to be a XLS, a simple CSV will work fine too, but I can't find anything in the help on this.



Any help would be appreciated.
2 REPLIES 2
syedsafvan
Contributor

RE: Exporting data to an Excel or other file

Hello Kent,



I too think that we don't have enough with DDT to write out stuff into spreadsheets. So for this purpose I used COM. Write your own custom COM functions that will help you get your job done. In my case I wanted to write stuff into the spread sheet and browse the spread sheet a lot so did not want to use the "next" method of DDT that accessed cells sequentially. So the COM functions appeared to be the best solution for me.




Script below in VB





Dim objExcel

Dim objWorkbook

Function DataSheet_GetAccess(WorkBookName)   

  Dim FilePath

  FilePath = ProjectSuite.Path & "TestData\" & WorkBookName

  Set objFSO = CreateObject("Scripting.FileSystemObject")

  If objFSO.FileExists (FilePath) then 

    Set objExcel = CreateObject("Excel.Application")  

    Set objWorkbook = objExcel.Workbooks.Open(FilePath)

    DataSheet_GetAccess =  1

  Else

    DataSheet_GetAccess = 0

  End if

End Function





Sub DataSheet_SetData(WorkSheetName, IterationNumber, FieldName, Value)

    Set objWorksheet = objWorkbook.Worksheets(WorkSheetName)

      i = 1

      Do While objWorksheet.Cells(1, i).Value <> ""

        If objWorksheet.Cells(1, i).Value = FieldName Then

             objWorksheet.Cells(IterationNumber, i).Value = Value

             Exit Do

        End If

        i = i + 1

      Loop

    Set objWorksheet = Nothing

End Sub




You might write your own stuff.




As far as writing into csv file that is very simple you could just use the built in aqFile. Look into help for aqFile.WriteToTextFile()




Thank you

Syed



Syed Ahmed Safvan

kmp2x
New Contributor

RE: Exporting data to an Excel or other file

Thanks, that's what I needed to know.
cancel
Showing results for 
Search instead for 
Did you mean: