ext:=''周五,女,18,061-7557381'';
Rows.CommaText:=''孙涛,女,31,3324559'';
end;
end;
procedure TForm1.OpenExl;
begin with Excel do begin Connect;
LCID:=GetUserDefaultLCID();
wkBook:=WorkBooks.Add(EmptyParam,LCID);
wkSheet:=wkBook.Sheets as _WorkSheet;
end;
end;
procedure TForm1.Write2Xls;
var Datas:Variant;
i,j:Integer;
begin ir:=StringGrid1.RowCount;
ic:=StringGrid1.ColCount;
Datas:=varArrayCreate([1,ir,1,ic],varVariant);
for i:=1 to ir do for j:=1 to ic do Datas[i,j]:=StringGrid1.Cells[j-1,i-1];
with wkSheet do begin Activate(LCID);
Cells.Item[1,1].Value:=''通讯录'';
Range[cells.Item[3,1],cells.Item[ir+2,ic]].Value:=Datas;
end;
// Excel.Visible[LCID]:=True;
Datas:=Unassigned;
end;
procedure TForm1.Retrieve;
var Datas:Variant;
i,j:Integer;
begin with wkSheet do begin Cells.SpecialCells(xlCellTypeLastCell,EmptyParam).Activate;
ir:=Excel.ActiveCell.Row;
ic:=Excel.ActiveCell.Column;
Datas:=Range[Cells.Item[1,1],Cells.Item[ir,ic]].Value;
with StringGrid1 do begin ColCount:=ic;
RowCount:=ir;
ScrollBars:=ssBoth;
for i:=0 to ir-1 do for j:=0 to ic-1 do Cells[j,i]:=Datas[i+1,j+1];
end;
Datas:=UnAssigned;
end;
end;
procedure TForm1.CloseExl;
const SaveAsName=''test.xls'';
begin wkBook.Close(True,SaveAsName,EmptyParam,LCID);
Excel.Quit;
Excel.Disconnect;
end;
procedure TForm1.NameSheet;
begin AName:=wkBook.Names.Add(''通讯录'',''=Sheet1!$A$3:$D$7'',EmptyParam,EmptyParam, EmptyParam,EmptyParam,EmptyParam,EmptyParam, EmptyParam,EmptyParam,EmptyParam);
end;
procedure TForm1.AddFormula;
var AFormula:String;
begin AFormula:=''=Rand()'';
wkSheet.Range[''F3'',''G6''].Value:=AFormula;
end;
procedure TForm1.Formats;
begin with wkSheet.Range[''A1'',''D1''],Font do begin Merge(True);
//合并单元格 HorizontalAlignment:= xlCenter;
Size:=18;
Name:=''隶书'';
FontStyle:=Bold;
end;
wkSheet.Columns.EntireColumn.AutoFit;
with Aname.RefersToRange,Borders do begin HorizontalAlignment:= xlRight;
Item[xlEdgeBottom].Weight:=xlMedium;
Item[xlEdgeTop].Weight:=xlMedium;
Item[xlInsideHorizontal].Weight:=xlThin;
item[xlInsideVertical].Weight:=xlThin;
end;
end;
procedure TFOrm1.AddMacro;
var LineNo: integer;
CM: CodeModule;
sDate:String;
begin CM := WkBook.VBProject.VBComponents.Item(''ThisWorkbook'').Codemodule;
LineNo := CM.CreateEventProc(''BeforeClose'', ''Workbook'');
SDate:=''上次访问日期:''+DateToStr(Date());
CM.InsertLines(LineNo.1,.Range("
B2"
).Value."
''+sDate+''"
'');
end;
procedure TForm1.Printit;
begin with wkSheet.PageSetUp do begin PaperSize:=xlPaperA4;
//Paper type A4 PrintTitleRows := ''A1:D1'';
//Repeat this row/page LeftMargin:=18;
//0.25"
Left Margin RightMargin:=18;
//0.25"
will vary between printers TopMargin:=36;
//0.5"
BottomMargin:=36;
//0.5"
CenterHorizontally:=True;
Orientation:=1;
//横向打印(landscape)=2, portrait=1 end;
wkSheet.PrintOut(EmptyParam,EmptyParam,1, EmptyParam,EmptyParam,EmptyParam, EmptyParam,EmptyParam,LCID);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin try OpenExl;
Write2xls;
AddFormula;
Name