如何使用XLSReadWriteII5创建验证列表

时间:2015-01-21 09:20:20

标签: delphi delphi-7 xlsx delphi-6

我需要使用组件TXLSReadWriteII5

在Excel中创建验证列表

我编写了以下代码,但由于某些原因,验证列表未在Excel文件中创建。提前谢谢。

var
  LwWorksheet : TXLSWorksheet;
  LValidation: TXLSDataValidation;
  LCell  :TXLSCell;
begin
  LwWorksheet:= XLS.Add;
  try
    LwWorksheet.Name:= 'This is a test';
    LwWorksheet.AsString[1,1] := 'This is a test';

    LwWorksheet.AsString[3,2] := 'A';
    LwWorksheet.AsString[3,3] := 'B';
    LwWorksheet.AsString[3,4] := 'C';

    LwWorksheet.AsString[2,2] := 'A';
    LwWorksheet.AsString[2,3] := 'B';
    LwWorksheet.AsString[2,4] := 'C';

    LwWorksheet.AsString[4,2] := 'A';
    LwWorksheet.AsString[4,3] := 'B';
    LwWorksheet.AsString[4,4] := 'C';

    LValidation:= LwWorksheet.Validations.Add;
    LValidation.Areas.Add(5,5);
    LValidation.Formula1:='$B$2:$B$4';
    LValidation.Sqref.Add(5,5);
    LValidation.Type_:= x12dvtList;
    LValidation.ShowDropDown:= True;
    LValidation.ShowInputMessage:= True;
    LValidation.AllowBlank:= False; 
  finally
    LwWorksheet.Free;
  end;//try...finally...

0 个答案:

没有答案