Discussion Board for collaboration related to QlikView App Development.
I ma trying to use a macro in my application that will exports the variables from a second application to CSV format..
I am using below code and it is not working....any help would be greatly appritiated..!!!
Sub MainProcess
set App=ActiveDocument.GetApplication
docpath = ActiveDocument.GetVariable("QVW").GetContent.String
Set docObj = App.OpenDoc (docpath,"","")
Call extractVars(docObj)
End Sub
sub extractVars(docObj)
'vExportTo = doc.Variables("vExportTo").GetContent.String
outputDir = "C:\Documents and Settings\XXX\Desktop\Field Usage\Delete\"
Set objTextFile = openOutputFile(outputDir & "variables.csv")
objTextFile.WriteLine("VariableName,VariableValue,RawVariableValue")
Set vars = docObj.GetVariableDescriptions
for i = 0 to vars.Count - 1
set v = vars.Item(i)
If Not (v.IsReserved Or v.IsConfig) Then
shownValue = v.ShownValue.String
' On Error Resume Next
objTextFile.WriteLine( _
csvQuote(v.Name) _
& "," & csvQuote(docObj.GetVariable(v.Name).GetContent.String) _
& "," & csvQuote(v.RawValue) _
)
End If
next
objTextFile.Close()
UserFile.CloseDoc
end sub
Function openOutputFile(filename)
Rem *** Create and open an output file
CONST ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set openOutputFile = objFSO.OpenTextFile (filename, ForWriting, True)
End Function
It is working now....
I have missed some parameters...
CONST QUOTE = """"
Sub MainProcess
set App=ActiveDocument.GetApplication
docpath = ActiveDocument.GetVariable("QVW").GetContent.String
Set docObj = App.OpenDoc (docpath,"","") ' Open the document
Call extractVars(docObj)
docObj.CloseDoc
ActiveDocument.Reload()
End Sub
Sub extractVars (docObj)
outputDir = ActiveDocument.Variables("vPrjLoc").GetContent.String
Set objTextFile = openOutputFile(outputDir & "\variables.csv")
objTextFile.WriteLine("VariableName,VariableValue,RawVariableValue")
Set vars = docObj.GetVariableDescriptions
for i = 0 to vars.Count - 1
set v = vars.Item(i)
rem exclude IsConfig & IsReserved vars
If Not (v.IsReserved Or v.IsConfig) Then
shownValue = v.ShownValue.String
objTextFile.WriteLine( _
csvQuote(v.Name) _
& "," & csvQuote(docObj.GetVariable(v.Name).GetContent.String) _
& "," & csvQuote(v.RawValue) _
)
End If
next
objTextFile.Close()
End Sub
Function openOutputFile(filename)
Rem *** Create and open an output file
CONST ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set openOutputFile = objFSO.OpenTextFile (filename, ForWriting, True)
End Function
Function csvQuote(str)
csvQuote = QUOTE & replace(str, """", """""") & QUOTE
End Function
It is working now....
I have missed some parameters...
CONST QUOTE = """"
Sub MainProcess
set App=ActiveDocument.GetApplication
docpath = ActiveDocument.GetVariable("QVW").GetContent.String
Set docObj = App.OpenDoc (docpath,"","") ' Open the document
Call extractVars(docObj)
docObj.CloseDoc
ActiveDocument.Reload()
End Sub
Sub extractVars (docObj)
outputDir = ActiveDocument.Variables("vPrjLoc").GetContent.String
Set objTextFile = openOutputFile(outputDir & "\variables.csv")
objTextFile.WriteLine("VariableName,VariableValue,RawVariableValue")
Set vars = docObj.GetVariableDescriptions
for i = 0 to vars.Count - 1
set v = vars.Item(i)
rem exclude IsConfig & IsReserved vars
If Not (v.IsReserved Or v.IsConfig) Then
shownValue = v.ShownValue.String
objTextFile.WriteLine( _
csvQuote(v.Name) _
& "," & csvQuote(docObj.GetVariable(v.Name).GetContent.String) _
& "," & csvQuote(v.RawValue) _
)
End If
next
objTextFile.Close()
End Sub
Function openOutputFile(filename)
Rem *** Create and open an output file
CONST ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set openOutputFile = objFSO.OpenTextFile (filename, ForWriting, True)
End Function
Function csvQuote(str)
csvQuote = QUOTE & replace(str, """", """""") & QUOTE
End Function
Hi,
Can you help me to differentiate what is ShownValue and Raw value in the above code with an example?
Thanks,
Rakul.