Entwickler-Ecke
Sonstiges (Delphi) - Excel per OLE Einfache Rahmenlinien
Boldar - Mo 14.07.08 21:24
Titel: Excel per OLE Einfache Rahmenlinien
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:
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:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
| const vstart = 1; const hstart = 1; const vend = 40; const hend = 40;
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:
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; 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); 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; 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
Delphi-Quelltext
1:
| excel.sheets[1].cells[x, y].Borders.Item[xlEdgeBottom].LineStyle := xldouble; |
einwandfrei, aber bei einfachen Rahmenlinien entstehen sowohl so
Delphi-Quelltext
1:
| excel.sheets[1].cells[x, y].Borders.Item[xlEdgeBottom].LineStyle := xlthick; |
als auch so
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:
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 - Di 15.07.08 22:40
Hatte denn noch niemand dieses Problem????
Bergmann89 - Mi 16.07.08 00:15
HI,
ich hab das damals so gemacht:
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 - Mi 16.07.08 13: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:
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
Entwickler-Ecke.de based on phpBB
Copyright 2002 - 2011 by Tino Teuber, Copyright 2011 - 2026 by Christian Stelzmann Alle Rechte vorbehalten.
Alle Beiträge stammen von dritten Personen und dürfen geltendes Recht nicht verletzen.
Entwickler-Ecke und die zugehörigen Webseiten distanzieren sich ausdrücklich von Fremdinhalten jeglicher Art!