Autor Beitrag
galbe19
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Fr 28.03.08 07:35 
hallo

ich habe ein program wo ich ein Excel exportiere.
ich habe definiert
uses excelXp;
aber das probelem ist ich habe excel 2007.
meine frage ist wie ich excel 2007 definiere und ob ich mein Programm auch euf einen rechner mit excel XP ausfuhren kann.

mfg
Alex
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 28.03.08 07:54 
Die COM-Schnittstelle sollte eigentlich rückwärtskompatibel sein. Die ExcelXX-Schnittstelle sollte eigentlich auch mit excel2007 funktionieren.

_________________
Markus Kinzler.
galbe19 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Fr 28.03.08 07:57 
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:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
uses excel Xp

unction tform1.ExportToExcel(oDataSet : TDataSet; sFile,text : String): Boolean;
var iCol,iRow : Integer;

         oExcel    : TExcelApplication;
         oWorkbook : TExcelWorkbook;
         oSheet    : TExcelWorksheet;
begin
         iCol   := 0;
         iRow   := 0;
         result := True;

         oExcel    := TExcelApplication.Create(Application);
         oWorkbook := TExcelWorkbook.Create(Application);
         oSheet    := TExcelWorksheet.Create(Application);

         try
            oExcel.Visible[0] := False;
            oExcel.Connect;
         except
            result            := False;
            MessageDlg('Excel may not be installed', mtError, [mbOk], 0);
            exit;
         end;

         //To make Excel visible.
         oExcel.Visible[0] := False;

         //Document title.
         oExcel.Caption    := 'This is the document title';
         oExcel.Workbooks.Add(Null,0);

         oWorkbook.ConnectTo(oExcel.Workbooks[1]);
         oSheet.ConnectTo(oWorkbook.Worksheets[1] as _Worksheet);

         iRow := 1;

         //To write the fileds names.
         for iCol:=0 to oDataSet.FieldCount-1 do begin
             oSheet.Cells.Item[iRow,iCol+1] := oDataSet.FieldDefs.Items[iCol].Name;
             oSheet.Cells.Item[iRow,iCol+1] := oDataSet.Fields[iCol].FieldName;
         end;

         oDataSet.Open;
         while NOT oDataSet.Eof do begin
               Inc(iRow);

               for iCol:=1 to oDataSet.FieldCount do begin
                   oSheet.Cells.Item[iRow,iCol] := oDataSet.Fields[iCol-1].AsString;
               end;

               oDataSet.Next;
         end;

         //Change the wprksheet name.
         oSheet.Name := Text;

         //Change the font properties of all columns.
         oSheet.Columns.Font.Color     := clBlack;
         oSheet.Columns.Font.FontStyle := fsBold;
         oSheet.Columns.Font.Size      := 10;

         //Auto fit all columns.
         oSheet.Columns.AutoFit;

         //Delete file if exists.
         DeleteFile(sFile);

         oSheet.SaveAs(sFile);
         oSheet.Disconnect;
         oSheet.Free;

         oWorkbook.Disconnect;
         oWorkbook.Free;

         oExcel.Quit;
         oExcel.Disconnect;
         oExcel.Free;
end;

das ist meine textcode.
und wenn ich sie auf einen rechner mit Excel 2007 ausfuhre bekomme ich einen fehler wegen excel.

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
Bernhard Geyer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 721
Erhaltene Danke: 3



BeitragVerfasst: Fr 28.03.08 10:43 
user profile icongalbe19 hat folgendes geschrieben:
[und wenn ich sie auf einen rechner mit Excel 2007 ausfuhre bekomme ich einen fehler wegen excel.

Mhh. Die Fehlermeldung "einen fehler wegen excel" kenn ich nicht :?:
Es wäre hilfreich wenn du etwas genau wärst bezüglich Fehlermeldung und stelle wo dieser Fehler auftritt. Ist Excel schon registriert?
galbe19 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Fr 28.03.08 11:02 
also

das programm funktioniert wenn ich auf den rechner das excel Xp drauf habe.
dar programm funktioniert aber nicht mehr wenn ich excel 2007 habe.

das ist das probelm

mfg
Alex
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Fr 28.03.08 11:23 
Welche Fehlermeldung kommt denn genau? Bernhard hat nach dem Wortlaut des Fehlers gefragt.

_________________
mfg. Joel
galbe19 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Fr 28.03.08 11:43 
es kommt keine Fehlermeldung
es hangt sich einfach auf und die excel datei wird nicht gespreichert.

mfg
Alex
Bernhard Geyer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 721
Erhaltene Danke: 3



BeitragVerfasst: Fr 28.03.08 14:47 
SaveAs gibts in mehreren Versionen. Da das Standardformat in Excel2007 XLSX ist könntest du probleme bekommen wenn du es mit XLS und Standardformat versuchst zu speichern (und das wird verwendet wenn du SaveAs ohne weitere Parameter aufrufst).

Laß mal Excel sichtbar. Evtl. wird ja u.U. auch die Fehlermeldung ohne Sichtbarkeit versteckt.