PDA

View Full Version : باز کردن یک فایل excel با کامپوننت server



shahabm58
سه شنبه 10 خرداد 1384, 09:49 صبح
سلام

javidtaheri
سه شنبه 10 خرداد 1384, 10:35 صبح
شما از ExcelExport استفاده کن عالیه جستجو کن پیداش میکنی

کسی کاربرد اجزاء پالت Server نمیدونه ? :گیج:
من ازhelp دلفی هم نتونستم بفهمم

Delphi-Clinic
سه شنبه 10 خرداد 1384, 10:58 صبح
procedure TTumOgr.SpeedButton1Click(Sender: TObject);
var XApp:Variant;
sheet:Variant;
r,c:Integer;
row,col:Integer;
filName:Integer;
q:Integer;
begin
XApp:=CreateOleObject('EXCEL.Application');
XApp.Visible:=true;
XApp.WorkBooks.Add(-4167);
XApp.WorkBooks[1].WorkSheets[1].Name:='Sheet1';
sheet:=XApp.WorkBooks[1].WorkSheets['Sheet1'];
for filName:=0 to DMod.OgrSiralaQuery.FieldCount-1 do
begin
q:=filName+1;
sheet.Cells[1,q]:=DMod.OgrSiralaQuery.Fields[filNa me].FieldName;
end;
for r:=0 to DMod.OgrSiralaQuery.RecordCount-1 do
begin
for c:=0 to DMod.OgrSiralaQuery.FieldCount-1 do
begin
row:=r+2;
col:=c+1;
sheet.Cells[row,col]:=DMod.OgrSiralaQuery.Fields[c ].AsString;
end;
DMod.OgrSiralaQuery.Next;
end;
XApp.WorkSheets['Sheet1'].Range['A1:AA1'].Font.Bol d:=True;
XApp.WorkSheets['Sheet1'].Range['A1:K1'].Borders.L ineStyle :=13;
XApp.WorkSheets['Sheet1'].Range['A2:K'+inttostr(DM od.OgrSiralaQuery.RecordCount-1)].Borders.LineStyle :=1;
XApp.WorkSheets['Sheet1'].Columns[1].ColumnWidth:= 16;
XApp.WorkSheets['Sheet1'].Columns[2].ColumnWidth:= 7;
XApp.WorkSheets['Sheet1'].Columns[3].ColumnWidth:= 19;
XApp.WorkSheets['Sheet1'].Columns[4].ColumnWidth:= 9;
XApp.WorkSheets['Sheet1'].Columns[5].ColumnWidth:= 9;
XApp.WorkSheets['Sheet1'].Columns[6].ColumnWidth:= 9;
XApp.WorkSheets['Sheet1'].Columns[7].ColumnWidth:= 46;
XApp.WorkSheets['Sheet1'].Columns[8].ColumnWidth:= 9;
XApp.WorkSheets['Sheet1'].Columns[9].ColumnWidth:= 7;
XApp.WorkSheets['Sheet1'].Columns[10].ColumnWidth: =6;
XApp.WorkSheets['Sheet1'].Columns[11].ColumnWidth: =13;

end;






procedure TForm1.BitBtnFromEXCELOnClick(Sender: TObject);
var
WorkBk : _WorkBook;
WorkSheet : _WorkSheet;
K, R, X, Y : Integer;
IIndex : OleVariant;
RangeMatrix : Variant;
NomFich : WideString;
begin
NomFich := ‘C:\MyDirectory\NameOfFile.xls’;
IIndex := 1;
XLApp.Connect;
// Open the EXCEL File
XLApp.WorkBooks.Open(NomFich,EmptyParam,EmptyParam ,EmptyParam,EmptyParam, EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyP aram,EmptyParam,
EmptyParam,EmptyParam,0);
WorkBk := XLApp.WorkBooks.Item[IIndex];
WorkSheet := WorkBk.WorkSheets.Get_Item(1) as _WorkSheet;
// In order to know the dimension of the WorkSheet, i.e the number of rows and the
// number of columns, we activate the last non-empty cell of it
WorkSheet.Cells.SpecialCells(xlCellTypeLastCell,Em ptyParam).Activate;
// Get the value of the last row
X := XLApp.ActiveCell.Row;
// Get the value of the last column
Y := XLApp.ActiveCell.Column;
// Define the number of the columns in the TStringGrid
GenericStringGrid.ColCount := Y;
// Assign the Variant associated with the WorkSheet to the Delphi Variant Matrix
RangeMatrix := XLApp.Range['A1',XLApp.Cells.Item[X,Y]].Value;
// Quit EXCEL and Disconnect the Server
XLApp.Quit;
XLApp.Disconnect;
// Define the loop for filling in the TStringGrid
K := 1;
repeat
for R := 1 to Y do
GenericStringGrid.Cells[(R - 1),(K - 1)] := RangeMatrix[K,R];
Inc(K,1);
GenericStringGrid.RowCount := K + 1;
until
K > X;
// Unassign the Delphi Variant Matrix
RangeMatrix := Unassigned;
end;

میتی دات نت
سه شنبه 10 خرداد 1384, 11:40 صبح
به نام خدا

ببین چطوره ؟ من قبلا یک بار استفاده کرده ام

به صورت درسی و آموزشی در 7 درس و 7 صفحه می باشد .

http://delphi.about.com/od/database/l/aa090903a.htm

:موفق:

میتی دات نت
سه شنبه 10 خرداد 1384, 11:43 صبح
به نام خدا

و یا این

:موفق: http://vzone.virgin.net/graham.marshall/excel.htm#excel.htm