📄 decodeformula2.pas
字号:
S := ColRowToRefStr(C,R,(Row1 and $4000) = 0,(Row1 and $8000) = 0);
DecodeArea7(Col2,Row2,C,R);
Stack.Add(S + ':' + ColRowToRefStr(C,R,(Row2 and $4000) = 0,(Row2 and $8000) = 0));
P := Pointer(Integer(P) + SizeOf(TPTGArea7));
end
else with PPTGArea8(P)^ do begin
DecodeArea8(Col1,Row1,C,R);
S := ColRowToRefStr(C,R,(Col1 and $4000) = 0,(Col1 and $8000) = 0);
DecodeArea8(Col2,Row2,C,R);
Stack.Add(S + ':' + ColRowToRefStr(C,R,(Col2 and $4000) = 0,(Col2 and $8000) = 0));
P := Pointer(Integer(P) + SizeOf(TPTGArea8));
end;
end;
ptgRefErr,ptgRefErrV,ptgRefErrA:
begin
asm add P,4 end;
if Version >= xvExcel97 then
asm inc P end;
Stack.Add('#REF!');
end;
ptgAreaErr,ptgAreaErrV,ptgAreaErrA:
begin
asm add P,7 end;
if Version >= xvExcel97 then
asm add P,2 end;
Stack.Add('#REF!');
end;
ptgName,ptgNameV,ptgNameA:
begin
asm inc P end;
if Version < xvExcel50 then with PPTGName7(P)^ do begin
if InSheet then
Stack.Add('[EXTERNNAME]' { XLS.ExternNames[NameIndex] } )
else
Stack.Add('[NAME]' { XLS.Names[NameIndex] } );
P := Pointer(Integer(P) + SizeOf(TPTGName7) - 4);
end
else if Version < xvExcel97 then with PPTGName7(P)^ do begin
Stack.Add(GetNameMethod(ntName,-1,NameIndex,0,0));
P := Pointer(Integer(P) + SizeOf(TPTGName7));
end
else with PPTGName8(P)^ do begin
if Assigned(GetNameMethod) then
Stack.Add(GetNameMethod(ntName,-1,NameIndex,0,0))
else
Stack.Add('[EXTERNNAME]');
P := Pointer(Integer(P) + SizeOf(TPTGName8));
end;
end;
ptgNameX,ptgNameXV,ptgNameXA:
begin
asm inc P end;
if Version < xvExcel97 then with PPTGNameX7(P)^ do begin
Stack.Add(GetNameMethod(ntExternName,ExtSheet,NameIndex,0,0));
P := Pointer(Integer(P) + SizeOf(TPTGNameX7));
end
else with PPTGNameX8(P)^ do begin
if Assigned(GetNameMethod) then
S := GetNameMethod(ntExternSheet,ExtSheet,NameIndex,0,0)
else
S := '[EXTERNNAME X]';
Stack.Add(S);
P := Pointer(Integer(P) + SizeOf(TPTGNameX8));
end;
end;
{
ptgNameV:
begin
asm inc P end;
with PPTGName(P)^ do
Stack.Add(FNames[ExtIndex - 1]);
P := Pointer(Integer(P) + SizeOf(TPTGName));
end;
}
ptgArray,ptgArrayV,ptgArrayA:
begin
asm inc P end;
// P2 := Pointer(Integer(PBuf) + PRecFORMULA(PBuf)^.ParseLen);
S := GetArray;
Stack.Add(Copy(S,1,Length(S) - 1) + '}');
P := Pointer(Integer(P) + 7);
end;
ptgFunc,ptgFuncV,ptgFuncA:
begin
asm inc P end;
if (Version >= xvExcel40) and (word(P^) <= High(ExcelFunctions)) then begin
Stack.Add(ExcelFunctions[word(P^)].Name + '(' + GetFuncArgs(ExcelFunctions[word(P^)].Min) + ')');
asm add P,1 end;
end
else if Version <= xvExcel30 then
Stack.Add(ExcelFunctions[byte(P^)].Name + '(' + GetFuncArgs(ExcelFunctions[byte(P^)].Min) + ')')
else begin
Stack.Add('?<' + IntToStr(Word(P^)) + '>?' + '(' + GetFuncArgs(1) + ')');
asm add P,1 end;
end;
asm add P,1 end;
end;
ptgFuncVar,ptgFuncVarV,ptgFuncVarA:
begin
asm inc P end;
i := Byte(P^) and $7F;
asm inc P end;
S := '1';
if (Version >= xvExcel50) and (word(P^) <= High(ExcelFunctions)) then
S := ExcelFunctions[word(P^) and $7FFF].Name
else if Version < xvExcel50 then
S := ExcelFunctions[byte(P^)].Name;
if (S[1] >= '0') and (S[1] <= '9') then begin
S := Stack[Stack.Count - i];
Stack.Delete(Stack.Count - i);
Dec(i);
end;
Stack.Add(S + '(' + GetFuncArgs(i) + ')');
asm add P,1 end;
if Version = xvExcel40 then
asm add P,1 end;
if Version >= xvExcel50 then
asm add P,1 end;
end;
ptgRef3d,ptgRef3dV,ptgRef3dA,ptgRefErr3d,ptgRefErr3dV,ptgRefErr3dA:
begin
i := Byte(P^);
asm inc P end;
if Version >= xvExcel97 then with PPTGRef3d8(P)^ do begin
if Assigned(GetNameMethod) then
S := GetNameMethod(ntExternSheet,Index,-1,0,0)
else
S := '[ExternSheet]';
if i in [ptgRefErr3d,ptgRefErr3dV] then
Stack.Add(S + '!#REF!')
else
Stack.Add(S + ColRowToRefStr(Col and $3FFF,Row,(Col and $4000) = 0,(Col and $8000) = 0));
P := Pointer(Integer(P) + SizeOf(TPTGRef3d8));
end
else with PPTGRef3d7(P)^ do begin
if Smallint(Index) >= 0 then begin
S := GetNameMethod(ntExternSheet,Index,-1,0,0)
end
else
S := '';
if (IndexFirst = $FFFF) or (IndexLast = $FFFF) then
S := S + '[DELETED]'
else if IndexFirst = IndexLast then begin
S := S + GetNameMethod(ntCurrBook,IndexLast,-1,0,0)
end
else begin
S := S + GetNameMethod(ntCurrBook,IndexFirst,-1,0,0) + ':' + GetNameMethod(ntCurrBook,IndexLast,-1,0,0)
end;
if i in [ptgRefErr3d,ptgRefErr3dV] then
Stack.Add(S + '!#REF!')
else
Stack.Add(S + '!' + ColRowToRefStr(Col,Row and $3FFF,(Row and $4000) = 0,(Row and $8000) = 0));
P := Pointer(Integer(P) + SizeOf(TPTGRef3d7));
end;
end;
ptgArea3d,ptgArea3dV,ptgArea3dA,ptgAreaErr3d,ptgAreaErr3dV,ptgAreaErr3dA:
begin
i := Byte(P^);
asm inc P end;
if Version >= xvExcel97 then with PPTGArea3d8(P)^ do begin
if Assigned(GetNameMethod) then
S := GetNameMethod(ntExternSheet,Index,-1,0,0)
else
S := '[ExternSheet]';
if i in [ptgAreaErr3d,ptgAreaErr3dV] then
Stack.Add(S + '!#REF!')
else
Stack.Add(S + ColRowToRefStr(Col1 and $3FFF,Row1,(Col1 and $4000) = 0,(Col1 and $8000) = 0) + ':' +
ColRowToRefStr(Col2 and $3FFF,Row2,(Col2 and $4000) = 0,(Col2 and $8000) = 0));
P := Pointer(Integer(P) + SizeOf(TPTGArea3d8));
end
else with PPTGArea3d7(P)^ do begin
if Smallint(SheetIndex) >= 0 then
S := '[EXTERN ???]:'
else
S := '';
if (IndexFirst = $FFFF) or (IndexLast = $FFFF) then
S := S + '[DELETED]'
else if IndexFirst = IndexLast then begin
S := S + GetNameMethod(ntCurrBook,IndexLast,-1,0,0)
end
else begin
S := S + GetNameMethod(ntCurrBook,IndexFirst,-1,0,0) + ':' + GetNameMethod(ntCurrBook,IndexLast,-1,0,0)
end;
if i in [ptgAreaErr3d,ptgAreaErr3dV] then
Stack.Add(S + '!#REF!')
else
Stack.Add(S + '!' + ColRowToRefStr(Col1,Row1 and $3FFF,(Row1 and $4000) = 0,(Row1 and $8000) = 0) + ':' +
ColRowToRefStr(Col2,Row2 and $3FFF,(Row2 and $4000) = 0,(Row2 and $8000) = 0));
P := Pointer(Integer(P) + SizeOf(TPTGArea3d7));
end;
end;
ptgMemFunc,ptgMemFuncV,ptgMemFuncA: begin
P := Pointer(Integer(P) + 3);
{
asm inc P end;
W := Word(P^);
P := Pointer(Integer(P) + 2 + W);
}
end;
else begin
Stack.Add(Format('Unknown ptg[%.2X]',[Byte(P^)]));
Break;
end;
end;
end;
if Stack.Count < 1 then
Result := '[ERROR]'
else
Result := Stack[Stack.Count - 1];
Stack.Free;
end;
procedure AdjustCell(BIFF8: boolean; Buf: Pointer; Len,DCol,DRow: integer; LockStartRow,ForceAdjust : Boolean);
var
V,C1,R1,C2,R2: integer;
Ok: boolean;
P,P2: PByteArray;
begin
P := Buf;
while (Integer(P) - Integer(Buf)) < Len do begin
case P[0] of
ptgExp {01} : V := 1;
ptgTbl {02} : V := 5;
ptgAdd {03} : V := 1;
ptgSub {04} : V := 1;
ptgMul {05} : V := 1;
ptgDiv {06} : V := 1;
ptgPower {07} : V := 1;
ptgConcat {08} : V := 1;
ptgLT {09} : V := 1;
ptgLE {0A} : V := 1;
ptgEQ {0B} : V := 1;
ptgGE {0C} : V := 1;
ptgGT {0D} : V := 1;
ptgNE {0E} : V := 1;
ptgIsect {0F} : V := 1;
ptgUnion {10} : V := 1;
ptgRange {11} : V := 1;
ptgUplus {12} : V := 1;
ptgUminus {13} : V := 1;
ptgPercent {14} : V := 1;
ptgParen {15} : V := 1;
ptgMissArg {16} : V := 1;
ptgStr {17} : begin
asm inc P end;
if BIFF8 then begin
if PByteArray(P)[1] = 0 then
V := PByteArray(P)[0] + 2
else
V := (PByteArray(P)[0] * 2) + 2;
end
else
V := PByteArray(P)[0] + 1;
end;
ptgAttr {19} : begin
asm inc P end;
if P[0] = $04 then begin
asm inc P end;
V := (Word(Pointer(P)^) + 1) * SizeOf(word) + 2;
end
else
V := 3;
end;
ptgSheet {1A} : V := 1;
ptgEndSheet {1B} : V := 1;
ptgErr {1C} : V := 2;
ptgBool {1D} : V := 2;
ptgInt {1E} : V := 3;
ptgNum {1F} : V := 9;
ptgArray {20} ,
ptgArrayV {40} ,
ptgArrayA {60} : V := 8;
ptgFunc {21} ,
ptgFuncV {41} ,
ptgFuncA {61} : V := 3;
ptgFuncVar {22} ,
ptgFuncVarV {42} ,
ptgFuncVarA {62} : V := 4;
ptgName {23} ,
ptgNameV {43} ,
ptgNameA {63} : if BIFF8 then V := 7 else V := 15;
ptgRef {24} ,
ptgRefV {44} ,
ptgRefA {64} ,
ptgRefN {2C} ,
ptgRefNV {4C} ,
ptgRefNA {6C} : begin
P2 := P;
P := Pointer(Integer(P) + 1);
if BIFF8 then begin
C1 := PPTGRef8(P).Col and $3FFF;
R1 := PPTGRef8(P).Row;
if ForceAdjust or ((PPTGRef8(P).Col and $8000) = $8000) then
If not LockStartRow Then
R1 := PPTGRef8(P).Row + DRow
else
R1 := PPTGRef8(P).Row;
if ForceAdjust or ((PPTGRef8(P).Col and $4000) = $4000) then
C1 := (PPTGRef8(P).Col and $3FFF) + DCol;
Ok := (C1 >= 0) and (C1 <= $FF) and (R1 >= 0) and (R1 <= $FFFF);
if Ok then begin
PPTGRef8(P).Col := (PPTGRef8(P).Col and $C000) + C1;
PPTGRef8(P).Row := R1;
end
else
P2[0] := (P2[0] and $F0) + $0A;
V := 4;
end
else begin
C1 := PPTGRef7(P).Col;
R1 := PPTGRef7(P).Row;
if ForceAdjust or ((PPTGRef7(P).Row and $8000) = $8000) then
C1 := PPTGRef7(P).Col + DCol;
if ForceAdjust or ((PPTGRef7(P).Row and $4000) = $4000) then
If not LockStartRow Then
R1 := (PPTGRef7(P).Row and $3FFF) + DRow
else
R1 := (PPTGRef7(P).Row and $3FFF);
Ok := (C1 >= 0) and (C1 <= $FF) and (R1 >= 0) and (R1 <= $3FFF);
if Ok then begin
PPTGRef7(P).Col := C1;
PPTGRef7(P).Row := (PPTGRef7(P).Row and $C000) + R1;
end
else
P2[0] := (P2[0] and $F0) + $0A;
V := 3;
end;
end;
ptgRefErr {2A} ,
ptgRefErrV {4A} ,
ptgRefErrA {6A} : if BIFF8 then V := 5 else V := 4;
ptgArea {25} ,
ptgAreaV {45} ,
ptgAreaA {65} ,
ptgAreaN {2D} ,
ptgAreaNV {4D} ,
ptgAreaNA {6D} : begin
P2 := P;
P := Pointer(Integer(P) + 1);
if BIFF8 then begin
C1 := PPTGArea8(P).Col1 and $3FFF;
R1 := PPTGArea8(P).Row1;
C2 := PPTGArea8(P).Col2 and $3FFF;
R2 := PPTGArea8(P).Row2;
if ForceAdjust or ((PPTGArea8(P).Col1 and $8000) = $8000) then
If not LockStartRow Then
R1 := PPTGArea8(P).Row1 + DRow
else
R1 := PPTGArea8(P).Row1;
if ForceAdjust or ((PPTGArea8(P).Col1 and $4000) = $4000) then
C1 := (PPTGArea8(P).Col1 and $3FFF) + DCol;
if ForceAdjust or ((PPTGArea8(P).Col2 and $8000) = $8000) then
R2 := PPTGArea8(P).Row2 + DRow;
if ForceAdjust or ((PPTGArea8(P).Col2 and $4000) = $4000) then
C2 := (PPTGArea8(P).Col2 and $3FFF) + DCol;
Ok := (C1 >= 0) and (C1 <= $FF) and (R1 >= 0) and (R1 <= $FFFF) and
(C2 >= 0) and (C2 <= $FF) and (R2 >= 0) and (R2 <= $FFFF);
if Ok then begin
PPTGArea8(P).Col1 := (PPTGArea8(P).Col1 and $C000) + C1;
PPTGArea8(P).Row1 := R1;
PPTGArea8(P).Col2 := (PPTGArea8(P).Col2 and $C000) + C2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -