Unit opexcell;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, xlsreadwriteii2, qfilectrls, olectrls, DB, ADODB, cellformats2,
Xlsfonts2, biffrecsii2, rows2;
Type
Tstringarray = array of string;
Topexcell = Class (tobject)
Public
Function readxlⅱ (VAR content: tstringarray; filename: string): bool; // read an Excel table
Function writexlⅱ (VAR content: tstringarray; filename: string): bool; // write an Excel table
End;
Implementation
Function topexcell. readxlⅱ (VAR content: tstringarray; filename: string): bool;
VaR
IR, IC, I, j: integer;
XLS: txlsreadwriteii2;
Begin
Result: = true;
XLS: = txlsreadwriteii2.create (NiL );
XLS. filename: = filename;
XLS. read;
// Get the row and column
IR: = XLS. Sheets [0]. lastrow;
IC: = XLS. Sheets [0]. lastcol;
Try
Setlength (content, IR + 1, IC + 1 );
For I: = 0 to IR do
Begin
For J: = 0 to IC do
Begin
Content [I, j]: = XLS. Sheets [0]. asstring [J, I];
End;
End;
Except
Result: = false;
End;
If assigned (xls) then
Begin
XLS. Destroy;
End;
End;
Function topexcell. writexlⅱ (VAR content: tstringarray; filename: string): bool;
VaR
IR, IC, I, j: integer;
XLS: txlsreadwriteii2;
Begin
XLS: = txlsreadwriteii2.create (NiL );
XLS. filename: = filename;
Try
Try
IR: = length (content );
IC: = length (content [0]);
For I: = 0 to IR-1 do
Begin
For J: = 0 to IC-1 do
Begin
XLS. Sheets [0]. asstring [J, I]: = content [I, j];
End;
End;
XLS. Write;
Result: = true;
Except
Result: = false;
End;
Finally
XLS. Destroy;
End
End;
End.
Txlsreadwriteii read and write Excel