如题,在人事资料查询结果转EXCEL时,身份证号码(18位的)最后3位显示为0,有什么办法能让它正确显示?我试过把一个18位的数字直接复制到EXCEL中最后3位也显示为0,但可以先把那一列的存储格式设置类别设置为"文字"贴上就可以正确显示了,但请问在程序中怎么设置转EXCEL时某一列的存储格式为"文字"?

解决方案 »

  1.   

    在导出时的语句中,加入符号 '
    if 字段是xx then xx:=''''+xx   
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '1234567890123
      

  2.   

    http://study.99net.net/study/program/delphi/1085477174.html
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComObj, extctrls, comctrls, ActiveX, OleServer,
      Excel2000;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var ExcelID: OleVariant;
    begin
      ExcelID := CreateOleObject( 'Excel.Application' );
      ExcelID.Visible := True;
      ExcelID.Caption := '测试';
      ExcelID.WorkBooks.Open( 'C:\book1.xls' );
      ExcelID.WorkSheets[2].Activate;
      ExcelID.ActiveSheet.Columns[4].PageBreak := 0;
      ExcelID.ActiveSheet.Columns[1].NumberFormat := '@';
      ExcelID.Cells[1,1].Value := '1234567890123456789';
      ExcelID.Cells[1,2].Value := '1234567890123456789';
    end;end.我试了是可以的,你可以试试看,应该没什么问题