问题描述
我对处理完全陌生,我想通过创建一个绘制矩形的简单草图来对其进行测试,但是,当我运行该草图时,会弹出一个没有任何内容的窗口。我尝试填充它,在其上勾勒出轮廓,以及其他各种东西,什么都没发生。我认为这不是代码问题,而是应用程序本身的问题,我不确定如何解决。我正在Windows上处理3.5.4。
代码:
uses
System.Win.ComObj,Excel2010
...
procedure GerarExcel(ADBGrid: TDBGrid; AQuery: TFDQuery);
var
Excel: Variant;
linha,coluna,I,X: Integer;
begin
{Here you create the Excel Application Object}
Excel := CreateOleObject('Excel.Application');
{If you want to open the excel you can set this line to True.
In case you want to save directly without user intervention you can set to False.}
Excel.Visible :=True;
Excel.Workbooks.Add;
{In this case
Titles begin on the (4) line and different columns (1-7)}
Excel.WorkBooks[1].Sheets[1].Cells[4,1].Interior.ColorIndex := 55;
Excel.WorkBooks[1].Sheets[1].Cells[4,1].Font.ColorIndex := 2;
Excel.WorkBooks[1].Sheets[1].Cells[4,1].Font.Bold := True;
Excel.WorkBooks[1].Sheets[1].Cells[4,1].font.size := 10;
Excel.WorkBooks[1].Sheets[1].Cells[4,1] := 'Your Title 2';
Excel.WorkBooks[1].Sheets[1].Cells[4,1].ColumnWidth := 15;
...
Excel.WorkBooks[1].Sheets[1].Cells[4,7].Interior.ColorIndex := 55;
Excel.WorkBooks[1].Sheets[1].Cells[4,7].Font.ColorIndex := 2;
Excel.WorkBooks[1].Sheets[1].Cells[4,7].Font.Bold := True;
Excel.WorkBooks[1].Sheets[1].Cells[4,7].font.size := 10;
Excel.WorkBooks[1].Sheets[1].Cells[4,7] := 'Your Title 7';
Excel.WorkBooks[1].Sheets[1].Cells[4,7].ColumnWidth := 17;
Excel.WorkBooks[1].Sheets[1].Cells[4,7].HorizontalAlignment := 4;
Excel.WorkBooks[1].Sheets[1].Cells[4,7].verticalAlignment := 1;
I := 1;
{In case you want to loop through a TClientDateSet to fill in the cells}
with AQuery do
begin
First;
while not Eof do
begin
{To change to a specific format}
Excel.WorkBooks[1].Sheets[1].Cells[I + 4,1].NumberFormat := 'dd/mm/aaaa';
Excel.WorkBooks[1].Sheets[1].Cells[I + 4,1] := FieldByName(C_DATA).AsDateTime;
Excel.WorkBooks[1].Sheets[1].Cells[I + 4,2] := FieldByName(C_CONTA_CREDITO).Asstring;
Excel.WorkBooks[1].Sheets[1].Cells[I + 4,3] := FieldByName(C_CONTA_DEBITO).Asstring;
Excel.WorkBooks[1].Sheets[1].Cells[I + 4,4].NumberFormat := 'R$#.##0,00';
Excel.WorkBooks[1].Sheets[1].Cells[I + 4,4] := FieldByName(C_VALOR).Asstring;
Excel.WorkBooks[1].Sheets[1].Cells[I + 4,5] := FieldByName(C_DESCRICAO).Asstring;
Excel.WorkBooks[1].Sheets[1].Cells[I + 4,6] := FieldByName(C_NOME).Asstring;
Excel.WorkBooks[1].Sheets[1].Cells[I + 4,7] := FieldByName(C_NOME_MOVIMENTO).Asstring;
Inc(I);
Next;
end;
end;
{All these variables configure the for landscape printing.}
Excel.ActiveSheet.PageSetup.RightFooter := 'Página &P de &N';
Excel.ActiveSheet.PageSetup.LeftFooter := '&D';
Excel.ActiveSheet.PageSetup.Orientation := 2;
Excel.ActiveSheet.PageSetup.PaperSize := xlPaperA4;
Excel.ActiveSheet.PageSetup.FitToPagesTall := False;
Excel.ActiveSheet.PageSetup.Zoom := False;
Excel.ActiveSheet.PageSetup.FitToPagesWide := 1;
{If you want the user to see the excel being opened and save it wherever the user wants
You are done here.}
{Save the file automatically
If you want the user to NOT see the excel being opened and save the file in a specific folder automatically
In the beginning you need to set Visible := False and then these lines}
FilePath := 'C:\...\my_excel_file.xlsx';
if FileExists(FilePath) then
DeleteFile(FilePath);
Excel.WorkBooks[1].Sheets[1].SaveAs(FilePath);
Excel.Quit;
end;
class Sketch {
void setup() {
size(100,100);
}
void draw() {
rect(50,50,25,25);
}
}