Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Exportar a Excel, formato de Celda (https://www.clubdelphi.com/foros/showthread.php?t=73854)

oscarac 20-05-2011 06:45:11

Exportar a Excel, formato de Celda
 
baje esta unidad que me ha ayudado bastante...
el asunto es que cuando exporto el grid al excel las columnas que so texto pero contienen numeros, no me las coloca como texto sino como numero

me explico con un ejemplo
en la grilla hay datos como este
Cita:

12C-25....09452633.... Nombre del Trabajador
pero cuando lo migra al excel aparece asi

Cita:

12C-25....9452633.... Nombre del Trabajador
no se cuales son los "codigos" que hay que colocar para que respete el tipo de dato

newtron 20-05-2011 10:55:22

Hola.

Yo para exportar a excel lo hago de una forma ligeramente distinta y no tengo ese problema, mira a ver si te sirve este ejemplo:

Código Delphi [-]
              If TipoDocumento=0 then begin
                // Excel
                ExcelX := Trunc(ImpresoAnverso.SeccionPaneles.Panel[MiIndice].Elemento[f].X/15)+1;
                ExcelY := Trunc(ImpresoAnverso.SeccionPaneles.Panel[MiIndice].Elemento[f].Y/5)+1;

                Hoja.Cells.Item[LineaExcel+ExcelY,ExcelX].NumberFormat := '@';
                if ImpresoAnverso.SeccionPaneles.Panel[MiIndice].Elemento[f].TipoCampo=teReal then
                  Hoja.Cells.Item[LineaExcel+ExcelY,ExcelX].NumberFormat := '#.##0,00';
                if ImpresoAnverso.SeccionPaneles.Panel[MiIndice].Elemento[f].TipoCampo=teEntero then
                  Hoja.Cells.Item[LineaExcel+ExcelY,ExcelX].NumberFormat := '0';

                if sAux=StringOfChar('_',length(sAux)) then
                  Hoja.Cells.Item[LineaExcel+ExcelY,ExcelX].Font.underline:=True
                else
                  if ImpresoAnverso.SeccionPaneles.Panel[MiIndice].Elemento[f].TipoCampo=teReal then begin
                    Hoja.Cells.Item[LineaExcel+ExcelY,ExcelX]:=StrToCurr(StrTran(sAux,'.',''));
                  end else if ImpresoAnverso.SeccionPaneles.Panel[MiIndice].Elemento[f].TipoCampo=teFecha then begin
                    Hoja.Cells.Item[LineaExcel+ExcelY,ExcelX]:=FormatDateTime('dd/mm/yyyy',StrToDateTime(sAux));
                  end else begin
                    Hoja.Cells.Item[LineaExcel+ExcelY,ExcelX]:=sAux;
                  end;
                If fsBold in ImpresoAnverso.SeccionPaneles.Panel[MiIndice].Elemento[f].Fuente.Style then
                  Hoja.Cells.Item[LineaExcel+ExcelY,ExcelX].Font.Bold:=true;
                case ImpresoAnverso.SeccionPaneles.Panel[MiIndice].Elemento[f].Alineacion of
                  aCentrada : begin
                    Hoja.Cells.Item[LineaExcel+ExcelY,ExcelX].HorizontalAlignment := xlcenter;
                  end;
                  aDerecha: begin
                    Hoja.Cells.Item[LineaExcel+ExcelY,ExcelX].HorizontalAlignment := xlright;
                  end;
                end;
                if ExcelY>LineasE then LineasE:=ExcelY;
              end;

Saludos


La franja horaria es GMT +2. Ahora son las 12:09:49.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi