-1

这段代码给了我错误

ex.Cells [3, 2]. HorizontalAlignment: = xlright;

ex.Cells [row, 1]. NumberFormat: = 'dd / mm / yy, @';

我怎样才能解决这个问题?

谢谢

4

1 回答 1

1

根据您的其他问题,您正在使用后期绑定(使用 a Variant)而不是早期绑定(使用 VCLTExcelApplication和其他组件)。这意味着xlRight未定义特定类型,因为您没有使用提供它们的类型库导入。您必须自己定义它们:

var
  ...
  NewAlign: OleVariant;
const
  xlBottom = $FFFFEFF5;
  xlLeft = $FFFFEFDD;
  xlRight = $FFFFEFC8;
  xlTop = $FFFFEFC0;
  xlHAlignCenter = $FFFFEFF4;
  xlHAlignCenterAcrossSelection = $00000007;
  xlHAlignDistributed = $FFFFEFEB;
  xlHAlignFill = $00000005;
  xlHAlignGeneral = $00000001;
  xlHAlignJustify = $FFFFEFDE;
  xlHAlignLeft = $FFFFEFDD;
  xlHAlignRight = $FFFFEFC8;
begin
  // XLApp is the instance of Excel you set up from your previous
  // questions
  XLApp.Workbooks[1].Worksheets[1].Range['C1:C5'].NumberFormat := 'dd/mm/yy';
  NewAlign := xlHAlignRight;
  XLApp.Workbooks[1].Worksheets[1].Range['C1:C5'].HorizontalAlignment := NewAlign;
end;

分配dd/mm/yy @没有意义,因为它要么是 date format 要么是dd/mm/yytext @,但不是两者兼而有之。

于 2013-03-31T04:17:35.470 回答