cxSpreadBook 要么 cxSpreadSheet 设置文本格式
uses
cxSSStyles,cxSSDesigner;
Type
TStyleAccess = class(TcxSSCellStyle);
TSheetAccess = class(TcxSSBookSheet);
procedure TForm2.Button16Click(Sender: TObject);
varRow,Col: Integer;
AStyle: TcxSSCellStyle;
CurrentStyle: integer;
begin
TSheetAccess(cxSpreadBook.ActiveSheet).Owner.BeginUpdate;
try
for Row := 0 to cxSpreadBook.ActiveSheet.RowCount - 1 do
for Col := 0 to cxSpreadBook.ActiveSheet.ColumnCount - 1 do
begin
AStyle := cxSpreadBook.ActiveSheet.GetCellObject(Col,row).Style;
CurrentStyle := TStyleAccess(AStyle).StyleInfo.FormatIndex;
if CurrentStyle =0 then //像那些时间类型的 不能强制转换成文本 不然会出错
begin
TStyleAccess(AStyle).StyleInfo.FormatIndex := 49;
TStyleAccess(AStyle).DoOnChange(AStyle, siFormat);
end;
end;
finally
TSheetAccess(cxSpreadBook.ActiveSheet).Owner.EndUpdate;
end;
end;
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步