哈哈,简单。有例程。
请参看ExpressQuantumGrid源代码:(我抄一段)
procedure TdxDBGridExportExcel.DoWriteHeader;
var
i, j, k: Integer;
S: string;
begin
with Grid do
begin
// Draw Bands
if ShowBands then
begin
for i := 0 to GroupColumnCount - 1 do
begin
XLSBlank[2] := TotalCount;
XLSBlank[3] := i;
Stream.WriteBuffer(XLSBlank, SizeOf(XLSBlank));
end;
for j := 0 to VisColCount - 1 do
begin
XLSBlank[2] := TotalCount;
XLSBlank[3] := j + GroupColumnCount;
Stream.WriteBuffer(XLSBlank, SizeOf(XLSBlank));
end;
k := 0;
for i := 0 to GetBandCount - 1 do
begin
S := GetBandText(i);
XLSLAbel[1] := Length(S) + 8;
XLSLabel[2] := TotalCount;
XLSLabel[3] := k + GroupColumnCount;
XLSLabel[4] := $1A;
XLSLabel[5] := Length(S);
Stream.WriteBuffer(XLSLabel, SizeOf(XLSLabel));
Stream.WriteBuffer(Pointer(S)^, Length(S));
for j := 0 to GetHeaderRowCount(i) - 1 do
k := k + GetHeaderColCount(i,j);
end;
Inc(TotalCount);
end;
// Draw Heders
if ShowHeader then
begin
for i := 0 to GroupColumnCount - 1 do
begin
XLSBlank[2] := TotalCount;
XLSBlank[3] := i;
Stream.WriteBuffer(XLSBlank, SizeOf(XLSBlank));
end;
for i := 0 to VisColCount - 1 do
begin
// S := GetHeaderText(VisColIndexes);
S := Columns[VisColIndexes].Caption;
XLSLAbel[1] := Length(S) + 8;
XLSLabel[2] := TotalCount;
XLSLabel[3] := i + GroupColumnCount;
XLSLabel[4] := $16;
XLSLabel[5] := Length(S);
Stream.WriteBuffer(XLSLabel, SizeOf(XLSLabel));
Stream.WriteBuffer(Pointer(S)^, Length(S));
end;
Inc(TotalCount);
end;
end;
end;