⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decodeformula2.pas

📁 一个经典的读写Excel的控件
💻 PAS
📖 第 1 页 / 共 4 页
字号:
                                  PPTGArea8(P).Row2 := R2;
                                end
                                else
                                  P2[0] := (P2[0] and $F0) + $0B;
                                V := 8;
                              end
                              else begin
                                C1 := PPTGArea7(P).Col1;
                                R1 := PPTGArea7(P).Row1;
                                C2 := PPTGArea7(P).Col2;
                                R2 := PPTGArea7(P).Row2;
                                if ForceAdjust or ((PPTGArea7(P).Row1 and $8000) = $8000) then
                                  C1 := PPTGArea7(P).Col1 + DCol;
                                if ForceAdjust or ((PPTGArea7(P).Row1 and $4000) = $4000) then
                                  If not LockStartRow Then
                                    R1 := (PPTGArea7(P).Row1 and $3FFF) + DRow
                                  else
                                    R1 := (PPTGArea7(P).Row1 and $3FFF);
                                if ForceAdjust or ((PPTGArea7(P).Row2 and $8000) = $8000) then
                                  C2 := PPTGArea7(P).Col2 + DCol;
                                if ForceAdjust or ((PPTGArea7(P).Row2 and $4000) = $4000) then
                                  R2 := (PPTGArea7(P).Row2 and $3FFF) + DRow;
                                Ok := (C1 >= 0) and (C1 <= $FF) and (R1 >= 0) and (R1 <= $3FFF) and
                                      (C2 >= 0) and (C2 <= $FF) and (R2 >= 0) and (R2 <= $3FFF);
                                if Ok then begin
                                  PPTGArea7(P).Col1 := C1;
                                  PPTGArea7(P).Row1 := (PPTGArea7(P).Row1 and $C000) + R1;
                                  PPTGArea7(P).Col2 := C2;
                                  PPTGArea7(P).Row2 := (PPTGArea7(P).Row2 and $C000) + R2;
                                end
                                else
                                  P2[0] := (P2[0] and $F0) + $0B;
                                V := 6;
                              end;
                            end;

      ptgAreaErr     {2B} ,
      ptgAreaErrV    {4B} ,
      ptgAreaErrA    {6B} : if BIFF8 then V := 9 else V := 7;

      ptgMemArea     {26} ,
      ptgMemAreaV    {46} ,
      ptgMemAreaA    {66} : V := Word(Pointer(Integer(P) + 1)^) + 7;

      ptgMemAreaN    {2E} ,
      ptgMemAreaNV   {4E} ,
      ptgMemAreaNA   {6E} : V := Word(Pointer(Integer(P) + 1)^) + 3;

      ptgMemErr      {27} ,
      ptgMemErrV     {47} ,
      ptgMemErrA     {67} : V := Word(Pointer(Integer(P) + 1)^) + 7;

      ptgMemNoMem    {28} ,
      ptgMemNoMemV   {48} ,
      ptgMemNoMemA   {68} : V := Word(Pointer(Integer(P) + 1)^) + 7;

      ptgMemNoMemN   {2F} ,
      ptgMemNoMemNV  {4F} ,
      ptgMemNoMemNA  {6F} : V := Word(Pointer(Integer(P) + 1)^) + 3;

      ptgMemFunc     {29} ,
      ptgMemFuncV    {49} ,
      ptgMemFuncA    {69} : V := Word(Pointer(Integer(P) + 1)^) + 3;

      ptgNameX       {39} ,
      ptgNameXV      {59} ,
      ptgNameXA      {79} : if BIFF8 then V := 7 else V := 25;

      ptgRef3d       {3A} ,
      ptgRef3dV      {5A} ,
      ptgRef3dA      {7A} : begin
                              P2 := P;
                              P := Pointer(Integer(P) + 1);
                              if BIFF8 then begin
                                C1 := PPTGRef3d8(P).Col and $3FFF;
                                R1 := PPTGRef3d8(P).Row;
                                if ForceAdjust or ((PPTGRef3d8(P).Col and $8000) = $8000) then
                                  If not LockStartRow Then
                                    R1 := PPTGRef3d8(P).Row + DRow
                                  else
                                    R1 := PPTGRef3d8(P).Row;
                                if ForceAdjust or ((PPTGRef3d8(P).Col and $4000) = $4000) then
                                  C1 := (PPTGRef3d8(P).Col and $3FFF) + DCol;
                                Ok := (C1 >= 0) and (C1 <= $FF) and (R1 >= 0) and (R1 <= $FFFF);
                                if Ok then begin
                                  PPTGRef3d8(P).Col := (PPTGRef3d8(P).Col and $C000) + C1;
                                  PPTGRef3d8(P).Row := R1;
                                end
                                else
                                  P2[0] := (P2[0] and $F0) + $0C;
                                V := 6;
                              end
                              else begin
                                C1 := PPTGRef3d7(P).Col;
                                R1 := PPTGRef3d7(P).Row;
                                if ForceAdjust or ((PPTGRef3d7(P).Row and $8000) = $8000) then
                                  C1 := PPTGRef3d7(P).Col + DCol;
                                if ForceAdjust or ((PPTGRef3d7(P).Row and $4000) = $4000) then
                                  If not LockStartRow Then
                                    R1 := (PPTGRef3d7(P).Row and $3FFF) + DRow
                                  else
                                    R1 := (PPTGRef3d7(P).Row and $3FFF);
                                Ok := (C1 >= 0) and (C1 <= $FF) and (R1 >= 0) and (R1 <= $3FFF);
                                if Ok then begin
                                  PPTGRef3d7(P).Col := C1;
                                  PPTGRef3d7(P).Row := (PPTGRef3d7(P).Row and $C000) + R1;
                                end
                                else
                                  P2[0] := (P2[0] and $F0) + $0C;
                                V := 16;
                              end;
                            end;

      ptgRefErr3d    {3C} ,
      ptgRefErr3dV   {5C} ,
      ptgRefErr3dA   {7C} : if BIFF8 then V := 7 else V := 17;

      ptgArea3d      {3B} ,
      ptgArea3dV     {5B} ,
      ptgArea3dA     {7B} : begin
                              P2 := P;
                              P := Pointer(Integer(P) + 1);
                              if BIFF8 then begin
                                C1 := PPTGArea3d8(P).Col1 and $3FFF;
                                R1 := PPTGArea3d8(P).Row1;
                                C2 := PPTGArea3d8(P).Col2 and $3FFF;
                                R2 := PPTGArea3d8(P).Row2;
                                if ForceAdjust or ((PPTGArea3d8(P).Col1 and $8000) = $8000) then
                                  If not LockStartRow Then
                                    R1 := PPTGArea3d8(P).Row1 + DRow
                                  else
                                    R1 := PPTGArea3d8(P).Row1;
                                if ForceAdjust or ((PPTGArea3d8(P).Col1 and $4000) = $4000) then
                                  C1 := (PPTGArea3d8(P).Col1 and $3FFF) + DCol;
                                if ForceAdjust or ((PPTGArea3d8(P).Col2 and $8000) = $8000) then
                                  R2 := PPTGArea3d8(P).Row2 + DRow;
                                if ForceAdjust or ((PPTGArea3d8(P).Col2 and $4000) = $4000) then
                                  C2 := (PPTGArea3d8(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
                                  PPTGArea3d8(P).Col1 := (PPTGArea3d8(P).Col1 and $C000) + C1;
                                  PPTGArea3d8(P).Row1 := R1;
                                  PPTGArea3d8(P).Col2 := (PPTGArea3d8(P).Col2 and $C000) + C2;
                                  PPTGArea3d8(P).Row2 := R2;
                                end
                                else
                                  P2[0] := (P2[0] and $F0) + $0D;
                                V := 10;
                              end
                              else begin
                                C1 := PPTGArea3d7(P).Col1;
                                R1 := PPTGArea3d7(P).Row1;
                                C2 := PPTGArea3d7(P).Col2;
                                R2 := PPTGArea3d7(P).Row2;
                                if ForceAdjust or ((PPTGArea3d7(P).Row1 and $8000) = $8000) then
                                  C1 := PPTGArea3d7(P).Col1 + DCol;
                                if ForceAdjust or ((PPTGArea3d7(P).Row1 and $4000) = $4000) then
                                  If not LockStartRow Then
                                    R1 := (PPTGArea3d7(P).Row1 and $3FFF) + DRow
                                  else
                                    R1 := (PPTGArea3d7(P).Row1 and $3FFF);
                                if ForceAdjust or ((PPTGArea3d7(P).Row2 and $8000) = $8000) then
                                  C2 := PPTGArea3d7(P).Col2 + DCol;
                                if ForceAdjust or ((PPTGArea3d7(P).Row2 and $4000) = $4000) then
                                  R2 := (PPTGArea3d7(P).Row2 and $3FFF) + DRow;
                                Ok := (C1 >= 0) and (C1 <= $FF) and (R1 >= 0) and (R1 <= $3FFF) and
                                      (C2 >= 0) and (C2 <= $FF) and (R2 >= 0) and (R2 <= $3FFF);
                                if Ok then begin
                                  PPTGArea3d7(P).Col1 := C1;
                                  PPTGArea3d7(P).Row1 := (PPTGArea3d7(P).Row1 and $C000) + R1;
                                  PPTGArea3d7(P).Col2 := C2;
                                  PPTGArea3d7(P).Row2 := (PPTGArea3d7(P).Row2 and $C000) + R2;
                                end
                                else
                                  P2[0] := (P2[0] and $F0) + $0D;
                                V := 20;
                              end;
                            end;

      ptgAreaErr3d   {3D} ,
      ptgAreaErr3dV  {5D} ,
      ptgAreaErr3dA  {7D} : if BIFF8 then V := 11 else V := 21;

      ptgFuncCEV     {58} : V := 3; // Not sure how to handle these.
      ptgFuncCEA     {78} : V := 3;
      else
        raise Exception.CreateFmt('Unknown ptg[%.2X] in AdjustCell',[P[0]]);
//        V := 1;
    end;
    P := Pointer(Integer(P) + V);
  end;
end;

procedure ConvertShrFmla(BIFF8: boolean; Buf: Pointer; Len,ACol,ARow: integer);
var
  V,C,R: integer;
  P: Pointer;

procedure DecodeArea7(Cin: byte; Rin: word; var Cout,Rout: integer);
begin
  if (Rin and $8000) = 0 then
    Rout := Smallint(Rin and $FF)
  else
    Rout := ARow + Shortint(Rin);
  if (Rin and $4000) = 0 then
    Cout := Cin
  else
    Cout := ACol + Shortint(Cin);
end;

procedure DecodeArea8(Cin,Rin: integer; var Cout,Rout: integer);
begin
  if (Cin and $4000) = 0 then
    Cout := Shortint(Cin and $FF)
  else
    Cout := ACol + Shortint(Cin and $FF);
  if (Cin and $8000) = 0 then
    Rout := Rin
  else
    Rout := ARow + Smallint(Rin);
end;

// Ref
// $4C $00 $00 $21 $C0

// Str
// $17 $01 $00 $24

// EQ
// $0B

// Attr
// $19 $02 $0F $00

// Ref
// $4C $00 $00 $FD $C0

// Name
// $43 $2B $00 $00 $00 $06 $19

// Concat
// $08

// AreaErr                     str
// $6B $00 $4C $00 $00 $21 $C0 $17 $01 $01 $AC $20 $0B $19 $02 $09 $00 $2C $00 $00 $FE $C0 $19 $08 $4B $00 $4C $00 $00 $21 $C0 $17 $07 $01 $4C $00 $69 $00 $73 $00 $74 $00 $65 $00 $20 $00 $AC $20 $0B $19 $02 $14 $00 $4C $00 $00 $FF $C0 $1E $01 $00 $4C $00 $00 $1F $C0 $04 $15 $05 $19 $08 $14 $00 $17 $0A $00 $2A $2A $46 $65 $68 $6C $65 $72 $2A $2A $19 $08 $03 $00 $22 $03 $01 $00 $19 $08 $03 $00 $22 $03 $01 $00 $19 $08 $03 $00 $42 $03 $01 $00

begin
  P := Buf;
  while (Integer(P) - Integer(Buf)) < Len do begin
    case Byte(P^) 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 Byte(P^) = $04 then begin
          asm inc P end;
          V := (Word(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 := 5 else V := 15;

      ptgRef         {24} ,
      ptgRefV        {44} ,
      ptgRefA        {64} : if BIFF8 then V := 5 else V := 4;

      ptgArea        {25} ,
      ptgAreaV       {45} ,
      ptgAreaA       {65} : if BIFF8 then V := 9 else V := 7;

      ptgMemArea     {26} ,
      ptgMemAreaV    {46} ,
      ptgMemAreaA    {66} : V := Word(Pointer(Integer(P) + 1)^) + 7;

      ptgMemAreaN    {2E} ,
      ptgMemAreaNV   {4E} ,
      ptgMemAreaNA   {6E} : V := Word(Pointer(Integer(P) + 1)^) + 3;

      ptgMemErr      {27} ,
      ptgMemErrV     {47} ,
      ptgMemErrA     {67} : V := Word(Pointer(Integer(P) + 1)^) + 7;

      ptgMemNoMem    {28} ,
      ptgMemNoMemV   {48} ,
      ptgMemNoMemA   {68} : V := Word(Pointer(Integer(P) + 1)^) + 7;

      ptgMemNoMemN   {2F} ,
      ptgMemNoMemNV  {4F} ,
      ptgMemNoMemNA  {6F} : V := Word(Pointer(Integer(P) + 1)^) + 3;

      ptgMemFunc     {29} ,
      ptgMemFuncV    {49} ,
      ptgMemFuncA    {69} : V := Word(Pointer(Integer(P) + 1)^) + 3;

      ptgRefErr      {2A} ,
      ptgRefErrV     {4A} ,
      ptgRefErrA     {6A} : if BIFF8 then V := 5 else V := 4;

      ptgAreaErr     {2B} ,
      ptgAreaErrV    {4B} ,
      ptgAreaErrA    {6B} : if BIFF8 then V := 9 else V := 7;

      ptgRefN,       {2C}
      ptgRefNV,      {4C}
      ptgRefNA       {6C} : begin
        case Byte(P^) of
          ptgRefN:  Byte(P^) := ptgRef;
          ptgRefNV: Byte(P^) := ptgRefV;
          ptgRefNA: Byte(P^) := ptgRefA;
        end;
        asm inc P end;
        if BIFF8 then begin
          DecodeArea8(PPTGRef8(P).Col,PPTGRef8(P).Row,C,R);
          PPTGRef8(P).Row := R;
          PPTGRef8(P).Col := (PPTGRef8(P).Col and $C000) + C;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -