这下面是我函数的一部分!
1、问题时我导入都成功,就是在身份证号码在导入的过程中,最后3位被EXCEL变成 了'000',而原来的身份证号15位可以导入正确!
2、在EXCEL中把单元格属性改为'文本',就可以输入18为数字了,问题我怎样在程序中可以把单元格属性变为文本属性,或有什么别的方法?在原来的单元格中是科学计数法的属性!
以下是我的部分程序,看看在那加!
Function DataSetToExcelSheet(DataSet:TDataSet;AdoQry:TAdoQuery;DbGrdEh:TDbGridEh;FieldTagMax:Integer;Sheet:OleVariant): Boolean;
var
Row,Col,FieldIndex :Integer;
BK:TBookMark;
begin
    Result := False;
    if not Dataset.Active then exit;
    BK:=DataSet.GetBookMark;
    DataSet.DisableControls;    Sheet.Activate;
    try
    // 列标题
    Row:=1;
    Col:=1;
    for FieldIndex:=0 to DbGrdEh.Columns.count-1 do
    begin
    If DbGrdEh.Columns.Items[FieldIndex].Visible = True Then Begin
    Sheet.Cells.Item[Row,Col].NumberFormatLocal := '@';
    Sheet.Cells(Row,Col) :=DbGrdEh.Columns.Items[FieldIndex].Title.caption;
    Inc(Col);
    End;
    end;    // 表内容
    DataSet.First;
    while Not DataSet.Eof do
    begin
      Row:=Row+1;
      Col:=1;
      for FieldIndex:=0 to DbGrdEh.Columns.count-1 do
      begin
        If DbGrdEh.Columns.Items[FieldIndex].Visible = True Then Begin
        Sheet.Cells(Row,Col):=DataSet.FieldByName(DbGrdEh.Columns.Items[FieldIndex].FieldName).AsString;
        Inc(Col);
        End;
      end;
      DataSet.Next;
    end;    Result := True;
   finally
    DataSet.GotoBookMark(BK);
    DataSet.EnableControls;
   end;end;

解决方案 »

  1.   

    Sheet.Cells.Item[Row,Col].NumberFormatLocal := '@';//Item应该是用不到的吧
    Sheet.Cells.[Row,Col].NumberFormatLocal := '@';
      

  2.   

    var
      ExcelApp,st:variant;
    begin
      ExcelApp:=CreateOleObject('Excel.Application');
      ExcelApp.workbooks.add();
      ExcelApp.Worksheets[1].activate;
      st := ExcelApp.workbooks[1].worksheets[1];
      st.Range['1:1'].NumberFormatLocal := '@'; //设置一行
      st.Range['A:A'].NumberFormatLocal := '@'; //设置一列
      ExcelApp.visible:=true;
      

  3.   

    加引号当然可以,自动变为文本了,但是改变了身份证,我想我们大家的身份证都没有字符吧!
    不过问题我以解决
    Sheet.Cells.Item[Row,Col].NumberFormatLocal := '@';这就对了
    谢谢东北人,真好!