Delphi operation Excel common

Here is what I used Excel in Delphi's operations

ExlApp: = CreateOLEObject ( 'Excel.Application' ); // create an object
ExlApp.Visible: = False; // True; // whether to show
ExlApp.DisplayAlerts: = False; // should display warning
ExlApp.Caption: = aTitle; // set title

ExlApp.Workbooks.Open (FileName); // open file
ExlApp.Workbooks [1] .Sheets [1] .Activate; // set to which the worksheet to an active state

ExlApp.Workbooks [1] .Title: = 'quotations';


Rows, columns into coordinates names, such as a row 3 is converted into a C1
  sTemp: = Char (iCol + 64);
  the Result: = the Format ( '% S% D', [sTemp, iRow]);

// --------------------------------------- merger same column

iStart: = iDataStart; // start from the first few lines
  iCount: = 0; // Number to be combined
  for i: = iDataStart to ExlApp.ActiveSheet.UsedRange.Rows.Count do // find the same progressive column
  the begin
    sValue: = Trim (VarToStr (ExlApp.ActiveSheet.Cells [iStart , iIndex] .Value)); // start line value
    sTemp: = Trim (VarToStr (ExlApp.ActiveSheet.Cells [i, iIndex] .Value)); / / value of the current line of
    SnO: ExlApp.ActiveSheet.Cells = [I,. 1] .Value;
    IF (sValue <> sTemp) the then // change the front column to merge
    the begin
      Rl: = GetCellName (iStart, iIndex);
      R2: = GetCellName (i-1 , iIndex); // i-1 is the previous combined line, this line is not

      ExlApp.ActiveSheet.Range [Format ( '% s: % s', [R1, R2])] Merge; // merge lines.
      ExlApp.ActiveSheet.Range [the Format ( '% S:% S', [Rl, R2 .])] Borders [1] .Weight: = 2; // grid line provided
      ExlApp.ActiveSheet.Range [format ( '% s: % s', [R1, R2])] Borders [2] .Weight. : = 2;
      ExlApp.ActiveSheet.Range [the Format ( '% S:% S', [Rl, R2])] Borders [. 3] .Weight:. = 2;
      ExlApp.ActiveSheet.Range [the Format ( '% S: S% ', [Rl, R2])] Borders [. 4] .Weight: = 2;.
      iStart: = I;
      iCount: =. 1;
    End
    the else IF (TryStrToInt (SnO, iTemp)) and (iTemp> 0) the then
    the begin
      Inc is an (iCount); // if the starting and the current value of the same quantity to be combined is increased
    end;

  End;
  IF iCount> 0 // Finally, there is the then be merged, combined continue
  the begin
    Rl: = GetCellName (iStart, iIndex);
    R2: = GetCellName (iCount +-iStart. 1, iIndex);
    ExlApp.ActiveSheet.Range [the Format ( '% s:% s' , [R1, R2])] merge; // R1 and merge prior to the CELL R2.
    ExlApp.ActiveSheet.Range [the Format ( '% S:% S', [Rl, R2] .)] Borders [1] .Weight : = 2; // grid line provided
    ExlApp.ActiveSheet.Range [format ( '% s: % s', [R1, R2])] Borders [2] .Weight:. 2 =;
    ExlApp.ActiveSheet.Range [the Format ( '% S:% S', [Rl, R2])]. Borders [. 3] .Weight: = 2;
    ExlApp.ActiveSheet.Range [the Format ( '% S:% . S ', [Rl, R2])] Borders [. 4] .Weight: = 2;
  End;

ExlApp.ActiveSheet.columns [i] .Hidden: = True; // hide columns

ExlApp.ActiveSheet.Columns [i] .Delete; // delete columns

ExlApp.ActiveSheet.Cells[4,2].Value:=FieldByName('cCusName').AsString; //赋值
sTemp:=ExlApp.ActiveSheet.Cells[iDataStart,1].Value; //取值

ExlApp.ActiveSheet.Cells [5,10] .NumberFormat: = ' @'; // Set the cell format, which is text-based
ExlApp.ActiveSheet.Cells [5,10] .NumberFormat: = ' # 0 ##. ## '; // set the format cells, which is a digital type
ExlApp.ActiveSheet.Cells [5,10] .NumberFormat: =' $ # 0 #### '; // set the cell format it. is the currency

ExlApp.ActiveSheet.Columns [11] .EntireColumn.AutoFit; // column automatically

ExlApp.ActiveSheet.Rows [3] .Insert; // insert a row

ExlApp.ActiveSheet.UsedRange.Rows.Count // number of rows, columns, too

// --------------------------------------- image manipulation

var
  vStream: TADOBlobStream;
  Scola, tmpFile, vPicType, R1: string;
  i iCol: Integer;
  picture, workRange: OleVariant;
  ignites: string;

the begin
VSTREAM: = TADOBlobStream.Create (TBlobField (Query001_2.FieldByName ( 'Pics')), bmRead); the image data is written to the stream
if vStream.Size = 0 then // no image data
the begin
  Exit;
End;
    vPicType: = CheckImgType (VSTREAM); // type image Analyzing
    vStream.Position: = 0; // points to the beginning of the stream
    tmpFile: '.' = GV_TempPath + PubData1.GetGUIDString + + vPicType; // creates a temporary file name
    TBlobField (Query001_2.FieldByName ( 'Pics . ')) SaveToFile (tmpFile) ; // save data to a temporary file stream
    ExlApp.ActiveSheet.Columns [iCol] .ColumnWidth: = 15 ; // set the column width
    Rl: = GetCellName (iRow, iCol);
    workRange: = ExlApp.ActiveSheet.Range [format ( '% s: % s', [R1, R1])]; // set range, where only a grid
    workRange.Select;
    picture: = ExlApp.ActiveSheet.Shapes.AddPicture (tmpFile, true, true, workRange.left + 1, workRange.top + 1, workRange.width - 2, workRange.height - 2); // insert images, two front true I do not know what's the use, respectively, behind left, top, width, height

    picture: = Unassigned; // release
    workRange: = Unassigned;
    DeleteFile (tmpFile); // delete temporary files
    vStream.Free;

the try
      iTemp: = 1; // measured from a first

      for i: = 1 to 10000 do // inaccessible because the number of shapes, so here the large dot set
      the begin
        IF VarIsEmpty (ExlApp.ActiveSheet.Shapes.Item (iTemp)) // the then determines the presence of the N-th delete
        the begin
          Inc is an ( iTemp);
          Break;
        End the else
        the begin
          IF ExlApp.ActiveSheet.Shapes.Item (iTemp) .Width <500 // this is the then delete the conditions you define
          the begin
            ExlApp.ActiveSheet.Shapes.Item (iTemp) .Delete; // delete N-th, the latter becomes the N-th, and so
          End the else
            inc is (iTemp); // do not have to delete it is determined that N + 1-th
        end;

      end;
    except

    end;

end;

// --------------------------------------- exit
the try
    ExlApp.WorkBooks.Close; / / close the workbook
    ExlApp.Quit; // exit
    ExlApp: = unassigned; // close the thread, or else there is in the task list will be
    the Result: = True;
  the except
    the Result: = False;
  End;


 

Guess you like

Origin blog.csdn.net/victor_yang/article/details/86570334