Autor Thema: Excel in Datenbank importieren!  (Gelesen 1791 mal)

Offline Christopher

  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 1.060
  • Geschlecht: Männlich
  • Dumm ist der, der dummes tut.
Excel in Datenbank importieren!
« am: 07.06.02 - 13:31:37 »
Hallo Leute,

ich suche einen Agenten oder eine Möglichkeite ohne viel Aufwand womit ich eine Exceltabelle oder CSV Datei in eine NotesDatenbank importiere.

Viele Grüße

Christopher
« Letzte Änderung: 01.01.70 - 01:00:00 von 1034200800 »
Client & Server R 5.011
Principal Certified Lotus Professional R5 System Administration
Microsoft Certified Systems Engineer 2000
Microsoft Certified Systems Administrator 2000
Microsoft Certified Systems Administrator 2003
Microsoft Certified Systems Engineer 2003

Offline eknori

  • @Notes Preisträger
  • Moderator
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 11.730
  • Geschlecht: Männlich
Re: Excel in Datenbank importieren!
« Antwort #1 am: 07.06.02 - 13:46:31 »
Speichere die tabelle als .WK4 Datei ab, dann kannst du über die IMPORT Funktionen von Notes die Daten in deine DB importieren.

Oder du machst es über script. Hier mal ein Beispiel:
(nicht von mir und ohne Garantie)


After spending a great deal of time to import information from Excel over the years, I wrote the following code to pull data from Excel files. The code allows me to get the users data into a blank database where I can manipulate it. The script assumes that the values in the first row are the names to be used for the field names and that the data begins on the second row. It continues to search for columns until it finds a blank cell in the first row. After finding which columns to use it adds a document for each row in the Excel file until it finds a blank row. Hope you find the following useful.

=============================
Jason Goodloe
jgoodloe@evolvetech.com
     
Code:  'Re-formated Version 'Multi-platform:

Option Public
Option Explicit


'WIN32
Declare Function W32_NEMGetFile Lib "nnotesws" Alias "NEMGetFile" ( wUnk As Integer, Byval szFileName As String, Byval szFilter As String, Byval szTitle As String ) As Integer
'WIN16
Declare Function W16_NEMGetFile Lib "_nem" Alias "NEMGetFile" ( wUnk As Integer, Byval szFileName As String, Byval szFilter As String, Byval szTitle As String ) As Integer
'OS2
Declare Function OS2_NEMGetFile Lib "inotesws" Alias "NEMGetFile" ( wUnk As Integer, Byval szFileName As String, Byval szFilter As String, Byval szTitle As String ) As Integer
'use nnotesws for Win95 and WinNT, inotesws for OS/2, and _nem for Win16




Sub Initialize
%REM
******************************************************************************
OverView: This Function deletes all of the documents in the current
database and then re-populates the database based on data
contained in the excel file. The column heading row is used
for the field names in the notes doucments.
Input: User must supply the path and file name for the excel file
Results: Creates a Notes document for each row in the excel spreadsheet,
excluding the header row
Called By: This function is run from the agent list
Assumptions: 1. Data is on one worksheet only and that this worksheet is
the first worksheet in the workbook
2 Worksheet uses the first row as a column heading
3. The first blank column header is assumed to be the
last column to read data in the file
4. The first blank row is assumed to be the last row of the file
5. Field names are the first 20 spaces of the column heading
excluding spaces
******************************************************************************
M O D I F I C A T I O N H I S T O R Y
******************************************************************************
Date BY Description
----------------- -------------------- ------------------------------
09/22/1999 J.Goodloe Initial Development 4.6.2
******************************************************************************
%END REM
Dim S As New NotesSession
Dim db As NotesDatabase
Dim Doc As NotesDocument
Dim item As NotesItem
Dim strCellRange$
Dim varCellValue As Variant
'File Dialog
Dim strFileName As String*256
Dim strTitle$
Dim strFilter$
'Excel Application
Dim varExcelApp As Variant
Dim varExcelWB As Variant
Dim varExcelSheet As Variant
'Valid columns list
Dim strExcelCodeList List As String
Dim FirstletterCode&
Dim LastletterCode&
'Iterate Rows
Dim intExcelRow%
Dim bIsRowBlank%
Dim bRowValueFound%

Set db = S.CurrentDatabase

'File Dialog
strFileName = Chr(0)
strTitle$ = s.Commonusername & ", select your database NOW"
strFilter$ = "MS Excel Files|*.xls|All Files|*.*|" 'Use this format for ANY file type

If IsDefined ("WIN32") Then
If W32_NEMGetFile (0, strFileName, strFilter$, strTitle$) <> 0 Then
strFileName = strFileName & |"| 'We need to do this because the return is a NULL terminated string.
End If
Elseif IsDefined ("WIN16") Then
If W16_NEMGetFile (0, strFileName, strFilter$, strTitle$) <> 0 Then
strFileName = strFileName & |"|
End If
Elseif IsDefined ("OS2") Then
If OS2_NEMGetFile (0, strFileName, strFilter$, strTitle$) <> 0 Then
strFileName = strFileName & |"|
End If
Else
Msgbox "Cannot load file dilog on this operating system." & Chr(13) & "Process Terminated."
Exit Sub
End If

'Open Excel Application
Set varExcelApp = CreateObject ("Excel.Application")
Set varExcelWB = varExcelApp.Workbooks.Open (strFileName)
'varExcelApp.Visible = True 'Uncomment this if you want to see the excel worksheet
Set varExcelSheet = varExcelWB.Application.Workbooks (1).Worksheets (1)

'Determine Valid columns list
For LastletterCode& = Asc("A") To Asc("Z")
strExcelCodeList (Chr$ (LastletterCode&)) = "1"
Next
For FirstletterCode& = Asc("A") To Asc("K")
For LastletterCode& = Asc("A") To Asc("Z")
strExcelCodeList (Chr$ (FirstletterCode&) & Chr$ (LastletterCode&)) = "1"
Next
Next
On Error Resume Next 'used to allow searching across multiple columns
Forall x In strExcelCodeList
strCellRange$ = Listtag (x) + "1"
varCellValue = ""
varCellValue = ReplaceValue (Cstr (varExcelSheet.Range (strCellRange$).value), " ", "")
If varCellValue <> "" Then
strExcelCodeList (Listtag (x)) = Left (varCellValue, 20)
Else
Erase strExcelCodeList (Listtag (x))
End If
End Forall
On Error Goto 0

'Iterate Rows to gather data
bIsRowBlank% = False
intExcelRow% = 2 'Start with Second row, First row is a header
While Not bIsRowBlank%
bRowValueFound% = False
Set Doc = New NotesDocument (db)
Forall y In strExcelCodeList
strCellRange$ = Listtag (y) + Cstr (intExcelRow%)
varCellValue = varExcelSheet.Range (strCellRange$).value
Set item = Doc.ReplaceItemValue (strExcelCodeList (Listtag (y)), varCellValue)
If (Not (bRowValueFound%)) And (Cstr (varCellValue) <> "") Then
bRowValueFound% = True
End If
End Forall

If bRowValueFound% Then
Call Doc.Save (True, False)
Set Doc = Nothing
Else
bIsRowBlank% = True
End If
intExcelRow% = intExcelRow% + 1
Wend

'Close Excel Application
On Error Resume Next
varExcelWB.activeworkbook.close
varExcelWB.quit
Set varExcelWB = Nothing
End Sub



Function ReplaceValue (strTxt$, strStringToReplace$, strReplaceWith$) As String
%REM
Funciton works similar to @ReplaceSubString function
%END REM
Dim intValuePos%
Dim strLeftTxt$
intValuePos% = Instr (1, strTxt$, strStringToReplace$)
While Not intValuePos% = 0
strLefttxt$ = Left$ (strTxt$, intValuePos% - 1)
strTxt$ = strLefttxt$ + strReplaceWith$ + Right$ (strTxt$, Len (strTxt$) - Len (strLefttxt$) - Len (strStringToReplace$))
intValuePos% = Instr (1, strTxt$, strStringToReplace$)
Wend
ReplaceValue = strTxt$
End Function
« Letzte Änderung: 01.01.70 - 01:00:00 von 1034200800 »
Egal wie tief man die Messlatte für den menschlichen Verstand auch ansetzt: jeden Tag kommt jemand und marschiert erhobenen Hauptes drunter her!

Offline Christopher

  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 1.060
  • Geschlecht: Männlich
  • Dumm ist der, der dummes tut.
Re: Excel in Datenbank importieren!
« Antwort #2 am: 07.06.02 - 15:27:11 »
Hallo Ulrich,

danke für Deine schnelle Antwort werde es gleich am Wochenende ausprobieren.

Hab mal so eine tolle Aufgabe bekommen. :-(

Gruß Christopher
« Letzte Änderung: 01.01.70 - 01:00:00 von 1034200800 »
Client & Server R 5.011
Principal Certified Lotus Professional R5 System Administration
Microsoft Certified Systems Engineer 2000
Microsoft Certified Systems Administrator 2000
Microsoft Certified Systems Administrator 2003
Microsoft Certified Systems Engineer 2003

Offline M_Messer

  • Junior Mitglied
  • **
  • Beiträge: 98
  • Geschlecht: Männlich
Re: Excel in Datenbank importieren!
« Antwort #3 am: 11.06.02 - 08:19:30 »
hi

würde das nicht auch ganz einfach über das simply notes import tool gehen ???

messer
« Letzte Änderung: 01.01.70 - 01:00:00 von 1034200800 »
- notes 5.0.4
- nt 4.0 sp6

Offline Christopher

  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 1.060
  • Geschlecht: Männlich
  • Dumm ist der, der dummes tut.
Re: Excel in Datenbank importieren!
« Antwort #4 am: 11.06.02 - 21:30:42 »
Keine Ahnung ich Eknori´s erste Lösung gewält funktioniert sehr gut.
« Letzte Änderung: 01.01.70 - 01:00:00 von 1034200800 »
Client & Server R 5.011
Principal Certified Lotus Professional R5 System Administration
Microsoft Certified Systems Engineer 2000
Microsoft Certified Systems Administrator 2000
Microsoft Certified Systems Administrator 2003
Microsoft Certified Systems Engineer 2003

 

Impressum Atnotes.de  -  Powered by Syslords Solutions  -  Datenschutz