Agent to export a view to CSV

Can someone please help me with this request. I am trying to export a view to a CSV file. I have searched the forum but cannot find anything. I can do it manually using the export function in the file menu but I need to be able to do it on a weekly basis. Is there a way this can be done using a scheduled agent? If so, can someone please explain to me how. Any help would be most appreciated.

Thanks

Craig

Subject: Agent to export a view to CSV

Craig,

you should have search the sandbox - in there are there are example of exporting not only to excel but to a csv file as well.

in any case, using lotus script is your best bet. if you good with script, it should not take you much longer than 30 minutes to do what you want.

John

Subject: RE: Agent to export a view to CSV

John,

Thank you for your quick response. I should have checked the sandbox! I will do it now, however, I am not very good at lotus script.

Craig

Subject: RE: Agent to export a view to CSV

I have now had a look in the sandbox but I cannot find anything that fits. They are mostly to excel and I just want CSV. They also appear to be run manually and require a manual selection of documents.

Subject: RE: Agent to export a view to CSV

Craig,

the code that i have in the sandbox allows for export to excel or ascii. yes it is manual, but it is a starting point for you to look.

for example, the script that was just given to you, only handles single item values - what if you have a multi value? What is you wanted to export rich text? what if the values you are exporting contain a tab character or a newline or carriage return. what if the value contains a comma - that will mess up your import.

since you are not that good with script - it may take a few hours to play around with what your were just given - but you are going to need a few more answers before continuing.

John

Subject: RE: Agent to export a view to CSV

Hi, this works for me.

Sub Initialize

Dim s As New NotesSession 

Dim doc As NotesDocument 

Dim maildoc As NotesDocument 

Dim db As NotesDatabase 

Dim rtitem As Variant 

Dim z As Integer

Dim view As NotesView 

Dim getfields As String

Dim searchstring As String



Set db = s.CurrentDatabase 



Set view = db.GetView("(report)") 

Set doc = view.GetFirstDocument 



If doc Is Nothing Then 

	Exit Sub 

End If 

	

Dim nVar As Variant, eVar As Variant 

nVar = Null 

Dim fileNum As Integer 

fileNum% = Freefile() 



fileName = "filename.csv" 



'--change here for another temp lib 

tempDirectory = s.GetEnvironmentString ( "Directory", True ) 

filePath = tempDirectory + "/dir/" + fileName 



searchstring$ = getfields



Open filePath For Output As fileNum% 	



While Not (doc Is Nothing) 

	Print #fileNum%, doc.field1(0)+ ";" + doc.field2(0) + ";" + doc.field3(0) + ";" + doc.field4(0)

	Set doc = view.GetNextDocument(doc) 

Wend

Close fileNum% 

End Sub

Subject: RE: Agent to export a view to CSV

You can also try this agent as well. It’s about the same, but you won’t have to update the column names if you update the view.

Sub Initialize

Dim s As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim nbcol As Integer

Dim k As Integer

Dim newline As String

Dim fileName As String

Dim fileNum As Integer



Set db = s.CurrentDatabase

Set view = db.GetView( "TheViewName" )

nbcol = Ubound(view.Columns)

Set doc = view.getfirstdocument



fileName = "c:\Temp\export.csv"

fileNum = Freefile()

Open fileName For Output As fileNum	



k = 0

While Not (doc Is Nothing)

	newline = ""

	For k = 0 To nbcol 

		newline = newline + doc.ColumnValues(k)

		If k <> nbcol Then newline = newline + ","

	Next

	

	Print #fileNum, newline

	Set doc = view.GetNextDocument(doc)

Wend



Close fileNum	

End Sub

Florian Lungu

Subject: RE: Agent to export a view to CSV

Thank you to everyone for your help. I now have an agent which will do my exports.

Thanks Again

Craig