Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 22.04.08 16:02 
Hi, Delpher,

hab im Netz nichts gefunden zu folgendem Problem:

Ich lese eine ExcelTabelle in ein Stringgrid ein - klappt super, wenn in dem Feldinhalt (also in der Excelzelle) kein Umlaut vorkommt. Ist das der Fall, wird der Eintrag vollständig unterdrückt, also bei c1r1 Tanja c2r1 Möller sehe ich nur c1r1 Tanja und die Zelle c2r1 ist leer.

Wer weiß dazu eine Lösung?

Vielen Dank für Hilfe,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 22.04.08 16:17 
Moin!

Lies doch die Zelle mal in eine temp. StringVar aus und gib sie mit ShowMessage aus, um auszuschließen, dass das StringGrid irgendwelche Probleme mit dem Inhalt hat. Zumindest ein erster Schritt... :?

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 22.04.08 18:46 
Hi, Narses,

vielen Dank für deine Idee!

Ich habe in der Zwischenzeit Folgendes gemacht: Ich habe die Tabelle eingelesen, die "fehlenden" - mir aber zum Glück bekannten Namen - eingetragen .. options := options + [goediting] ... , abgespeichert und wieder eingelesen, und siehe da, alles bestens! Also, wer weiß, mit welchem Programm / auf welche Weise die Daten mal abgespeichert wurden. Die Schriftart war nämlich auch gleich.

So geht's - es lebe Delphi und ver... sei MicroSchrott!

Grüße,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 04.05.08 12:20 
Hi, Delpher,

ich muss mich noch einmal zu diesem Problem melden.
Die Excel-Tabelle lese ich mit folgendem Code ein:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
function TForm4.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;
  XLApp := CreateOleObject('Excel.Application');  // Create Excel-OLE Object
  try
    XLApp.Visible := False;
    XLApp.Workbooks.Open(AXLSFile);
    Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];  // Sheet := XLApp.Workbooks[1].WorkSheets[1];

    Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;  //last non-empty cell

    x := XLApp.ActiveCell.Row; y := XLApp.ActiveCell.Column;  //Nummer der last row, column
    AGrid.RowCount := x; AGrid.ColCount := y;     // Set Stringgrid's row &col dimensions.

    // Assign the Variant associated with the WorkSheet to the Delphi Variant
    RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;

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

  finally
    if not VarIsEmpty(XLApp) then
    begin     // XLApp.DisplayAlerts := False;
      XLApp.Quit;
      XLAPP := Unassigned;
      Sheet := Unassigned;
      Result := True;
    end;
  end;
end;


Ich habe sie vorher mit Delphi erstellt. Aber, wie gesagt, ein Zellinhalt, der einen Umlaut enthält, wird nicht dargestellt - verschluckt (siehe oben).

Wer kann dieses Problem lösen?

Zum Ausprobieren dient die angehängte Exceltabelle.

Vielen Dank für eine Hilfe, bzw. Lösung!
Detlef A.
Einloggen, um Attachments anzusehen!
_________________
ut vires desint, tamen est laudanda voluntas
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 06.05.08 10:13 
Ein Nachtrag:

Wenn ich einen "verschluckten" Namen nachträglich ins Stringgrid eintrage, abspeichere und mir mit Excel ansehe, werden Zeichen von der Art Ä1/4 usw. angezeigt.
Welche Einstellung passt da nicht?

Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 06.05.08 10:34 
Moin!

user profile iconD. Annies hat folgendes geschrieben:
for r := 1 to y do AGrid.Cells[r-1, k-1] := vartowidestr(RangeMatrix[K, R]);Wer kann dieses Problem lösen?
Hm, kann es sein, dass das ein MBCS-Problem ist? :? Schätze, das TStringGrid ist nicht der Lage, einen WideString korrekt dazustellen. :nixweiss:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 06.05.08 13:28 
Hi, Narses,

vielen Dank für deine Antwort (bist ja wohl der Einzige, der dazu überhaupt etwas sagen kann .. aber wie sagte schon Einstein: Ein einziger reicht!)

Nun, aufgrund deiner Aussage habe ich alles noch einmal überprüft: Stutzig wurde ich als Showmessage den Umlaute-Namen richtig ausgeben konnte - und dann habe ich den Fehler gesehen: Als Übergabeparameter war ein TStringgrid angegeben, aber es musste ein TTntStringgrid sein (wegen Unicode) und jetzt klappt alles bestens !!! :dance2: :dance: :dance2: :mrgreen:

Juhu, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Mi 07.05.08 09:19 
Kleiner Nachtrag:

Ich habe den Code noch etwas vereinfacht (?)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
{RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;

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


    for k := 0 to x-1 do
    for r := 0 to y-1 do
      AGrid.cells[r,k] := XlApp.cells[k+1,r+1];


Vielleicht ist er so leichter lesbar statt mit RangeMatrix.
Detlef

_________________
ut vires desint, tamen est laudanda voluntas