How to import an excel sheet

I want to import an excel sheet on a view, how can I do?

Subject: Integra for Notes

I know, not every developer is keen on a 3rd party tool, but Integra for Notes allows you to concentrate on the more challenging requirements :wink:

Importing an excel sheet is a simple task with Integra for Notes. In our example database a great example has been incorporated, which you can closely examine, if you want.

A fully functional eval is available at http://www.integra4notes.com

Subject: how to import an excel sheet

This code is not the exact work-around bu can help you, i think. The first row of the sheet contains the name of field “END-IMPORT” is limit for import by line. For each line make one document.

Bye Ugo

Sub importExcel

Dim ses As New notessession

Dim wrk As New notesUIWorkspace



Dim db As notesdatabase

Dim docImp As notesdocument



Dim xlSheet1 As Variant

Dim xlApp As Variant

Dim wrkBook As Variant

Dim tplExcel As Variant

Dim nameExcel As String

Dim nameSheet As String



Dim iEmptyRow As Integer

Dim row As Long

Dim col As Long

Dim index As Long

Dim sForm As String

Dim vNmFld() As String

Dim vCol As Variant	

’ ------------------------------------------

Set db=ses.currentdatabase



nameExcel = Inputbox( "Insert path of file excel")

nameSheet = Inputbox( "Insert sheet name")

sForm = Inputbox( "Insert destination form name")



Set xlApp = CreateObject("Excel.Application") 

If Not xlApp Is Nothing Then

	Set wrkbook = xlApp.Workbooks 'wrkbook to Workbook 

	wrkbook.open nameExcel

	Set xlSheet1 = xlApp.Worksheets(nameSheet)

	xlSheet1.activate

	'	xlApp.Visible = True 'set to visible 

’ read field name

	row = 1

	index = 0

	vCol = getListCol(250)

	While (Not xlSheet1.Range(vcol(index) + Cstr(row)).value = "") And index < 400

		Redim Preserve vNmFld(index)

		vNmFld(index) = xlSheet1.Range(vCol(index) + Cstr(row)).value

		index = index + 1

	Wend

	col = index - 1

	While ( Not Lcase(xlSheet1.Range("A" + Cstr(row)).value) = "END-IMPORT" ) And index < 200000

		Set docImp = db.createDocument 

		docImp.form = sForm

		For index = 0 To col

			Call docImp.replaceItemValue(vNmFld(index),_ 

			xlSheet1.Range(vCol(index) + Cstr(row) ).value )

		Next

		Call docImp.save(1,1,1)

		row = row +1

	Wend

	Call wrkbook.close

	xlApp.quit

	

	

End If

End Sub

Function getListCol( iTop As Integer) As Variant

Dim iPos As Integer

Dim index As Integer

Dim iFirst As Integer

Dim iSecond As Integer



Redim vCol(iTop) As String



iPos = 0

index = 0

While (iPos <= iTop ) And (index < 26)

	vCol(iPos) = Chr(65 + index)

	iPos = iPos +1

	index = index + 1

Wend

While (iPos <= iTop ) And (index < 256)

	iFirst = index \ 26

	iSecond = index Mod 26

	vCol(iPos) = Chr(64 + iFirst) + Chr(65 + iSecond)

	iPos = iPos +1

	index = index + 1

Wend

getListCol = vCol

End Function

Subject: RE: how to import an excel sheet

Can I put the route of my path instead of The “inputbox”? beacuse is only one filehow can I do it? like this?

nameExcel = c:\Bu\Ps\ServicioPsicologico\motivos

nameSheet = Motivos.xls

sForm = FPrueba

Subject: RE: how to import an excel sheet

sure!but

nameExcel = “c:\Bu\Ps\ServicioPsicologico\motivos\Motivos.xls”

’ is long path file name

nameSheet = “Sheet1” 'is excel sheet name

sForm = “FPrueba” 'is notes form name

bye

Subject: RE: how to import an excel sheet

now I have another problem that makes me crazy, its says:

"Microsoft Excel: Can’t obtein access to ‘Sheet1’,the document can be read-only or coding "

Sheet1= is excel sheet name

Diego

Subject: RE: how to import an excel sheet

is excel closed while you try to import?

Else, try to copy the sheet into new excel sheet, using “paste special” and “only value”

Ugo

Subject: RE: how to import an excel sheet

yes,everything is ok, now I created other sheet and I open that, but now the error is different, now is:

OLE: Automation object error

Subject: RE: how to import an excel sheet

Sorry for late response…

Ole “automation error” is a general purpose error of MS Office object. Often the object is empty XlApp or XlSheet or workbooks…

You can try excel’s objets related codeline into vba of excel (Alt+F11)