Solved

Export Notes data to Excel - template location

Posted on 2003-11-03
14
901 Views
Last Modified: 2013-12-18
Hi experts,
I'm using some script to export data to Excel that starts like this:
  ' Prepare MS Excel for work
      Set xlApp = CreateObject("Excel.Application")
      Set xlWB = xlApp.Workbooks.Add("C:\Program Files\Microsoft Office\Templates\template1.xlt")
Now that works fine providing the template is in the specified location, but I'm finding problems in that some people don't keep their templates in this directory and I'm thinking it might be better to put the template in the same directory as their Notes files. Normally this will be C:\Notes\Data\ probably, but again people can choose something else. So I'm wondering, if I place the template in whatever directory the user is using for storing his database, then can we alter the code above to look in the same directory as the database is located whatever it is, without actually specifying the path as done above?
Cheers,
Stuart
0
Comment
Question by:StuartOrd
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 9673343
Why don't you store the company templates in a Notes-database, or in the same database? And then save it in a know directory. You can also ask Excel for the default template directory.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9673771
Instead of distributing templates across local workstations, I would suggest you to keep it on a file server and access it from that share. In this way it is easy to distribute any changes to the template and maintain it centrally from one location.

eg:
     Set xlApp = CreateObject("Excel.Application")
     Set xlWB = xlApp.Workbooks.Add("\\Server\ShareName\Microsoft Office\Templates\template1.xlt")

PS: Create a read only share so that nobody writes info in this area.

~Hemanth
 
0
 

Author Comment

by:StuartOrd
ID: 9674029
Thanks for the comments.
sjef_bosman:How do I store the template "in the same database"? If it's linked to the database in some way, that would be fine. How do I then point the agent at this location?
Hemanth (hi again!): I'm working in a much smaller world than yours and the databases are usually running on a local PC with no Notes server. Few people use it as it's specialised. So I really need it on the local PC
Regards,
Stuart
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9674055
Well then I would go with sjef suggestion
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9674893
For sjef's suggestion, here are some details:

You could store teh template in a profile document.  Create a form, put a rich text field on it, name it something like EXCEL TEMPLATE and mark it to not be available for compose or search.

Create an action button or agent with the formula:

@Command([EditProfile]; "EXCEL TEMPLATE")

Run that code, the form pops up, attach the template file, save and close.

Now, the following code can access this file:

CONST FILE_NAME = "template1.xlt"
Dim s as new notesSession
Dim db as notesDatabase
Set db = s.currentDatabase
Dim profile as notesDocument
Set profile = db.getProfileDocument("EXCEL TEMPLATE")
Dim excelFile as notesEmbeddedObject
Set excelFile = doc.getAttachment(FILE_NAME)
excelFile.extractFile("C:\" & FILE_NAME)
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 9677007
If I understand you correctly that your users don't replicate with a server, you'd run in trouble refreshing your Excel-template if (when) that becomes necessary. I therefore assume that replication is done every now and then, but not too often. The most flexible idea is to put the template inside a document, but not necessarily in a Profile document. On a good day you need more templates for other purposes, so you add a template to your template database. It's probably best to create a new form in your database and a view to find documents created with that form. You could protect your templates from being modified with the usual Reader- and Author-fields.

You could also look into the Document Library template in standard Notes installations, and then use stuff you find in there.

How to find your excel-template:

Set db= s.CurrentDatabase
Set view= db.GetView("Templates")
Set doc= view.GetDocumentByKey("Excel-template", True)

followed by portions of qwaletee's code to extract the template.

Sjef
0
 

Author Comment

by:StuartOrd
ID: 9762927
OK, I'm trying this. Part of my code is now:

Dim excelFile As notesEmbeddedObject
      Set view=db.GetView("Excel template")
      Set doc=view.GetFirstDocument
      Set excelFile = doc.getAttachment("LEAC.xlt")
      Call doc.ExtractFile( "c:\" & "LEAC.xlt" )

I have a view called "Excel templates" as you can see, and it contains one document made with a form called "ExcelTemplateForm" that has a rich text field called "Exceltemplate1". Into this document I attached my template "LEAC.xlt".

When I run this agent, it fails at the last line shown, with the error "Illegal use of property". I copied the style of the line from Designer help - but that's not the first time I've done thta and it failed! Isn't the method ExtractFile embedded into Notes somehow?
Stuart
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 100 total points
ID: 9763312
Extractfile should be called differently. Here part of some sourcecode for a Word-attachment:

            Set item= doc.getfirstitem(fname)
            Set eo= item.EmbeddedObjects(0)
            filepath= filepath + "\" + eo.source
            Call eo.extractfile(filepat)

It's probably not an Attachment, it's embedded into a rich-text field.
0
 

Author Comment

by:StuartOrd
ID: 9766678
Thanks sjef-bosman
The code I got to work is as follows:
                Dim xlApp As Variant
      Dim xlsheet As Variant
      Dim xlWB As Variant
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim count As Integer
      Dim session As New NotesSession
      Set db = session.CurrentDatabase
               
                'New bit for embedded template
      Dim excelFile As notesEmbeddedObject
      Set view=db.GetView("Excel template")
      Set doc=view.GetFirstDocument
      Set excelFile = doc.getAttachment("LEAC.xlt")      
                Call excelFile.ExtractFile( "c:\LEAC.xlt")

      ' Prepare MS Excel for work
      Set xlApp = CreateObject("Excel.Application")
      Set xlWB = xlApp.Workbooks.Add("C:\LEAC.xlt")
              etc

Now I need to alter it to hold several templates in the database.... but I'll let you know if I get stuck!

Regards,
Stuart
0
 

Author Comment

by:StuartOrd
ID: 9766944
Hey, it's a doddle, just several rich text fields in the same form into which I attached the other templates, and the other scripts are more or less the same with the new teplate name in the code. I wish it were all so easy.
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9767436
Doddle?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 9769675
Some "free" advice (and thanks for the points!):

Maybe you'd better create a document per template, all with a template form:
- you won't be depending on the names of the fields
- you don't have to change the design if you have to add a template
- you can pick the template out of a view
- the code will be the same for all templates (same fieldname)
- it's a lot neater to do it this way
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9773409
Sjef,

He's probably OK this way.  He's grabbing it straight by filename, so he is not dependant on field name anyway.
0
 

Author Comment

by:StuartOrd
ID: 9774511
Doddle = slang for very easy.
I wondered about making several template forms, but I wasn't sure how to grab the second and third documents as appropriate for the template being sought by each agent, and since this way worked first time, I applied "if it ain't bust, don't fix it"  ;-)
Just in case - bust = broken ;-o


0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question