//转换成Excel文档
//muhx 20040423 night
procedure TMainFrm.ChangeToExcel(TmpCelInfo: TCellInfo; aFileName: string);
var
strSaveFileName: string;
newExcel: Variant;
i: Integer;
begin
strSaveFileName := aFileName;
try
NewExcel := CreateOleObject('Excel.Application');
newExcel.Visible := False;
except
MessageDlg('启动Excel失败!', mtError, [mbOk], 0);
NewExcel.Quit;
NewExcel := Unassigned;
Exit;
end;
try
try
newExcel.DisplayAlerts := False;
newExcel.Caption := 'LIR256B01内阻测试仪测试数据';
newExcel.WorkBooks.Add;
newExcel.ActiveSheet.Name := '内阻测试数据';
//设置列宽
newExcel.ActiveSheet.Columns[1].ColumnWidth := 7;
newExcel.ActiveSheet.Columns[2].ColumnWidth := 5;
newExcel.ActiveSheet.Columns[3].ColumnWidth := 5;
newExcel.ActiveSheet.Columns[4].ColumnWidth := 11;
newExcel.ActiveSheet.Columns[5].ColumnWidth := 9;
newExcel.ActiveSheet.Columns[6].ColumnWidth := 9;
newExcel.ActiveSheet.Columns[7].ColumnWidth := 9;
newExcel.ActiveSheet.Columns[8].ColumnWidth := 10;
newExcel.ActiveSheet.Columns[9].ColumnWidth := 10;
newExcel.ActiveSheet.Columns[10].ColumnWidth := 16;
//newExcel.ActiveSheet.PageSetup.CenterVertically := 2/0.035;
//添加表头 20040310 muhx
newExcel.Cells[1,5].Value := '内阻测试数据';
newExcel.ActiveSheet.Range['A1:J1'].Borders[3].Weight := 3;
newExcel.ActiveSheet.Range['A1:J1'].Borders[4].Weight := 3;
newExcel.ActiveSheet.Rows[1].Font.Bold := True;
newExcel.Cells[2,1].Value := '通道号';
newExcel.Cells[2,2].Value := '区号';
newExcel.Cells[2,3].Value := '板号';
newExcel.Cells[2,4].Value := '板上电池号';
newExcel.Cells[2,5].Value := '电池编号';
newExcel.Cells[2,6].Value := '通道选择';
newExcel.Cells[2,7].Value := '分选结果';
newExcel.Cells[2,8].Value := '电压(mV)';
newExcel.Cells[2,9].Value := '内阻(mΩ)';
newExcel.Cells[2,10].Value := '检测时间';
newExcel.ActiveSheet.Range['A2:J2'].Borders[4].Weight := 3;
//向Excel工作表中添加内容
for i := 0 to CellNo - 1 do
begin
ShowWait(CellNo - 1, 0, i, '当前进度:');
newExcel.Cells[i + 3, 1].Value := IntToStr(TmpCelInfo.iCellID);
newExcel.Cells[i + 3, 2].Value := IntToStr(TmpCelInfo.iZoneID);
newExcel.Cells[i + 3, 3].Value := IntToStr(TmpCelInfo.iBoardID);
newExcel.Cells[i + 3, 4].Value := IntToStr(TmpCelInfo.iCellNoInBoard);
newExcel.Cells[i + 3, 5].Value := TmpCelInfo.sCellName;
newExcel.Cells[i + 3, 6].Value := BoolToStr(TmpCelInfo.bCellSelected,True);
newExcel.Cells[i + 3, 7].Value := TmpCelInfo.sSortResult;
newExcel.Cells[i + 3, 8].Value := FormatFloat('0', TmpCelInfo.rVoltage);
newExcel.Cells[i + 3, 9].Value := FormatFloat('0.0', TmpCelInfo.rResistance);
newExcel.Cells[i + 3, 10].Value := DateTimeToStr(TmpCelInfo.tTestTime);
end;
//保存
if not newExcel.ActiveWorkBook.Saved then
newExcel.ActiveWorkBook.SaveAs(strSaveFileName);
FreeWait; //若进度条没有释放则释放进度条
sleep(20);
ShowStatusInfo('转换Excel文档完毕');
Application.MessageBox('转换数据完毕。', '提示',
MB_OK or MB_ICONINFORMATION);
except
Application.MessageBox('转换成Excel格式失败!', 'LIR256B01电池内阻测试仪',
MB_OK or MB_ICONWARNING);
end;
finally
newExcel.WorkBooks.Close;
newExcel.Quit;
newExcel := unassigned;
end;
end;
//--------------------在StatusBar中显示ProgressBar--------------------//
//取得StatusBar的Rect
procedure TMainFrm.StatusBarDrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
begin
fStatusDrawRect := Rect;
end;
//显示进度条
//muhx 20040418 am
procedure TMainFrm.ShowWait(aMax, aMin, aPos: integer; S: string);
begin
if not Assigned(fProgress) then //Assigned returns False if P is nil, True otherwise.
begin
try
fProgress := TProgressBar.Create(MainFrm);
fPanelWidth := StatusBar.Panels.Items[2].Width;
StatusBar.Panels.Items[2].Width := 250;
StatusBar.Repaint;
Application.ProcessMessages;
with fProgress do
begin
Parent := StatusBar;
Top := fStatusDrawRect.Top;
Left := fStatusDrawRect.Left;
Width := fStatusDrawRect.Right - fStatusDrawRect.Left;
Height := fStatusDrawRect.Bottom - fStatusDrawRect.Top;
min := aMin;
max := aMax;
Visible := True;
end;
except
fProgress.Free;
fProgress := nil;
end;
end;
try
with fProgress do
begin
if aPos < Max then
begin
Visible := True;
Position := aPos;
StatusBar.Panels.Items[1].Text := s;
StatusBar.Repaint;
Application.ProcessMessages;
end
else
begin
StatusBar.Panels.Items[2].Width := fPanelWidth;
Free;
fProgress := nil;
end;
end;
except
fProgress.Free;
fProgress := nil;
end;
end;
//释放进度条
//muhx 20040418 am
procedure TMainFrm.FreeWait;
begin
if Assigned(fProgress) then
fProgress := nil;
end;