Einzelnen Beitrag anzeigen

Benutzerbild von RWarnecke
RWarnecke

Registriert seit: 31. Dez 2004
Ort: Stuttgart
4.408 Beiträge
 
Delphi XE8 Enterprise
 
#16

Re: Vorhandene Excelliste bearbeiten

  Alt 22. Mai 2008, 11:10
Ich habe ein VB-Makro, welches mir aus einer Exceltabelle mit Daten ein SQL-Skript erstellt. Das ist die Schleife, die die komplette Tabelle durcharbeitet.
Code:
    For iWks = 1 To ActiveWorkbook.Worksheets.Count
      Open sPath & "Inhalt-Kostenstellen.sql" For Output As #1
      Set rng = ActiveWorkbook.Worksheets(iWks).Range("A1").CurrentRegion
      Print #1, "delete from kostenstellen where mandant > 0;"
      For iRow = 2 To rng.Rows.Count
         sTxt = sTxt & "INSERT INTO Kostenstellen(Mandant,Abteilung,Kostenstelle,Bezeichnung,CompanyID,Gesellschaft,Title) VALUES ("
         For iCol = 1 To rng.Columns.Count - 1
            If iCol = rng.Columns.Count - 1 Then
              sTxt = sTxt & "'" & ActiveWorkbook.Worksheets(iWks).Cells(iRow, iCol).Value & "'); "
            Else
              If iCol = 1 Then
                sTxt = sTxt & ActiveWorkbook.Worksheets(iWks).Cells(iRow, iCol).Value & ", "
              Else
                sTxt = sTxt & "'" & ActiveWorkbook.Worksheets(iWks).Cells(iRow, iCol).Value & "', "
              End If
            End If
         Next iCol
         Print #1, Left(sTxt, Len(sTxt) - 1)
         sTxt = ""
      Next iRow
      Close #1
    Next iWks
Dieser Teil geht jede Zeile und Spalte durch.
Rolf Warnecke
App4Mission
  Mit Zitat antworten Zitat