我想将输出内容保存在excel表格中,但是数字太长总是转变格式,怎么能设置单元格的格式为文本?

解决方案 »

  1.   

    newsheet.range['A1:'+'A'+INTtostr((行数count)].NumberFormatLocal:='@';设置第一列为文本
      

  2.   

    Assuming a _Worksheet variable, WS:  var
        Format: OleVariant;
      ...
        WS := Excel.ActiveSheet as _Worksheet;To format one cell in the General number style 
        Format := 'General';
        WS.Range['A1', 'A1'].NumberFormat := Format;To format a range in the 'Text' style, aligned right 
    Weirdly enough, to give a range a 'text' style you have to set its NumberFormat property to '@':   with WS.Range['A1', 'M10'] do
      begin
        NumberFormat := '@';
        HorizontalAlignment := xlHAlignRight;
      end;To format a range of cells with the 'March 4, 1999' date style 
        Format := 'mmmm d, yyyy';
        WS.Range['B1', 'C10'].NumberFormat := Format;To format an entire column in a customized currency style 
        Format := '$#,##0.00_);[Red]($#,##0.00)';
        WkSheet.Range['C1', 'C1'].EntireColumn.NumberFormat := Format;To set the text in a cell to 20pt Arial, bold, and fuchsia 
        with Excel.ActiveCell.Font do
        begin
          Size := 20;
          FontStyle := 'Bold';
          Color := clFuchsia;
          Name := 'Arial';
        end;To change the cell's colour    Excel.ActiveCell.Interior.Color := clBtnFace; 
    or 
        Excel.Range['B2', 'C6'].Interior.Color := RGB(223, 123, 123); 
    To make the first three characters in a cell bold 
      var
        Start, Length: OleVariant;
      ...
        Start := 1;
        Length := 3;
        Excel.ActiveCell.Characters[Start, Length].Font.FontStyle := 'Bold';
        Start := 4;
        Length := 16;
        Excel.ActiveCell.Characters[Start, Length].Font.FontStyle := 'Regular';