unit metrologiya;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, ExtCtrls, ComObj, OleServer, ExcelXP;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Label2: TLabel;
GroupBox1: TGroupBox;
Bevel1: TBevel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
with StringGrid1 do begin
FixedCols:=1;FixedRows:=0;
//ColCount:=5;
Cells[0,0]:='125';
Cells[0,1]:='625';
Cells[0,2]:='1250';
Cells[0,3]:='1875';
Cells[0,4]:='2375';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Form1: TForm1;
SG1 : Array[1..6,1..6] Of real;
SG2 : Array[1..5] Of real;
i, j: integer;
s:real;
const
Pgsk=2500; //шкала по давлению газа перед стопорным клапаном
begin
For i:=1 To 6 Do
For j:=1 To 6 Do
If (StringGrid1.Cells[j-1,i-1]='') Then
SG1[j,i] := 0
Else //StringGrid1.Cells[j-1+StringGrid1.FixedRows,i-1+StringGrid1.FixedCols]
SG1[j,i] := StrToFloat(StringGrid1.Cells[j-1,i-1]);
//SG1[i,j] := StrToFloat(StringGrid1.Cells[j-1,i-1]);
For i:=1 To 5 Do
Begin
S:=0;
for j:=2 to 6 do begin
S:=s+SG1[j,i];
End;
SG2[i]:=((S/5)-StrToFloat(StringGrid1.Cells[0,i-1]))/2500*100; вот это выражение
передается в эксель, мне нужно чтобы еще передавалось результат выражения S/5
End;
For i:=1 To 5 Do
StringGrid2.Cells[0,i-1] := FloatToStr(SG2[i])
end;
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
#8,'0'..'9' : ; // цифры и <Back Space>
#13: // клавиша <Enter>
if StringGrid1.Col < StringGrid1.ColCount - 1
then StringGrid1.Col := StringGrid1.Col + 1;
'.',',': // разделитель целой и дробной частей числа
begin
if Key <> DecimalSeparator then
Key := DecimalSeparator; // заменим разделитель на допустимый
if Pos(StringGrid1.Cells[StringGrid1.Col,0],DecimalSeparator) <> 0
then Key := Chr(0); // запрет ввода второго разделителя
end;
'-': // минус можно ввести только первым символом,
// т.е. когда ячейка пустая
if Length(StringGrid1.Cells[StringGrid1.Col,0]) <> 0
then Key := Chr(0);
else // остальные символы запрещены
key := Chr(0);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
Var
ExcelApp,
ExcelSheet,
ExcelCol,
ExcelRow,
Excel: Variant;
Size: real;
i, j, N, M: Word;
begin
// Запускаю приложение Excel
ExcelApp:=CreateOleObject('Excel.Application');
ExcelApp.Visible:=True;
// Создаю рабочую книгу
ExcelApp.Workbooks.Add(-4167);
ExcelApp.Workbooks[1].WorkSheets[1].Name:='Отчёт';
ExcelCol:=ExcelApp.Workbooks[1].WorkSheets['Отчёт'].Columns;
// Size:=8.43; // Ширина ячейки StringGrid1.DefaultRowHeight
ExcelApp.Columns.Columns[1].ColumnWidth:=5;
ExcelApp.Columns.Columns[2].ColumnWidth:=18;
ExcelApp.Columns.Columns[3].ColumnWidth:=9;
ExcelApp.Columns.Columns[4].ColumnWidth:=12;
ExcelApp.Columns.Columns[5].ColumnWidth:=11;
ExcelApp.Columns.Columns[6].ColumnWidth:=13;
ExcelApp.Columns.Columns[7].ColumnWidth:=13;
ExcelApp.Columns.Columns[8].ColumnWidth:=13;
N:=StringGrid1.ColCount-1; // Число ячеек в строке
//Если StringGrid содержит переменное число строк, то пользуемся циклом:
// For j:=0 To N Do
// ExcelCol.Columns[j+1].ColumnWidth:=Size;
ExcelRow:=ExcelApp.Workbooks[1].WorkSheets['Отчёт'].Rows;
ExcelRow.Rows[1].Font.Bold:=True; // Заголовки столбцов - жирные
// Ввод данных в лист Excel из StringGrid
ExcelSheet:=ExcelApp.Workbooks[1].WorkSheets['Отчёт'];
For i:=0 To StringGrid2.RowCount-1 Do
For j:=0 To StringGrid2.ColCount-1 Do
ExcelSheet.Cells[i+17,j+8]:=StringGrid2.Cells[j, i]; //вот тут и проблемка
//построение шаблона таблицы
ExcelApp.Range['A1:H1'].Merge;
ExcelSheet.Cells[1,1].HorizontalAlignment := 3;
ExcelSheet.Cells[1,1].Value:='ПРОТОКОЛ №';
ExcelSheet.Cells[2,1].Value:='';
ExcelSheet.Cells[3,1].Value:='Проверка измерительный каналов САУ ГТГ';
ExcelSheet.Cells[4,1].Value:='';
ExcelSheet.Cells[5,1].Value:='';
ExcelSheet.Cells[6,1].Value:='';
ExcelSheet.Cells[7,1].Value:='Условия проведения проверки:';
ExcelSheet.Cells[8,1].Value:='Температура окружающего воздуха 24,0 С';
// ExcelSheet.Cells[8,1].Value:='';
ExcelSheet.Cells[9,1].Value:='Давление 104,3 кПа';
// ExcelSheet.Cells[10,1].Value:='';
ExcelSheet.Cells[10,1].Value:='Относительная влажность 31%';
// ExcelSheet.Cells[12,1].Value:='';
ExcelSheet.Cells[11,1].Value:='Напряжение питания 220В';
ExcelSheet.Cells[12,1].Value:='Эталоны: многофукциональный калибратор МС5-R-IS №20106573';
ExcelSheet.Cells[13,1].Value:='ПКА ТКМ №24286, МЦП-2М №02066784';
ExcelSheet.Cells[14,1].Value:='';
ExcelApp.Range[ExcelApp.Cells[15,1], ExcelApp.Cells[15,6]].Select;
ExcelApp.Selection.HorizontalAlignment:=3;
ExcelApp.Selection.WrapText:=true;
ExcelApp.Selection.VerticalAlignment:=2;
ExcelApp.Selection.Borders.LineStyle:=1;
ExcelApp.Range['A15:A16'].Merge;
ExcelSheet.Cells[15,1].Value:='№ п/п';
ExcelApp.Range['B15:B16'].Merge;
ExcelSheet.Cells[15,2].Value:='Наименование измеряемого параметра';
ExcelApp.Range['C15:C16'].Merge;
ExcelSheet.Cells[15,3].Value:='Адрес';
ExcelApp.Range['D15:D16'].Merge;
ExcelSheet.Cells[15,4].Value:='Расчетное значение контролируемого параметра';
ExcelApp.Range['E15:E16'].Merge;
ExcelSheet.Cells[15,5].Value:='Значение входного сигнала';
ExcelApp.Range['F15:F16'].Merge;
ExcelSheet.Cells[15,6].Value:='Измеренное значение контролируемого параметра';
ExcelApp.Range['G15:H15'].Merge;
ExcelSheet.Cells[15,7].Value:='Погрешность ЭТ ИК';
ExcelSheet.Cells[16,7].Value:='Допустимая';
ExcelSheet.Cells[16,8].Value:='Фактическая';
// ExcelApp.Range[ExcelApp.Cells[15,7], ExcelApp.Cells[15,8]].Select;
// ExcelApp.Selection.MergeCells:=true;
end;
end.