Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Servers
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 26-08-2014
Avatar de jafera
jafera jafera is offline
Miembro
 
Registrado: may 2007
Ubicación: Llagostera (Girona)
Posts: 582
Poder: 17
jafera Va por buen camino
Error con exportacion a Excel

Buenas a todos.

Como comenté en algún otro post, hice el cambio de D6 a DXE5, no sin tener más de un problema con la conversión de código.
De momento todos los problemas se han ido solucionando y aplicando mejoras en el código a fin de aligerar un poco los ejecutables que han crecido enormemente en relación a los viejos D6.

El problema con el que no doy la solución por ahora es la exportación a excel del contenido de una sql a fin de que sea transparente al usuario.
Hasta el momento usaba el código siguiente:

Código Delphi [-]
procedure TF_GeneracioFullPagament.BtnExcelClick(Sender: TObject);
var
        RangeE: Excel2000.ExcelRange;                                //linea 263
        I, Row: Integer;
        Bookmark: TBookmarkStr;
begin
        IBExcel1.Close;
        IBExcel1.SQL[6] := 'AND C.ANIO='+ComboBox1.Text;
        IBExcel1.Open;
        ExcelApplication1.Visible [0] := True;
        ExcelApplication1.Workbooks.Add (NULL, 0);
        RangeE := ExcelApplication1.ActiveCell;
        for I := 0 to IBExcel1.Fields.Count - 1 do
        begin
                RangeE.Value := IBExcel1.Fields [i].DisplayLabel;
                RangeE := RangeE.Next;
        end;
                IBExcel1.DisableControls;
        try
                Bookmark := IBExcel1.Bookmark;                          //linea 280
                try
                        IBExcel1.First;
                        Row := 2;
                        while not IBExcel1.EOF do
                        begin
                                RangeE := ExcelApplication1.Range ['A' + IntToStr (Row),'A' + IntToStr (Row)];
                                for I := 0 to IBExcel1.Fields.Count - 1 do
                                begin
                                        RangeE.Value := IBExcel1.Fields [i].AsString;
                                        RangeE := RangeE.Next;
                                end;
                                begin
                                        IBExcel1.Next;
                                        Inc (Row);
                                        ExcelApplication1.Range['G1','G'+IntToStr(Row)].NumberFormat := '@';
                                        ExcelApplication1.Range['J1','J'+IntToStr(Row)].NumberFormat := '0.00';
                                        ExcelApplication1.Range['K1','K'+IntToStr(Row)].NumberFormat := '0.00';
                                        ExcelApplication1.Range['L1','L'+IntToStr(Row)].NumberFormat := '0.00';
                                        ExcelApplication1.Range['M1','M'+IntToStr(Row)].NumberFormat := '0.00';
                                        ExcelApplication1.Range['N1','N'+IntToStr(Row)].NumberFormat := '0.00';
                                end;
                        end;
                finally
                        IBExcel1.Bookmark := Bookmark;                                      //linea 304
                end;
        finally
                IBExcel1.EnableControls;
        end;
        RangeE := ExcelApplication1.Range ['A1', 'N' + IntToStr (Row - 1)];
        RangeE.AutoFormat (3, NULL, NULL, NULL, NULL, NULL, NULL);
end;

y no le gusta las lineas:

[dcc32 Warning] Inici.pas(9): W1005 Unit 'Vcl.FileCtrl' is specific to a platform
[dcc32 Warning] GenerarFullPagament.pas(263): W1002 Symbol 'ExcelRange' is specific to a platform
[dcc32 Error] GenerarFullPagament.pas(280): E2010 Incompatible types: 'AnsiString' and 'System.TArray<System.Byte>'
[dcc32 Error] GenerarFullPagament.pas(304): E2010 Incompatible types: 'System.TArray<System.Byte>' and 'AnsiString'

He cambiado los servers a XP en lugar de 2000 y el código queda así:

Código Delphi [-]
procedure TF_GeneracioFullPagament.BtnExcelClick(Sender: TObject);
var
        RangeE: ExcelXP.ExcelRange;
        I, Row: Integer;
        Bookmark: TBookmarkStr;
begin
        IBExcel1.Close;
        IBExcel1.SQL[6] := 'AND C.ANIO='+ComboBox1.Text;
        IBExcel1.Open;
        ExcelApplication1.Visible [0] := True;
        ExcelApplication1.Workbooks.Add (NULL, 0);
        RangeE := ExcelApplication1.ActiveCell;
        for I := 0 to IBExcel1.Fields.Count - 1 do
        begin
                RangeE.Value := IBExcel1.Fields [i].DisplayLabel;       // linea 275
                RangeE := RangeE.Next;
        end;
                IBExcel1.DisableControls;
        try
                Bookmark := IBExcel1.Bookmark;                            // linea 280
                try
                        IBExcel1.First;
                        Row := 2;
                        while not IBExcel1.EOF do
                        begin
                                RangeE := ExcelApplication1.Range ['A' + IntToStr (Row),'A' + IntToStr (Row)];
                                for I := 0 to IBExcel1.Fields.Count - 1 do
                                begin
                                        RangeE.Value := IBExcel1.Fields [i].AsString;              //linea 289
                                        RangeE := RangeE.Next;
                                end;
                                begin
                                        IBExcel1.Next;
                                        Inc (Row);
                                        ExcelApplication1.Range['G1','G'+IntToStr(Row)].NumberFormat := '@';
                                        ExcelApplication1.Range['J1','J'+IntToStr(Row)].NumberFormat := '0.00';
                                        ExcelApplication1.Range['K1','K'+IntToStr(Row)].NumberFormat := '0.00';
                                        ExcelApplication1.Range['L1','L'+IntToStr(Row)].NumberFormat := '0.00';
                                        ExcelApplication1.Range['M1','M'+IntToStr(Row)].NumberFormat := '0.00';
                                        ExcelApplication1.Range['N1','N'+IntToStr(Row)].NumberFormat := '0.00';
                                end;
                        end;
                finally
                        IBExcel1.Bookmark := Bookmark;                                           //linea 304
                end;
        finally
                IBExcel1.EnableControls;
        end;
        RangeE := ExcelApplication1.Range ['A1', 'N' + IntToStr (Row - 1)];
        RangeE.AutoFormat (3, NULL, NULL, NULL, NULL, NULL, NULL);
end;

Y ahora me da error en las lineas:

[dcc32 Error] GenerarFullPagament.pas(275): E2029 '[' expected but ':=' found
[dcc32 Error] GenerarFullPagament.pas(275): E2010 Incompatible types: 'Procedure' and 'string'
[dcc32 Error] GenerarFullPagament.pas(280): E2010 Incompatible types: 'AnsiString' and 'System.TArray<System.Byte>'
[dcc32 Error] GenerarFullPagament.pas(289): E2029 '[' expected but ':=' found
[dcc32 Error] GenerarFullPagament.pas(289): E2010 Incompatible types: 'Procedure' and 'string'
[dcc32 Error] GenerarFullPagament.pas(304): E2010 Incompatible types: 'System.TArray<System.Byte>' and 'AnsiString'

Alguien me puede iluminar un poco?

Llevo dias dándole vueltas y no encuentro por dónde atajarlo.

Saludos

Josep
Responder Con Cita
  #2  
Antiguo 27-08-2014
Avatar de oscarac
[oscarac] oscarac is offline
Miembro Premium
 
Registrado: sep 2006
Ubicación: Lima - Perú
Posts: 2.009
Poder: 20
oscarac Va por buen camino
me parece que el tema del range debe estar en este formato


Código Delphi [-]
ExcelApplication1.Range['G1:G'+IntToStr(Row)].NumberFormat
__________________
Dulce Regalo que Satanas manda para mi.....
Responder Con Cita
  #3  
Antiguo 28-08-2014
Avatar de jafera
jafera jafera is offline
Miembro
 
Registrado: may 2007
Ubicación: Llagostera (Girona)
Posts: 582
Poder: 17
jafera Va por buen camino
Gracias por la respuesta Oscarac.

Al final he optado por el uso del componente SCExcelExport que simplifica bastante el trabajo, os adjunto el código:

Código Delphi [-]
procedure TF_GeneracioFullPagament.BtnExcelClick(Sender: TObject);
begin
        scExcelExport1.WorksheetName := 'Subvencions Carnaval '+ComboBox1.Text;
        scExcelExport1.Dataset:=IBExcel1;
        IBExcel1.Close;
        IBExcel1.SQL[6] := 'AND C.ANIO='+ComboBox1.Text;
        IBExcel1.Open;
        scExcelExport1.StyleColumnWidth:=cwOwnerWidth;
        scExcelExport1.ColumnWidth := 20;
        scExcelExport1.HeaderText.Text:='Sunvenció colles carnaval any '+ComboBox1.Text;
        scExcelExport1.FontHeader.Size:=12;
        scExcelExport1.BeginRowHeader:=2;
        scExcelExport1.BeginRowTitles:=4;
        scExcelExport1.BorderTitles.BackColor := clBlue;
        scExcelExport1.FontTitles.Color:=clWhite;
        scExcelExport1.SummarySelection := ssValues;
        scExcelExport1.SummaryCalculation := scSUM;
        scExcelExport1.StyleColumnWidth:=cwAutoFit;
        //scExcelExport1.ExcelWorkSheet.PageSetup.Orientation:= xlLandscape;
        scExcelExport1.ExcelVisible:=True;

        try
                scExcelExport1.ExportDataset;
        if Assigned(scExcelExport1.ExcelWorkSheet) then
                scExcelExport1.SaveAs('C:\Carnaval_1.0\Fulles Excel\Subvencio Carnaval '+ComboBox1.Text+'.xls',ffXLS);
        finally
                scExcelExport1.Disconnect;
        end;
end;

Funciona bien excepto la linea comentada que me arroja un error de Interface Not Supported.
Olvido algun paso o colocar algo en uses?

Gracias

Josep
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Personalizar exportacion a excel ilichhernandez Conexión con bases de datos 12 08-06-2011 21:52:59
exportacion de access a excel luxus Conexión con bases de datos 3 15-04-2008 21:30:59
problemilla con la exportación a excel Apetelinau Conexión con bases de datos 2 07-03-2007 23:59:48
Exportacion a Excel incorrecta jfloro Servers 4 19-09-2003 09:48:36
Exportación de Qreports a excel DanielAlexander Impresión 12 28-07-2003 14:31:19


La franja horaria es GMT +2. Ahora son las 00:28:50.


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
Copyright 1996-2007 Club Delphi