unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ComObj, Vcl.StdCtrls, Vcl.Grids,Math;
type
TForm1 = class(TForm)
ButtonLaunch: TButton;
ButtonClose: TButton;
OpenDialog1: TOpenDialog;
ButtonOpen: TButton;
EditA11: TEdit;
EditA21: TEdit;
EditA31: TEdit;
EditA12: TEdit;
EditA22: TEdit;
EditA32: TEdit;
EditA13: TEdit;
EditA23: TEdit;
EditA33: TEdit;
EditB1: TEdit;
EditB2: TEdit;
EditB3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
ButtonSolve: TButton;
StringGrid1: TStringGrid;
ButtonFill: TButton;
Button1: TButton;
procedure ButtonLaunchClick(Sender: TObject);
procedure ButtonCloseClick(Sender: TObject);
procedure ButtonOpenClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ButtonFillClick(Sender: TObject);
procedure ButtonSolveClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
Exc:Variant;
n: boolean ;
{$R *.dfm}
procedure TForm1.ButtonFillClick(Sender: TObject);
begin
ButtonLaunch.Click;
//clear;
Randomize;
Exc.Range['A1']:=IntToStr(Random(10));
Exc.Range['A2']:=IntToStr (Random(10));
Exc.Range['A1:A2'].AutoFill(Exc.Range['A1:A12'],2);
EditA11.Text:=Exc.Range['A1'];
EditA21.Text:=Exc.Range['A2'];
EditA31.Text:=Exc.Range['A3'];
EditA12.Text:=Exc.Range['A4'];
EditA22.Text:=Exc.Range['A5'];
EditA23.Text:=Exc.Range['A6'];
EditA13.Text:=Exc.Range['A7'];
EditA32.Text:=Exc.Range['A8'];
EditA33.Text:=Exc.Range['A9'];
EditB1.Text:=Exc.Range['A10'];
EditB2.Text:=Exc.Range['A11'];
EditB3.Text:=Exc.Range['A12'];
end;
procedure TForm1.ButtonLaunchClick(Sender: TObject);
begin
Exc:=CreateOleObject('Excel.Application');
Exc.Visible := true;
Exc.Workbooks.Add
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Exc.Visible= true then
Button1.Caption:='Скрыть окно';
Exc.Quit;
end;
procedure TForm1.ButtonCloseClick(Sender: TObject);
begin
Exc.Quit;
end;
procedure TForm1.ButtonOpenClick(Sender: TObject);
begin
if OpenDialog1.Execute then
Exc.Workbooks.Open(OpenDialog1.Filename);
end;
procedure TForm1.ButtonSolveClick(Sender: TObject);
var path:string;
i:integer;
begin
Exc.Range ['A1'] := EditA11.Text;
Exc.Range ['B1'] := EditA12.Text;
Exc.Range ['C1'] := EditA13.Text;
Exc.Range ['A2'] := EditA21.Text;
Exc.Range ['B2'] := EditA22.Text;
Exc.Range ['C2'] := EditA23.Text;
Exc.Range ['A3'] := EditA31.Text;
Exc.Range ['B3'] := EditA32.Text;
Exc.Range ['C3'] := EditA33.Text;
Exc.Range['A5'].FormulaArray:='=МОПРЕД(A1:C3)';
Exc.Range['C5:E7'].FormulaArray:='=МОБР(A1:C3)';
Exc.Range['G5:G7'].FormulaArray:='=МУМНОЖ(C5:E7;E1:E3)';
for i:=0 to 2 do
begin
path:='G'+IntToStr(5+i);
StringGrid1.Cells[i,1]:=Exc.Range[path];
end;
end;
{procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Exc.Ouit;
n:=true;
if n=1 then Button1.Click and Form1.Close
else Excel.exe.Close
end; }
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0]:= 'X';
StringGrid1.Cells[1,0]:= 'Y';
StringGrid1.Cells[2,0]:= 'Z';
end;
end.
{процедура создания формы и начальных установок}
procedure TForm1.FormCreate(Sender: TObject);
var
Find:TSearchRec;
i:integer;
SMenu:TMenuItem;
begin{FormCreate}
. . .
{проверка возможности работы с MSOffice-Excel}
try MSApp:=CreateOLEObject('Excel.Application');
except ShowMessage('Error: cannot open MSApplication - Exel');end;
{Формирование списка меню "Выбеоите файл"}
if FindFirst(Path+'\work\*.xls',faAnyFile,Find)=0then
begin
Form1.MainMenu1.Items[0].Enabled:=True;
repeat{создаем пункт меню с именев файла}
SMenu:=TMenuItem.Create(MainMenu1);
SMenu.Caption:=Find.Name;
SMenu.OnClick:=Form1.SelectMenu;
Form1.MainMenu1.Items[0].Add(SMenu);
until FindNext(Find)<>0;
FindClose(Find);
end ;
end;{FormCreate}
. . .
procedure LoadGrid(a:string);
var
Book:OleVariant;
i,j:integer;
begin{LoadGrid}
Form1.Label1.Caption:='Загружаю файл:'+Path+'\work\'+a;{информируем пользователя}
MSApp.WorkBooks.Open(Path+'\work\'+a, 0, True);{открываем Excel-файл}
{устанавливаем размеры таблицы}
Form1.StringGrid1.ColCount:=MSApp.ActiveWorkbook.ActiveSheet.UsedRange.Columns.Count;
Form1.StringGrid1.RowCount:=MSApp.ActiveWorkbook.ActiveSheet.UsedRange.Rows.Count;
{готовимся к быстрому копированию}
Book:=MSApp.ActiveWorkbook.ActiveSheet.UsedRange.Value;
{копируем в рабочую Грид}
for i:=0 to Form1.StringGrid1.RowCount-1 do
for j:=0 to Form1.StringGrid1.ColCount-1 do
Form1.StringGrid1.Cells[j,i]:=Book[i+1,j+1];
MSApp.WorkBooks.Close;{закрываем Excel-файл}
end;{LoadGrid}
function StrToInt(const S: string): Integer;
function TryStrToInt(const S: string; out Value:Integer):Boolean;
if TryStrToInt(stroкa,number) then begin . . . end
else ShowMessage(' типа бум-бум по голове ');
if TryStrToInt(Exc.Range['A5'],number) then = if number=0 then begin . . . end
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(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
Form1.Button1.Caption:='Show 2';
Form1.Button2.Caption:='Show 1';
Form1.Edit2.Visible:=false;
Form1.Button2.Visible:=false;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Edit1.Hide;
Form1.Button1.Hide;
Form1.Edit2.Visible:=true;
Form1.Button2.Visible:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form1.Edit2.Hide;
Form1.Button2.Hide;
Form1.Edit1.Visible:=true;
Form1.Button1.Visible:=true;
end;
end.
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0]:= 'X';
StringGrid1.Cells[1,0]:= 'Y';
StringGrid1.Cells[2,0]:= 'Z';
Form1.Button1.Caption:='Отобразить окно';
Form1.Button2.Caption:='Скрыть окно';
Form1.Button2.Visible:=false;
end;
end.
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Button1.Hide;
Exc.Quit;
Form1.Button2.Visible:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form1.Button2.Hide;
Exc.Quit; / Это просто прописал для закрытия, нужно чтобы скрывала
Form1.Button1.Visible:=true;
end;
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.