Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
{step 1}
Range['A1','J1'].Value := VarArrayOf(['Order No',
{step 1}
Range['A1','J1'].Value2 := VarArrayOf(['Order No',
SELECT OrderNo, CustNo, SaleDate, EmpNo, ShipVIA, Terms, ItemsTotal, TaxRate, Freight, AmountPaid
FROM "orders.db" Orders where ItemsTotal > 15000
Sub ExportToExcel()
'
' ExportToExcel Macro
' Macro recorded 2/10/2002 by
[b] [i] {step 1} [/i] [/b]
Range("A1").Select
ActiveCell.FormulaR1C1 = "Order No"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Cust No"
Range("C1").Select
[b] [i] etc.. [/i] [/b]
Range("J1").Select
ActiveCell.FormulaR1C1 = "Amount Paid"
[b][i]{step 2} [/i][/b]
Range("A1:J1").Select
Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
[b] [i] {step 3} [/i] [/b]
Range("A2").Select
ActiveCell.FormulaR1C1 = "100"
Range("B2").Select
ActiveCell.FormulaR1C1 = "200"
Range("C2").Select
ActiveCell.FormulaR1C1 = "11/6/2001"
Range("D2").Select
ActiveCell.FormulaR1C1 = "30"
Range("E2").Select
ActiveCell.FormulaR1C1 = "Agent"
Range("F2").Select
ActiveCell.FormulaR1C1 = "Fob"
Range("G2").Select
[b] [i] etc.. [/i] [/b]
Range("H3").Select
ActiveCell.FormulaR1C1 = "2"
Range("I3").Select
ActiveCell.FormulaR1C1 = "1000"
Range("J3").Select
ActiveCell.FormulaR1C1 = "9000"
[b] [i] {step 4} [/i] [/b]
Columns("C:C").Select
Selection.NumberFormat = "d-mmm-yy"
[b] [i] {step 5} [/i] [/b]
Columns("H:H").Select
Selection.NumberFormat = "0.00%"
[b] [i] {step 6} [/i] [/b]
Columns("G:G").Select
Selection.NumberFormat = "$#,##0.00"
Columns("I:I").Select
Selection.NumberFormat = "$#,##0.00"
Columns("J:J").Select
Selection.NumberFormat = "$#,##0.00"
[b] [i] {step 7} [/i] [/b]
Range("A1:J3").Select
Selection.AutoFormat Format:=xlRangeAutoFormatList1, Number:=True, Font:= _
True, Alignment:=True, Border:=True, Pattern:=True, Width:=True
[b] [i] {step 8} [/i] [/b]
Columns("C:C").EntireColumn.AutoFit
End Sub
procedure TForm1.bbtnExportToExcelClick(Sender: TObject);
var
LineNumber, LCID : Integer;
LineString : string;
begin
with SaveDialog1 do
begin
FileName :=';
Filter:= 'Excel files|*.XLS;All Files|*.*';
DefaultExt := 'XLS';
Title := 'Exporting to Excel';
if execute then
begin
query1.Open;
LCID := GetUserDefaultLCID;
with ExcelApplication1 do
begin
connect;
try
visible[LCID] := true;
Workbooks.Add(EmptyParam,LCID);
commands found in macro
[b] [i] {step 1} [/i] [/b]
Range['A1','J1'].Value := VarArrayOf(['Order No',
'Cust No','Sale Date','Emp No',
'Ship Via', 'Terms','Items Total',
'Tax Rate','Freight','Amount Paid']);
[b] [i] {step 2} [/i] [/b]
with Range['A1','J1']do
begin
HorizontalAlignment := xlcenter;
VerticalAlignment := xlBottom;
Wraptext := false;
Orientation := 0;
ShrinkTofit := false;
MergeCells := false;
Font.Bold := true;
end;
Query1.First;
LineNumber := 1;
[b] [i] {step 3} , where by iteration the data from the query is transported to excell [/i] [/b]
While not query1.Eof do
begin
Inc(lineNumber);
LineString := IntToStr(LineNumber);
Range['A'+LineString, 'J'+LineString].Value :=
VarArrayof([Query1OrderNo.value, Query1CustNo.Value
[b] [i] {step 4} is built in [/i] [/b]
FormatDateTime('d-mmm-yy',Query1SaleDate.Value),
Query1EmpNo.Value, Query1ShipVIA.Value,
Query1Terms.Value, Query1ItemsTotal.Value,
Query1TaxRate.Value, Query1Freight.Value,
Query1AmountPaid.Value]);
Query1.Next;
end;
LineString := IntToStr(LineNumber);
[b] [i] {step 5 and 6} [/i] [/b]
Range['H2','G'+LineString].NumberFormat := '0.00%';
Range['G2','G'+LineString].NumberFormat := '$#,##0.00';
Range['I2','I'+LineString].NumberFormat := '$#,##0.00';
Range['J2','J'+LineString].NumberFormat := '$#,##0.00';
[b] [i] {step 7} [/i] [/b]
Range['A1','J'+LineString].AutoFormat(xlRangeAutoFormatlist1, true,
true,true,true,true,true);
[b] [i] {step 8} [/i] [/b]
Range['A1','J'+LineString].Columns.AutoFit;
[b][i]end of macro stuff [/i][/b]
ActiveWorkbook.SaveAs(FileName,xlNormal, ', ', false, false,
xlNochange,xlUserResolution,False,EmptyParam,EmptyParam,
LCID);
Quit;
finally
disconnect;
end; //try
end; //with Excelapplication1
end; //if execute
end; //with Savedialog1
end;
Range['A1','J1'].Value := VarArrayOf(['Order No',
'Cust No','Sale Date','Emp No',
'Ship Via', 'Terms','Items Total',
'Tax Rate','Freight','Amount Paid']);