- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
var
Excel: OleVariant;
Rows, Cols: integer;
WorkSheet: OleVariant;
DebugList: TStringList;
I, j, CSeek: integer;
R, ArrV: OleVariant;
ObjData: TDataContainer;
D: integer;
begin
{$IFDEF DEBUG}
DebugList := TStringList.Create;
{$ENDIF}
try
Excel := CreateOleObject('Excel.Application');
Excel.Visible := false;
Excel.Workbooks.Open[DocPath, 0, True];
WorkSheet := Excel.ActiveWorkbook.ActiveSheet;
R := Excel.Intersect(WorkSheet.UsedRange,
WorkSheet.UsedRange.Offset[14, 0]);
ArrV := R.Value;
Rows := VarArrayHighBound(ArrV, 1);
Cols := VarArrayHighBound(ArrV, 2);
{$IFDEF DEBUG}
DebugList.Add(Format('Количество ячеек в таблице = %d', [(Rows) * Cols]));
DebugList.Add(Format('Rows = %d, Cols = %d', [Rows, Cols]));
{$ENDIF}
CSeek := 0;
D := 1;
for I := 1 to Rows do
begin
if (CompareStr(Trim(VarToStr(ArrV[I, 1])), Trim('Итого')) = 0) then
Break;
if (CompareStr(Trim(VarToStr(ArrV[I, 1])),
Trim('отдел')) = 0) or
(CompareStr(Trim(VarToStr(ArrV[I, 1])), Trim('10.05')) = 0) or
(CompareStr(Trim(VarToStr(ArrV[I, 1])), Trim('10.06')) = 0) or
(CompareStr(Trim(VarToStr(ArrV[I, 1])), Trim('10.09')) = 0) then
begin
CSeek := I + 2;
Continue;
end;
if CSeek > I then
Continue;
for j := 1 to Cols do
begin
case j of
1:
begin
if VarToStr(ArrV[I, j]) <> '' then
begin
ObjData := TDataContainer.Create;
ObjData.Name := ArrV[I, j];
end;
end;
3:
begin
if VarToStr(ArrV[I, j]) <> '' then
ObjData.InventoryNumber := GetInventoryNumber(ArrV[I, j]);
end;
10:
begin
if (D mod 2 <> 0) then
begin
if VarToStr(ArrV[I, j]) <> '' then
ObjData.DataCount := ArrV[I, j];
end
else
ObjData.Cost := ArrV[I, j];
if (ObjData <> nil) and (ObjData.DataCount > 0) then
begin
FData.Add(ObjData);
DebugList.Add(ObjData.AsString);
end;
end;
end;
Inc(D);
end;
end;
{$IFDEF DEBUG}
DebugList.Add('Objects created: ' + IntToStr(FData.Count));
D:=1;
for ObjData in FData.Items.Values do
D := D + ObjData.DataCount;
DebugList.Add('Total objects count: ' + IntToStr(D));
DebugList.SaveToFile('C:\ExcelDebug.txt');
{$ENDIF}
finally
{$IFDEF DEBUG}
DebugList.Free;
{$ENDIF}
Excel.Quit;
end;
end;
При разборе выхлопа из 1С в Excel - excel и формат выгрузки сделали всё, чтобы я люто наговнокодил-(