请教诸位,如何设定Excel单元格的格式?我要的是英文日期格式,最好能够提供全部格式的代码。
    谢谢诸位了!

解决方案 »

  1.   

    没明白你到底是要XLS的格式,还是要日期格式。
      

  2.   

    ActiveSheet.Columns[2].NumberFormatlocal:= 'yyyy-mm-dd ';
      

  3.   

       我说了是要EXCEL  单元格的格式。
       不是要"yyyy-mm-dd"这样的,是要"14-Mar-01"这样的。
      

  4.   

    是 [$-409]d-mmm-yy;@
    想看其他全部格式的代码如下,在excel软件里面把第一单元格设置成你想要的格式,并写入合法的值,存盘退出excel。
    执行下面的代码,可以在第一行第二格写入格式值,第二行第一格新按此格式写入一个示例。procedure TForm1.Button1Click(Sender: TObject);
    var
            Excelid: Variant;
            mstr: string;
    begin
            Excelid := Null;
            try
                    Excelid:=CreateOleObject( 'Excel.Application' );
            except
                    on Exception do begin
                            ShowMessage('无法创建Xls文件,请确认是否安装EXCEL');
                            exit;
                    end;
            end;
            //Excelid.WorkBooks.Add;
            try
                    Excelid.WorkBooks.Open('d:\test.xls');
            except
                    on Exception do begin
                            ShowMessage('无法打开文件!');
                            exit;
                    end;
            end;        Excelid.Visible := True;
            Excelid.worksheets[1].Cells[1,1].select;
            mstr := Excelid.Selection.NumberFormatLocal;
            Excelid.worksheets[1].Cells[1,2].value := mstr;        //用取到的格式值写个新的示例
            Excelid.worksheets[1].Cells[2,1].select;
            Excelid.worksheets[1].Cells[2,1].value := '2011-12-13';
            Excelid.Selection.NumberFormatLocal := mstr;
    end;
      

  5.   

    uses ComObj;procedure TForm1.Button1Click(Sender: TObject);
    var
      ExcelApp :Variant;
    begin
      ExcelApp := CreateOleObject('Excel.Application');
      try
      ExcelApp.WorkBooks.Open('D:\1.xls');
      ExcelApp.workSheets[1].Columns[1].NumberFormat:='dd-mmm-yy';
      ExcelApp.DisplayAlerts:=false;
      ExcelApp.workSheets[1].SaveAs('D:\1.xls');
      finally
        ExcelApp.Quit;
      end;
    end;