Delphi 

Excel Delphi


: webdelphi
Vlad 7
, , - . , - , - Excel. , " Excel Delphi. ." (- ) . , , ( ) Excel Delphi. ? - , .. Excel- , - . , Excel. , , Excel, , , . , - . . , - .

Excel - MSXML . , . . , - .


Excel

, Excel Delphi - . :

procedure TForm16.SlowVariant;
var Rows, Cols, i,j: integer;
WorkSheet: OLEVariant;
d: TDateTime;
begin
//
ExcelApp.Workbooks.Open(edFile.Text);
//
WorkSheet:=ExcelApp.ActiveWorkbook.ActiveSheet;
//
Rows:=WorkSheet.UsedRange.Rows.Count;
Cols:=WorkSheet.UsedRange.Columns.Count;

StringGrid1.RowCount:=Rows;
StringGrid1.ColCount:=Cols;

//
d:=Now;

//
for I := 0 to Rows-1 do
for j := 0 to Cols-1 do
StringGrid1.Cells[J,I]:=WorkSheet.UsedRange.Cells[I+1,J+1].Value;

Label2.Caption:=' : '+FormatDateTime('hh:mm:ss:zzz',
Now()-d);
end;


StringGrid . , . - - "" .

Excel, 143 142 , .. 20306 . :

12 ... 1000 1000 ? .

, , , , , . . , . .

, . . :

procedure TForm16.RangeRead;
var Rows, Cols, i,j: integer;
WorkSheet: OLEVariant;
FData: OLEVariant;
d: TDateTime;
begin
//
ExcelApp.Workbooks.Open(edFile.Text);
//
WorkSheet:=ExcelApp.ActiveWorkbook.ActiveSheet;
//
Rows:=WorkSheet.UsedRange.Rows.Count;
Cols:=WorkSheet.UsedRange.Columns.Count;

//
FData:=WorkSheet.UsedRange.Value;

StringGrid1.RowCount:=Rows;
StringGrid1.ColCount:=Cols;

//
d:=Now;

//
for I := 0 to Rows-1 do
for j := 0 to Cols-1 do
StringGrid1.Cells[J,I]:=FData[I+1,J+1];

Label2.Caption:=' : '+FormatDateTime('hh:mm:ss:zzz',
Now()-d);
end;


FData Variant. 1 , . FData , , Excel.

:

, , , StringGrid'.

Excel, .. Excel .
Excel

, Excel , .. , Excel. , StringGrid Excel:

procedure TForm16.WriteData;
var i,j: integer;
FData: Variant;
Sheet,Range: Variant;
begin
//
FData:=VarArrayCreate([1,StringGrid1.RowCount,1,StringGrid1.ColCount],varVariant);
// StringGrid
for i:=1 to VarArrayHighBound(FData,1) do
for j:=1 to VarArrayHighBound(FData,2) do
FData[i,j]:=StringGrid1.Cells[J-1,I-1];
{ }
//
ExcelApp.Workbooks.Open(edFile.Text);
//
Sheet:=ExcelApp.ActiveWorkBook.Sheets[2];
Sheet.Activate;
//
Range:=Sheet.Range[Sheet.Cells[1,1],Sheet.Cells[VarArrayHighBound(FData,1),VarArrayHighBound(FData,2)]];
//
Range.Value:=FData;
// Excel
ExcelApp.Visible:=True;
end;


, VarArrayCreate, Excel. , Excel - 2 :
,
.

, Excel :

, . , , , 1000 256 7 . , VarArrayLock() VarArrayUnLock(), , FData .

/ Excel? , Excel . Excel. , , , , - XLSReadWrite.

- "" Excel Delphi. ". , GS ( ) XLSReadWrite:

Delphi 7
var
IntlXls: TXLSReadWriteII2;
I, J: Integer;

begin
//
IntlXls := TXLSReadWriteII2.Create(nil);

//
IntlXls.Sheets[0].Name := " ";
//
IntlXls.Sheets[0].Rows.AddIfNone(0, 10000);
IntlXls.Sheets[0].Columns.AddIfNone(0, 100);

// ( )
for I := 0 to 99 do
IntlXls.Sheets[0].Columns[I].PixelWidth := 150;
// ( , )
for I := 0 to 9999 do
IntlXls.Sheets[0].Rows[I].Height := 20 * 14;

//
for J := 0 to 9999 do
for I := 0 to 99 do
begin
//
// , AsString
IntlXls.Sheets[0].AsFloat[I, J] := J + I / 100;

// ( chaLeft, chaCenter, chaRight)
IntlXls.Sheets[0].Cell[I, J].HorizAlignment := chaLeft;

// ( cvaTop, cvaCenter, cvaBottom)
IntlXls.Sheets[0].Cell[I, J].VertAlignment := cvaTop;

//
IntlXls.Sheets[0].Cell[I, J].FontName := " Arial ";
IntlXls.Sheets[0].Cell[I, J].FontSize := 12;
IntlXls.Sheets[0].Cell[I, J].FontStyle := [];
IntlXls.Sheets[0].Cell[I, J].FontColor := TColorToClosestXColor(clBlue);
IntlXls.Sheets[0].Cell[I, J].Rotation := 0;
//
with IntlXls.Sheets[0].Cell[I, J] do
FontStyle := FontStyle + [xfsBold];
//
with IntlXls.Sheets[0].Cell[I, J] do
FontStyle := FontStyle + [xfsItalic];
//
IntlXls.Sheets[0].Cell[I, J].FillPatternForeColor :=
TColorToClosestXColor(clYellow);

// ( )
IntlXls.Sheets[0].Cell[I, J].BorderLeftColor :=
TColorToClosestXColor(clBlack);
IntlXls.Sheets[0].Cell[I, J].BorderLeftStyle := cbsThin;

// ( )
if I = 49 then
IntlXls.Sheets[0].MergedCells.Add(I, J, I + 1, J);
end;

IntlXls.SaveToFile(" c: \ demo.xls ");
IntlXls.Free;
end;


:

function ExportToExcelXls(var AFileName: string): Integer;
var
IntlXls: TXLSReadWriteII2;
IntlCol: Integer;
IntlRow: Integer;
IntlMainCol: Integer;
IntlMainRow: Integer;
begin
//
prgrbrStatus.Max := FLinkReport.RowCount;
prgrbrStatus.Position := 0;
pnlStatus.Visible := TRUE;
pnlStatus.Refresh;
// ".XLS"?
if Length(AFileName) < 5 then
//
AFileName := AFileName + ".xls "
else if AnsiCompareText(Copy(AFileName, Length(AFileName)- 3, 4), ".xls ") <> 0
then
//
AFileName := AFileName + ".xls ";
// ?
if FileExists(AFileName) then
//
if Application.MessageBox
(PChar(" " " + AFileName + " " . ? "),
" ", MB_TASKMODAL + MB_ICONQUESTION + MB_YESNO + MB_DEFBUTTON2)
<> IDYES then
//
begin
//
Result := UNIRPT_GENERATE_ABORT;

//
Exit;
end; // if
//
IntlXls := TXLSReadWriteII2.Create(nil);
//
try
//
IntlXls.Sheets[0].Name := FLinkReport.Caption;
//
IntlXls.Sheets[0].Rows.AddIfNone(0, FLinkReport.Cells.RowCount + 1);
IntlXls.Sheets[0].Columns.AddIfNone(0, FLinkReport.Cells.ColCount + 1);
//
for IntlCol := 0 to FLinkReport.Cells.ColCount - 1 do
IntlXls.Sheets[0].Columns[IntlCol].PixelWidth :=
FLinkReport.ColWidths[IntlCol];
//
for IntlRow := 0 to FLinkReport.Cells.RowCount - 1 do
IntlXls.Sheets[0].Rows[IntlRow].Height := FLinkReport.RowHeights
[IntlRow] * 14;
//
for IntlRow := 0 to FLinkReport.Cells.RowCount - 1 do
begin
//
for IntlCol := 0 to FLinkReport.Cells.ColCount - 1 do
begin
//
IntlMainCol := IntlCol + FLinkReport.Cells[IntlCol, IntlRow].Range.Left;
IntlMainRow := IntlRow + FLinkReport.Cells[IntlCol, IntlRow].Range.Top;
//
with FLinkReport.Cells[IntlMainCol, IntlMainRow] do
begin
// ?
if (IntlMainCol = IntlCol) and (IntlMainRow = IntlRow) then
// ,
begin
//
try
// -
IntlXls.Sheets[0].AsFloat[IntlCol, IntlRow] := StrToFloat(Value);
except
//
IntlXls.Sheets[0].AsString[IntlCol, IntlRow] := Value;
end;

//
case HorizAlign of
haLeft:
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].HorizAlignment
:= chaLeft;
haCenter:
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].HorizAlignment :=
chaCenter;
haRight:
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].HorizAlignment
:= chaRight;
end; // case
//
case VertAlign of
vaTop:
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].VertAlignment
:= cvaTop;
vaCenter:
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].VertAlignment :=
cvaCenter;
vaBottom:
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].VertAlignment :=
cvaBottom;
end; // case
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].FontName := Font.Name;
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].FontSize := Font.Size;
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].FontCharset :=
Font.Charset;
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].FontStyle := [];
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].FontColor :=
TColorToClosestXColor(Font.Color);
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].Rotation := Font.Angle;
// ?
if Font.IsBold then
//
with IntlXls.Sheets[0].Cell[IntlCol, IntlRow] do
FontStyle := FontStyle + [xfsBold];
// ?
if Font.IsItalic then
//
with IntlXls.Sheets[0].Cell[IntlCol, IntlRow] do
FontStyle := FontStyle + [xfsItalic];
//
if Color <> clWindow then
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].FillPatternForeColor :=
TColorToClosestXColor(Color);
end // if
else
// ( )
IntlXls.Sheets[0].AsString[IntlCol, IntlRow] := ";

// ?
with Borders.Left do
if LineHeight > 0 then
//
begin
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderLeftColor :=
TColorToClosestXColor(Color);
//
if LineHeight = 1 then
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderLeftStyle
:= cbsThin
else if LineHeight in [1, 2] then
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderLeftStyle :=
cbsMedium
else
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderLeftStyle
:= cbsHair;
end; // if, with
// ?
with Borders.Top do
if LineHeight > 0 then
//
begin
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderTopColor :=
TColorToClosestXColor(Color);
//
if LineHeight = 1 then
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderTopStyle
:= cbsThin
else if LineHeight in [1, 2] then
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderTopStyle :=
cbsMedium
else
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderTopStyle
:= cbsHair;
end; // if, with
// ?
with Borders.Right do
if LineHeight > 0 then
//
begin
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderRightColor :=
TColorToClosestXColor(Color);
//
if LineHeight = 1 then
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderRightStyle
:= cbsThin
else if LineHeight in [1, 2] then
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderRightStyle :=
cbsMedium
else
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderRightStyle
:= cbsHair;
end; // if, with
// ?
with Borders.Bottom do
if LineHeight > 0 then
//
begin
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderBottomColor :=
TColorToClosestXColor(Color);
//
if LineHeight = 1 then
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderBottomStyle
:= cbsThin
else if LineHeight in [1, 2] then
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderBottomStyle :=
cbsMedium
else
//
IntlXls.Sheets[0].Cell[IntlCol, IntlRow].BorderBottomStyle
:= cbsHair;
end; // if, with
// ?
if ((Range.Width > 1) or (Range.Height > 1)) and
((IntlMainCol = IntlCol) and (IntlMainRow = IntlRow)) then
//
IntlXls.Sheets[0].MergedCells.Add(IntlCol, IntlRow,
IntlCol + Range.Width - 1, IntlRow + Range.Height - 1);
// ?
if btnCancel.Tag = 2 then
// ,
Break;
end; // with
end; // for
//
prgrbrStatus.Position := prgrbrStatus.Position + 1;
Application.ProcessMessages;
// ?
if btnCancel.Tag = 2 then
// ,
Break;
end; // for
// ?
if btnCancel.Tag <> 2 then
//
begin
//
IntlXls.Sheet[0].TopRow := 0;
IntlXls.Sheet[0].LeftCol := 0;
IntlXls.Sheet[0].Selection.ActiveRow := 0;
IntlXls.Sheet[0].Selection.ActiveCol := 0;

//
prgrbrStatus.Position := prgrbrStatus.Max;
Application.ProcessMessages;
//
IntlXls.FileName := AFileName;
IntlXls.Write;
//
Result := UNIRPT_OK;

end // if
else
//
Result := UNIRPT_GENERATE_ABORT;

finally
//
IntlXls.Free;
end; // try..finally
end; // function ExportToExcelXls


GS . . , , Excel Excel . , Excel ADO, Range CopyFromRecordset, Excel , Excel'. - . , , - .



 

 Borland CodeGear Delphi for PHP, -.
  VBA- Delphi ().
  "". " " .


 Delphi 

2018 Team.Furia.Ru.
.