求助 ( 积分: 200 )

  • 主题发起人 主题发起人 wt741963
  • 开始时间 开始时间
W

wt741963

Unregistered / Unconfirmed
GUEST, unregistred user!
我想把从数据库读出的数据写入excel文件,我用excel作了一个模板,然后把这个模板
存成jsp文件,我在前面加了excel的文件头,但我发现这个模板无法接收从session
和request传来的参数,不知是什么原因,但我这个程序在webfirst上运行正常,到了
websphere上就出了这个问题。请高手赐教。
 
我想把从数据库读出的数据写入excel文件,我用excel作了一个模板,然后把这个模板
存成jsp文件,我在前面加了excel的文件头,但我发现这个模板无法接收从session
和request传来的参数,不知是什么原因,但我这个程序在webfirst上运行正常,到了
websphere上就出了这个问题。请高手赐教。
 
To wt741963,
我的QQ:82780254
procedure ExportExcel(Title: String;
Handle: Thandle;
Qry: TADOQuery;
DB: TDBGridEh;
Flag: Integer);
var
Excel: Variant;
WorkBook: OleVariant;
WorkSheet: OleVariant;
I, J: Integer;
begin
try
if Qry.RecordCount = 0 then
begin
MessageBox(Handle, Mess98002, MessTitleCHN,
MB_ICONINFORMATION + MB_OK);
Exit;
end;
Excel := CreateOleObject('Excel.Application');
Excel.Application.Workbooks.add;
Excel.Caption := Title;
Excel.Application.Visible := True;

WorkBook := Excel.Application.WorkBooks[1];
WorkSheet := WorkBook.WorkSheets.Item[1];
except
MessageBox(Handle, Mess98003, MessTitleCHN,
MB_ICONINFORMATION + MB_OK);
Exit;
end;

case Flag of
1:
begin
I := 1;
Qry.First;
for J := 0 to DB.FieldCount - 1do
begin
WorkSheet.Cells[1, J + 1].HorizontalAlignment := 3;
WorkSheet.Cells[1, J + 1] := DB.Fields[J].DisplayName;
end;
while not Qry.Eofdo
begin
Inc(I);
for J := 0 to DB.FieldCount - 1do
begin
if (J = 0) or (J = 1) then
WorkSheet.Cells[I, J + 1].HorizontalAlignment := 2
else
WorkSheet.Cells[I, J + 1].NumberFormat := '0.00';
WorkSheet.Cells[I, J + 1] := DB.Fields[J].AsString;
end;
Qry.Next;
end;
end;

2:
begin
I := 1;
Qry.First;
for J := 0 to DB.FieldCount - 1do
begin
WorkSheet.Cells[1, J + 1].HorizontalAlignment := 3;
WorkSheet.Cells[1, J + 1] := DB.Fields[J].DisplayName;
end;
while not Qry.Eofdo
begin

Inc(I);

for J := 0 to DB.FieldCount - 1do
begin
if (J = 0) or (J = 1) or (J = 8) then
WorkSheet.Cells[I, J + 1].HorizontalAlignment := 2
else
begin
WorkSheet.Cells[I, J + 1].NumberFormat := 'hh:mm';
with FlagColordo
begin
case Qry.FieldByName('Flag' + IntToFlag(J - 1)).AsInteger of
FlagHols:
WorkSheet.Cells[I, J + 1].Interior.Color := ColorHols;
FlagEvection:
WorkSheet.Cells[I, J + 1].Interior.Color := ColorEvection;
FlagOvertime:
WorkSheet.Cells[I, J + 1].Interior.Color := ColorOvertime;
FlagAbsent:
WorkSheet.Cells[I, J + 1].Interior.Color := ColorAbsent;
FlagLate:
WorkSheet.Cells[I, J + 1].Interior.Color := ColorLate;
FlagEarly:
WorkSheet.Cells[I, J + 1].Interior.Color := ColorEarly;
FlagForget:
WorkSheet.Cells[I, J + 1].Interior.Color := ColorForget;
end;
end;
end;
if J = 8 then
begin
if Qry.FieldByName('IsRest').AsBoolean = True then
WorkSheet.Cells[I, J + 1] := '√'
else
WorkSheet.Cells[I, J + 1] := 'X';
WorkSheet.Cells[I, J + 1].HorizontalAlignment := 3;
end
else
WorkSheet.Cells[I, J + 1] := DB.Fields[J].AsString;
end;
Qry.Next;
end;
end;

3:
begin
I := 1;
Qry.First;
for J := 0 to DB.FieldCount - 1do
begin
WorkSheet.Cells[1, J + 1].HorizontalAlignment := 3;
WorkSheet.Cells[1, J + 1] := DB.Fields[J].DisplayName;
end;
while not Qry.Eofdo
begin

Inc(I);

for J := 0 to DB.FieldCount - 1do
begin
if (J < 2) then
WorkSheet.Cells[I, J + 1].HorizontalAlignment := 2;
if (J > 1) and (J < 14) then
WorkSheet.Cells[I, J + 1].NumberFormat := '0.00';
WorkSheet.Cells[I, J + 1] := DB.Fields[J].AsString;
end;
Qry.Next;
end;
end;

4:
begin
I := 1;
Qry.First;
for J := 0 to DB.FieldCount - 1do
begin
WorkSheet.Cells[1, J + 1].HorizontalAlignment := 3;
WorkSheet.Cells[1, J + 1] := DB.Fields[J].DisplayName;
end;
while not Qry.Eofdo
begin
Inc(I);
for J := 0 to DB.FieldCount - 1do
begin
WorkSheet.Cells[I, J + 1].HorizontalAlignment := 2;
WorkSheet.Cells[I, J + 1] := DB.Fields[J].AsString;
end;
Qry.Next;
end;
end;

5:
begin
I := 1;
Qry.First;
for J := 0 to DB.FieldCount - 1do
begin
WorkSheet.Cells[1, J + 1].HorizontalAlignment := 3;
WorkSheet.Cells[1, J + 1] := DB.Fields[J].DisplayName;
end;
while not Qry.Eofdo
begin
Inc(I);
for J := 0 to DB.FieldCount - 1do
begin
if (J = 0) or (J = 8) then
WorkSheet.Cells[I, J + 1].HorizontalAlignment := 2;
WorkSheet.Cells[I, J + 1] := DB.Fields[J].AsString;
if J = 8 then
WorkSheet.Cells[I, J + 1].NumberFormat := '#';
if (J = 9) or (J = 10) then
WorkSheet.Cells[I, J + 1].NumberFormat := 'yyyy-mm-dd';
end;
Qry.Next;
end;
end;
end;
end;
 
检查一下是不是字符集的问题
 
后退
顶部