Home > Back-end >  In the case of only equipped with WPS, how delphi6.0. XLS file import function
In the case of only equipped with WPS, how delphi6.0. XLS file import function

Time:10-13

You consult greatly, in the case of only equipped with WPS, how delphi6.0. XLS file import function? Thank you for the

CodePudding user response:

Can use ADO connection is opened,

CodePudding user response:

WPS is actually can compatible with word, can be operated by oleVariant. XSL and almost word, and the Internet to find relevant examples and API

CodePudding user response:

Equipped with office machines can be quoted before Excel2000. Pas

CodePudding user response:

reference jim80s reply: 3/f
before equipped with office machines can be reference Excel2000. The pas


Installed WPS also have corresponding pas unit, and Excel2000. Pas definition is some variables, control word development manual, the examples are VBA code

WPS and office API is actually about the same, just the variable name is different, begin with wd in the office, WPS will begin with the WPS, but the value of the point to actually is still the same

CodePudding user response:

The unit UExcelOperator;

Interface

USES the
Windows, DB, Classes, SysUtils, Dialogs;

Type

TExcelCls=class (TOBject)

Private
{Private declarations}
Public
{Public declarations}
Procedure SaveDataToExcel (aDataSet: TDataSet);
The end;

Var
ArXlsBegin: array [0.. 5] of Word=($809, 8, 0, $10, 0, 0).
ArXlsEnd: array [0.. 1] of Word=($0. A, 00);
ArXlsString: array [0.. 5] of Word=($204, 0, 0, 0, 0, 0).
ArXlsNumber: array [0.. 4] of Word=($203, 14, 0, 0, 0).
ArXlsInteger: array [0.. 4] of Word=($27 e, 10, 0, 0, 0).
ArXlsBlank: array [0.. 4] of Word=($201, 6, 0, 0, $17);

Implementation

Procedure ExportExcelFile (FileName: string; BWriteTitle: Boolean; ADataSet: TDataSet);
Var
I: integer;
Col, row: word;
ABookMark: TBookMark;
AFileStream: TFileStream;
Procedure incColRow;//add ranks number
The begin
Then the if Col=ADataSet. FieldCount - 1
The begin
Inc (Row);
Col:=0;
End
The else
Inc (Col);
The end;

Procedure WriteStringCell (AValue: string);//write string data
Var
L: Word;
The begin
L:=Length (AValue);
ArXlsString [1] :=8 + L;
ArXlsString [2] :=Row;
ArXlsString [3] :=Col;
ArXlsString [5] :=L;
AFileStream. WriteBuffer (arXlsString, SizeOf (arXlsString));
AFileStream. WriteBuffer (Pointer (AValue) ^, L);
IncColRow;
The end;

Procedure WriteIntegerCell (AValue: integer);//write integer
Var
V: Integer;
The begin
ArXlsInteger [2] :=Row;
ArXlsInteger [3] :=Col;
AFileStream. WriteBuffer (arXlsInteger, SizeOf (arXlsInteger));
V:=(AValue SHL 2) or 2;
AFileStream. WriteBuffer (V, 4);
IncColRow;
The end;

Procedure WriteFloatCell (AValue: double);//write floating-point
The begin
ArXlsNumber [2] :=Row;
ArXlsNumber [3] :=Col;
AFileStream. WriteBuffer (arXlsNumber, SizeOf (arXlsNumber));
AFileStream. WriteBuffer (AValue, 8);
IncColRow;
The end;

The begin
//I:=0;
If FileExists (FileName) then
The DeleteFile (FileName);//file exists, first remove
AFileStream:=TFileStream. Create (FileName, fmCreate);
Try//write file header
AFileStream. WriteBuffer (arXlsBegin, SizeOf (arXlsBegin));//write column head
Col:=0;
Row:=0;
If bWriteTitle then
The begin
For I:=0 to aDataSet. Do FieldCount - 1
WriteStringCell (aDataSet Fields [I] FieldName);
The end;//write data centralized data
ADataSet. DisableControls;
ABookMark:=aDataSet. GetBookmark;
ADataSet. First;

While not aDataSet. Eof do
The begin
For I:=0 to aDataSet. Do FieldCount - 1
Case ADataSet. Fields [I]. The DataType of the
FtSmallint, ftInteger, ftWord ftAutoInc, ftBytes:
WriteIntegerCell (aDataSet Fields [I] AsInteger);
FtFloat ftCurrency, ftBCD:
WriteFloatCell (aDataSet Fields [I] AsFloat)
The else
WriteStringCell (aDataSet Fields [I] AsString) are identical.
The end;
ADataSet. Next;
The end;
//write end-of-file
AFileStream. WriteBuffer (arXlsEnd, SizeOf (arXlsEnd));
If ADataSet. BookmarkValid (ABookMark) then
ADataSet. GotoBookmark (ABookMark);
The finally
AFileStream. Free;
ADataSet. EnableControls;
The end;
The end;

Procedure TExcelCls. SaveDataToExcel (aDataSet: TDataSet);
Var
StrSaveFile: string;
SaveDialog: TSaveDialog;
The begin
Try
SaveDialog:=TSaveDialog. Create (nil);
SaveDialog. Filter:='Microsoft Excel file | *. XLS';
SaveDialog. FileName:='query results. XLS';
SaveDialog. Options:=[ofOverwritePrompt, ofHideReadOnly ofEnableSizing];

If SaveDialog. Execute then
The begin
StrSaveFile:=SaveDialog. FileName;
ExportExcelFile (StrSaveFile, true, aDataSet);
The end;
SaveDialog. Free;
The finally


The end;
The end;

End.

CodePudding user response:

NativeExcel3

CodePudding user response:

Still don't understand, can ask xsl510079027 demonstrate relevant API information? Thank you very much

CodePudding user response:

ExcelApp:=TExcelApplication. Create (nil);
ExcelWorkbook:=TExcelWorkbook. Create (nil);
ExcelWorksheet:=TExcelWorksheet. Create (nil);

ExcelApp. Connect;
ExcelApp. Visible [0] :=False; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related