Autor Beitrag
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mo 14.07.08 22:24 
Ich steuere Excel per Ole. Nun Werden aber zuerst die Benötigten Änderungen ermittelt, und dann Daraus die xls Datei erstellt.

Ich habe folgende Unit eingefügt:

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:
unit xlsconstants;

interface

const
  xlThin = 2;
  xlThick = 4;
  xl3DColumn = -4100;
  xlColumns = 2;
  xlDouble = -4119;
  xlEdgeBottom = 9;
  xlUnderlineStyleSingle = 2;
  xlCenter = -4108;
  xlLocationAsObject = 2;
  xlBottom = -4107;
  xlDownward = -4170;
  xlCategory = 1;
  xlRows = 1;
  xlWorksheet = -4167;
  xlRight = -4152;
  xlLandscape = 2;
  xlPortrait = 1;
  xlEdgeTop = 8;
  xlEdgeLeft = 7;
  xlEdgeRight = 10;
  xlInsideVertical = 11;
  xlInsideHorizontal = 12;
  xlAutomatic = -4105;
  xlContinuous = 1;
  xlDiagonalUp = 6;
  xlDiagonalDown = 5;
  xlNone = -4142;
  xlSolid = 1;
  xlLeft = -4131;

implementation

end.



ich Habe folgende Typdefinition als Temporärer Zwischenspeicher:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
const vstart = 1;         //-->vertical start point in arrexcel
const hstart = 1;         //-->horizontal start point in arrexcel
const vend = 40;          //-->vertical stop point in arrexcel
const hend = 40;          //-->horizontal stop point in arrexcel


type linestyles = (double, thin, thick, none);

type excelstr = record
  inhalt: shortstring;
  Bold: boolean;
  kursiv: boolean;
  size: integer;
  bottom, right: linestyles;
  end;

type arrexcel = array [vstart..vend, hstart..hend] of excelstr;




Nun haben ich folgenden Code:
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:
{======================================================}
procedure Tform_abrechnung.Excel (const a: arrexcel; sheetname, filename: shortstring);
var
  Excel : Variant;
  y, x: byte;
  list : tprocesslist;
begin
  try
    {======================================================}
    Excel := CreateOleObject('Excel.Application');
    excel.Application.SheetsInNewWorkBook := 1//Die 1 is die Anzahl der Sheets
    Excel.Workbooks.Add;
    Excel.Sheets[1].name := sheetname;
    excel.range['A1:D1'].select;
    excel.selection.font.bold := true;
    excel.selection.font.size := 20;
    excel.columns[1].columnwidth := 21;
    for x := vstart to vend do
    begin
    application.processmessages;
      for y := hstart to hend do
      begin
        inc (setp);                       //setp ist eine Globale integer-Variable und f eine Tprogressbar
        f.position := setp;
        Excel.Sheets[1].Cells[x, y].Value := a[x, y].inhalt;
        Excel.Sheets[1].Cells[x, y].font.bold:= a[x, y].Bold;
        if a[x, y].bottom=double then excel.sheets[1].cells[x, y].Borders.Item[xlEdgeBottom].LineStyle := xldouble;
        if a[x, y].bottom= thick then excel.sheets[1].cells[x, y].Borders.Item[xlEdgeBottom].LineStyle := xlcontinuous;
        if a[x, y].bottom=  thin then excel.sheets[1].cells[x, y].Borders.Item[xlEdgeBottom].LineStyle := xlthin;
        if a[x, y].right=double then excel.sheets[1].cells[x, y].Borders.Item[xledgeright].LineStyle := xldouble;
        if a[x, y].right=  thin then excel.sheets[1].cells[x, y].Borders.Item[xledgeright].LineStyle := xlcontinuous;
        if a[x, y].right= thick then excel.sheets[1].cells[x, y].Borders.Item[xledgeright].LineStyle := xlthin;
        excel.sheets[1].cells[x, y].font.size := a[x, y].size;
      end;
    end;
    Excel.ActiveWorkbook.SaveAs(filename);
  finally
    Excel.DisplayAlerts := False;
    Excel.Quit; //Beendet Excel
    Excel := Unassigned;
    f.position := 0;
    end;

end;


Nun schreibe ich in einer Schleife die Werte aus dem array in excel. Der Rahmen funktioniert bei Doppelten Linien, also so
ausblenden Delphi-Quelltext
1:
excel.sheets[1].cells[x, y].Borders.Item[xlEdgeBottom].LineStyle := xldouble;					


einwandfrei, aber bei einfachen Rahmenlinien entstehen sowohl so

ausblenden Delphi-Quelltext
1:
excel.sheets[1].cells[x, y].Borders.Item[xlEdgeBottom].LineStyle := xlthick;					


als auch so

ausblenden Delphi-Quelltext
1:
excel.sheets[1].cells[x, y].Borders.Item[xlEdgeBottom].LineStyle := xlthin;					


gestrichelte Linien. Wenn ich dass in Excel in einem Makro mache, gibt es folgenden Code:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Sub Makro1()
    Range("F11:H11").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Range("G22").Select
End Sub


in Delphi gibt es unter
excel.sheets[1].cells[x, y].Borders.Item[xlEdgeBottom]
bei mir aber das Element weight nicht, ausserdem bezeiht sich dass in VB ja auch auf die selection, und nicht auf die Zelle. Wie mache ich dass nun am bestem In meinem Fall? Müsste ich dann erst die Selection in diesem Bereich setzten??
Boldar Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Di 15.07.08 23:40 
Hatte denn noch niemand dieses Problem????
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Mi 16.07.08 01:15 
HI,

ich hab das damals so gemacht:

ausblenden Delphi-Quelltext
1:
XLApp.Workbooks[M].Worksheets[N].Range['B1:B30'].Borders[2].Weight  := 3;					


wobei der Wert in den [] hinter "Border" den in Exel bekannten Werten xlEdgeLeft, xlEdgeTop, xlEdgeBottom und xlEdgeRight entsprechen, welcher Integerwert zu welchem xlWert gehört weiß ich nich, da musst du n bisl experimentieren!

€: könnte auch sein, das deine Integer Werte in deiner eingebunden Unit falsch sind. Setz mal beliebige Integer Werte ein und notier dir, wie das ganze in Exel aussieht, dann kannst du dir die Konstanten selber setzten!

MfG Bergmann.
Boldar Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mi 16.07.08 14:51 
Ok dicke Linien schaffe ich jetzt, wenn ich weight auf 3 setzte.
So wie Gezeigt klappt es bei mir nicht, ich muss erst den Bereich selektieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
        if a[x, y].bottom= thick then
        begin
          excel.Range[Getexcelpoints(gettpoint(y, x))].select;
          excel.selection.borders[xledgebottom].weight:=3;
        end;


Aber welchen wert muss ich bei weight einsetzen für normale Linien??
Naja, cih werde mal ein bisschen Probieren.

Edit: Normale Linien Wert 2