AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Excel mit mehreren Sheets öffnen

Ein Thema von Moombas · begonnen am 5. Apr 2018 · letzter Beitrag vom 10. Sep 2018
 
Moombas
(Gast)

n/a Beiträge
 
#10

AW: Excel mit mehreren Sheets öffnen

  Alt 7. Sep 2018, 08:04
Moin zusammen,

ich bin es nochmal und habe einen kleinen Nachtrag/Nachfrage, die am besten hierzu passt.
Der Fehler der Exceltabelle beim Einlesen lag immer dann vor, wenn ein Filter gesetzt war und dieser bestimmte Zeilen raus gefiltert hat (ich war davon ausgegangen, das der Filter nur eine optische Geschichte ist und im Hintergrund die Tabelle ja noch alle Daten hat).

Weiß jemand wie ich den Filter über Delphi entferne? Das was in den Excel-Makros drin steht, hat leider nicht geholfen, denn wenn ich "Sheet.ShowAllData;" aktiviere kann mein Programm die Exceldatei nicht mehr einlesen (keine Fehlermeldung, das Stringgrid bleibt einfach leer). Ich würde damit gerne diese Fehlerquelle ausschließen.

Delphi-Quellcode:
function XLS_To_StringGrid(AXLApp : OleVariant; AGrid : TStringGrid; Sheetname : string):Boolean;
const
  xlCellTypeLastCell = $0000000B;
var
  Sheet: OLEVariant;
  RangeMatrix: Variant;
  X, Y, K, R: Integer;
begin
  Result := False;
  try
    try
      if (Sheetname <> '') and HaveSheet(AXLApp, Sheetname) then begin
        Sheet := AXLApp.WorkSheets[Sheetname];
      end else
        Sheet := AXLApp.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.select;
// Sheet.ShowAllData;
      Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
      X := AXLApp.ActiveCell.Row; // Get the value of the last row
      Y := AXLApp.ActiveCell.Column; // Get the value of the last column

      // Set Stringgrid's row &col dimensions.
      AGrid.RowCount := X; // Excel-Row 1 = Header
      AGrid.ColCount := Y;

      RangeMatrix := Sheet.Range['A1', Sheet.Cells.Item[X, Y]].Value; // Assign the Variant associated with the WorkSheet to the Delphi Variant
      // Define the loop for filling in the TStringGrid
      K := 0;
      While (K < X) do begin
        Inc(K);
        for r := 1 to y do
          AGrid.Cells[(R - 1), (K - 1)] := RangeMatrix[K, R];
      end;
      Result := True;
    except
      // Logging...
    end;
  finally
    RangeMatrix := Unassigned;
    Sheet := Unassigned;
  end;
end;

Geändert von Moombas ( 7. Sep 2018 um 08:09 Uhr)
  Mit Zitat antworten Zitat
 


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 03:58 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-2025 by Thomas Breitkreuz