; g_xlswriterisruning := false;
end;
(*
procedure stringgridtoxls(grid:tstringgrid;fname:string);
var c,r,rmax:integer;
xls:txlswriter;
begin
xls:=txlswriter.create(fname);
rmax:=grid.rowcount;
if grid.colcount > xls.maxcols then
xls.maxcols:=grid.colcount+1;
if rmax > xls.maxrows then // ¦¹®æ¦¡³ì¦h¥u¯à¦s 65535 rows
rmax:=xls.maxrows;
try
xls.writebof;
xls.writedimension;
for c:=0 to grid.colcount-1 do
for r:=0 to rmax-1 do
xls.cellstr(r,c,grid.cells[c,r]);
xls.writeeof;
finally
xls.free;
end;
end;
*)
{ txlswriter }
constructor txlswriter.create(vfilename:string;const vmaxcols, vmaxrows:integer);
begin
inherited create;
if fileexists(vfilename) then
fstream:=tfilestream.create(vfilename,fmopenwrite)
else
fstream:=tfilestream.create(vfilename,fmcreate);
if vmaxcols<100 then maxcols := vmaxcols //modify by 角落的青苔@2005/05/19
else maxcols := 100;
if vmaxcols<65535 then maxrows := vmaxrows
else maxrows := 65535;
//maxcols:=100; // <2002-11-17> dllee column ೸ó¬o¤£¥i¯à¤j©ó 65535, ©ò¥h¤£¦a³b²z
//maxrows:=65530;//65535; // <2002-11-17> dllee ³o­ó®æ¦¡³ì¤j¥u¯à³o»ò¤j¡a½ðª`·n¤jªº¸ê®æ®w«ü®e©ö´n¤j©ó³o­ó­è
end;
destructor txlswriter.destroy;
begin
if fstream <> nil then
fstream.free;
inherited;
end;
procedure streamwritewordarray(stream: tstream; wr: array of word);
var
i: integer;
begin
for i := 0 to length(wr)-1 do
{$ifdef cil}
stream.write(wr[i]);
{$else}
stream.write(wr[i], sizeof(wr[i]));
{$endif}
end;
procedure streamwriteansistring(stream: tstream; s: string);
{$ifdef cil}
var
b: tbytes;
{$endif}
begin
{$ifdef cil}
b := bytesof(ansistring(s));
stream.write(b, length(b));
{$else}
stream.write(pchar(s)^, length(s));
{$endif}
end;
procedure txlswriter.writebof;
begin
writeword(bof_biff5);
writeword(6); // count of bytes
writeword(0);
writeword(doctype_xls);
writeword(0);
end;
procedure txlswriter.writedimension;
begin
writeword(dimensions); // dimension op code
writeword(8); // count of bytes
writeword(0); // min cols
writeword(maxrows); // max rows
writeword(0); // min rowss
writeword(maxcols); // max cols
end;
procedure txlswriter.celldouble(vrow, vcol: word; avalue: double;
vatribut: tsetofatribut);
//var fatribut:array [0..2] of byte;
begin
cxlsnumber[2] := vrow;
cxlsnumber[3] := vcol;
streamwritewordarray(fstream, cxlsnumber);
//setcellatribut(vatribut,fatribut);
//fstream.write(fatribut,3);
fstream.writebuffer(avalue, 8);
end;
procedure txlswriter.cellinteger(vrow,vcol:word;avalue:integer;vatribut:tsetofatribut=[]);
var v:integer;
begin
cxlsrk[2] := vrow;
cxlsrk[3] := vcol;
streamwritewordarray(fstream, cxlsrk);
v := (avalue shl 2) or 2;
fstream.writebuffer(v, 4);
end;