AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Datenbanken excel tabsheet einlesen , OLE fehler

excel tabsheet einlesen , OLE fehler

Ein Thema von bernhard_LA · begonnen am 23. Nov 2015 · letzter Beitrag vom 23. Nov 2015
 
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.138 Beiträge
 
Delphi 11 Alexandria
 
#1

excel tabsheet einlesen , OLE fehler

  Alt 23. Nov 2015, 11:10
Datenbank: MSSQL • Version: 8 • Zugriff über: ADO
ich möchte mit dieser Funktion (Quelle http://www.swissdelphicenter.ch/de/showcode.php?id=1728)
ein Excel Arbeitsblatt einlesen .


Delphi-Quellcode:
function Xls_To_StringGrid(AGrid: TStringGrid; AXLSFile: string): Boolean;
const
   xlCellTypeLastCell = $0000000B;
var
   XLApp, Sheet: OLEVariant;
   RangeMatrix: Variant;
   x, y, k, r: Integer;
begin
   Result := False;
   // Create Excel-OLE Object
   XLApp := CreateOleObject('Excel.Application');
   try
     // Hide Excel
     XLApp.Visible := False;

     // Open the Workbook
     XLApp.Workbooks.Open(AXLSFile);

     // Sheet := XLApp.Workbooks[1].WorkSheets[1];
     Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];

     // In order to know the dimension of the WorkSheet, i.e the number of rows
     // and the number of columns, we activate the last non-empty cell of it

     Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
     // Get the value of the last row
     x := XLApp.ActiveCell.Row;
     // Get the value of the last column
     y := XLApp.ActiveCell.Column;

     // Set Stringgrid's row &col dimensions.

     AGrid.RowCount := x;
     AGrid.ColCount := y;

     // Assign the Variant associated with the WorkSheet to the Delphi Variant

     RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;
     // Define the loop for filling in the TStringGrid
     k := 1;
     repeat
       for r := 1 to y do
         AGrid.Cells[(r - 1), (k - 1)] := RangeMatrix[K, R];
       Inc(k, 1);
       AGrid.RowCount := k + 1;
     until k > x;
     // Unassign the Delphi Variant Matrix
     RangeMatrix := Unassigned;

   finally
     // Quit Excel
     if not VarIsEmpty(XLApp) then
     begin
       // XLApp.DisplayAlerts := False;
       XLApp.Quit;
       XLAPP := Unassigned;
       Sheet := Unassigned;
       Result := True;
     end;
   end;
end;
#1 :
und erhalte diesen OLE Fehler beim Einlesen einer ersten Tabelle, woran liegt es ....???

#2:
Ich habe eine andere *.xls Datei getestet und bekomme den zweiten OLE Fehler
Angehängte Grafiken
Dateityp: jpg ole_error.jpg (15,6 KB, 20x aufgerufen)
Dateityp: jpg ole2.jpg (17,1 KB, 14x aufgerufen)

Geändert von bernhard_LA (23. Nov 2015 um 11:22 Uhr)
  Mit Zitat antworten Zitat
 

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:03 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz