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:
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:
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??