Página 5 de 5

Exportar para excel com Abas

Enviado: 23 Ago 2017 22:50
por asimoes
Não funcionou,

A impressão que eu tenho é que tem que ter o office excel, word, etc instalado pra funcionar

Exportar para excel com Abas

Enviado: 23 Ago 2017 23:17
por asimoes
agora funcionou a string de conexão estava errada:

A que funcionou:

cStr := [Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:\excel\Aniversariantes.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";]

Exportar para excel com Abas

Enviado: 27 Nov 2018 13:24
por lugab
Bom dia, pessoal...

Alguém tem exemplo de geração de gráfico de barras no Excel pra compartilhar ?

Exportar para excel com Abas

Enviado: 03 Mai 2019 10:30
por asimoes
Voltando ao assunto:

oSheet:Cells( 2, 1 ):Value := "'"+"003ACAD"

Pode usar assim também, assim não fica a aspas simples na frente do valor

oSheet:Cells( 2, 1 ):Value := Chr(160) + "003ACAD"

Exportar para excel com Abas

Enviado: 09 Mai 2019 11:00
por asimoes
Inserindo imagem no excel

Código: Selecionar todos

With Object oSheet1 := oExcel:ActiveSheet
   //:Shapes:addPicture("P:\GERAL\HARBOUR\TESTE.JPG", 0, 1, 5, 5, 100, 100)
   // Ou
   :Cells( 1, 1 ):Select()	
   :Pictures:Insert( "P:\GERAL\HARBOUR\TESTE.JPG" ):Select()
End   

Exportar para excel com Abas

Enviado: 18 Mai 2019 17:54
por Alexandre Silva
O que eu nao consigo é definir a celula como no exemplo do cliente
Nas primeiras linhas, dos titulos, aparacem as bordas das celulas do conteudo dos dados de baixo
Como se a primeira linha tivesse 4 colunas e nao apenas uma..
Tb nao consigo fazer uma linha mais fina como no exemplo do cliente..

Se tivesse uma maneira de carregar a planilha vazia do cliente e preencher omo os dados do arquivo.. tb seria bom..

Obrigado

Exportar para excel com Abas

Enviado: 19 Mai 2019 10:50
por asimoes
a primeira linha você tem que mesclar a celulas de a1 a1

Eu não tenho excel aqui para testar, mas não é difícil fazer essa planilha

Exportar para excel com Abas

Enviado: 19 Mai 2019 10:55
por asimoes
Um exemplo:

Código: Selecionar todos

   oExcel := Win_OleCreateObject( "Excel.Application" ) 

   xlMaximized := -4137
   
   xlMinimized := -4140
   	
   xlNormal    := -4143		
   	
   WITH OBJECT oExcel
      :DisplayAlerts := .F.
      :ScreenUpdating := .F.
      :Visible := .F. 	
      :WorkBooks:Add()
      :Sheets:Add()
      oSheet := :ActiveSheet
   END
   
   HB_CDPSELECT( "PTISO" )
   
   WITH OBJECT oSheet
   
      :Name := "BOLETIM QUANTITATIVO"
      	
      :Cells( 1, 1 ):Select()	
   	  
      :Cells( 1, 2 ):Value := Hb_Eol() + Space(50) + "SECRETARIA MUNICIPAL DE FAZENDA" + ;
      	                     Hb_Eol() + Space(50) + "SUBSECRETARIA DE GESTÃO" + ;
      	                     Hb_Eol() + Space(50) + "GERÊNCIA DE RECURSOS HUMANOS"	
      
      FOR I:=1 TO 2
         :Cells( I, 2 ):VerticalAlignment   := xlVAlignTop
         :Rows(1):RowHeight := 60	
      NEXT  
      	
      oSheet:Range("A1:G4"):Merge()
      
      :Shapes:addPicture("P:\GERAL\HARBOUR\FAZENDA.JPG", 0, 1, 5, 5, 100, 100)
      			
      //:Columns(2):ColumnWidth := 40	
      
      :Cells( 6, 1 ):Value := "CARGOS"
      
      :Cells( 6, 1 ):Borders(2):LineStyle:= 1	
      	
      :Cells( 6, 1 ):Borders(4):LineStyle:= 1	
      
      FOR I:=1 TO 6
         :Cells( I, 1 ):Font:Bold := .T.	
      NEXT
      
      nCol := 2
      	
      FOR EACH oElemento IN aColunas
         IF ! Empty( oElemento[6] )
         	  IF Trim( oElemento[6] ) = "SMF" .OR. Trim( oElemento[6] ) = "GERAL"
               :Cells( 6, nCol ):Value := Trim( oElemento[5] ) + " " + Trim( oElemento[6] ) 
               IF Trim( oElemento[6] ) = "GERAL"
                  :Cells( 6, nCol ):Borders(1):LineStyle := 1
               ENDIF
            ELSE
               :Cells( 6, nCol ):Value := Trim( oElemento[5] ) + "/" + Trim( oElemento[6] ) 	
            ENDIF	   	
         ELSE
            :Cells( 6, nCol ):Value := Trim( oElemento[5]	)
         ENDIF	
         :Cells( 6, nCol ):Font:Bold            := .T.
         :Cells( 6, nCol ):HorizontalAlignment  := Centro
         :Cells( 6, nCol ):Borders(4):LineStyle := 1	
         nCol ++
      NEXT
      
      nLin := 7
      
      FOR EACH oElemento IN aCar
         :Cells( nLin, 1 ):Value                := oElemento
         :Cells( nLin, 1 ):Borders(2):LineStyle := 1
         :Cells( nLin, 1 ):Borders(4):LineStyle := 1
         nCol := 2
         FOR nLot := 1 TO Len( aTotal[ oElemento:__enumIndex ] )
         	  IF aTotal[ oElemento:__enumIndex ][ nLot ] != 0
               :Cells( nLin, nCol ):Value := Str( aTotal[ oElemento:__enumIndex ][ nLot ], 6 )
            ENDIF
            :Cells( nLin, nCol ):Borders(4):LineStyle := 1
            nCol ++
         NEXT
         :Cells( nLin, nCol - 1 ):Borders(1):LineStyle := 1
         nLin ++
      NEXT
      
      :Cells( nLin, 1 ):Value := "TOTAL GERAL"
      
      nCol := 2
      	
      FOR nLot := 1 TO Len( aTotal[Len( aTotal )] )
         IF aTotal[Len( aTotal )][nLot] != 0	
            :Cells( nLin, nCol ):Value := Str( aTotal[Len( aTotal )][nLot], 6 )
         ENDIF
         nCol ++
      NEXT
      
      nColunas := oSheet:UsedRange():Columns():Count
      
      oExcel:Sheets("BOLETIM QUANTITATIVO"):Select()   
      	
      :Columns():AutoFit()	
   END

   WITH OBJECT oExcel	
      :ScreenUpdating          := .T.
      :Application:WindowState := xlMaximized
      :ActiveWorkbook:SaveAs( "D:\TEMP_DRH\BOLETIM", 56 ) // 56 = xls, 61 = xlsx
      :Visible                 := .T.
   END

Exportar para excel com Abas

Enviado: 21 Mai 2019 15:51
por Alexandre Silva
opa
Obrigado , essas propriedades :

:Rows(1):RowHeight := 60 Altura da linha
e oSheet:Range("A1:G4"):Merge()
me ajudaram muito..

Exportar para excel com Abas

Enviado: 04 Jun 2019 15:07
por Alexandre Silva
Nao sei como colocar 2 imagens (logotipos) na planilha..

Uma imagem eu consigo na celula (1,1) ,
Ja na segunda tentativa nao funcionou,
Eu queria a imagem nas 2 paginas ja que tem muitas colunas, a planilha quebra em 2 paginas lado a lado

Código: Selecionar todos

vimagem:='c:\logo.jpg'
oExcel:= TOleAuto():New( "Excel.Application" )
oExcel:WorkBooks:Add()
oSheet:= oExcel:Get( "ActiveSheet" )
oSheet:PageSetup:Orientation  := 2 // 2 paisagem, 1=retrato
oSheet:PageSetup:PrintGridlines := .t.
oSheet:name:='RM 04'
oSheet:Cells:Font:Name := "Arial"
oSheet:Cells:Font:Size := 8
*---
vc1:=10
vc2:=25
vlf:='AO'
oSheet:Cells(1,1):Font:Size := 20
oSheet:Cells(1,1):Font:Bold := .T.
oSheet:Cells(1,1):HorizontalAlignment := -4108  //Centrar nome
oSheet:Cells(1,1):VerticalAlignment := -4108  //Centrar nome
oSheet:Cells(1,1):Value := 'Planejamento e Controle da Produ‡ao'
oSheet:Rows(1):RowHeight := 34
oSheet:Range("A1:V1"):Merge()
oSheet:Cells(1,1):Select()
if file(vimagem)    //
   oSheet:Shapes:addPicture(vimagem, 0, 1, 5, 5, -1, -1)
endif
*------------ 
oSheet:Cells(1,vc2):Font:Size := 20
oSheet:Cells(1,vc2):Font:Bold := .T.
oSheet:Cells(1,vc2):HorizontalAlignment := -4108  //Centrar nome
oSheet:Cells(1,vc2):VerticalAlignment := -4108  //Centrar nome
oSheet:Cells(1,vc2):Value :='Planejamento e Controle da Produ‡ao'
oSheet:Range('W1:'+vlf+'1'):Merge()
if file(vimagem)    // nao funciona  !!!!!!  
   oSheet:Cells(1,vc2):Select()
   oSheet:Shapes:addPicture(vimagem, 0, 1, 5, 5, -1, -1)
endif


Exportar para excel com Abas

Enviado: 24 Jan 2020 12:50
por alemellado
alexandre você na verdade colocou duas vezes a imagem no mesmo lugar, para colocar a segunda imagem deveria ter mudado a coluna onde o excel coloca a imagem
acho que seria mais ou menos isso:
primeira imagem:
oSheet:Shapes:addPicture(vimagem, 0, 1, 5, 5, -1, -1)
segunda imagem:
oSheet:Shapes:addPicture(vimagem, 0, 1, 1060, 5, -1, -1)
aqui o numero 1060 manda colocar a imagem na coluna 1060 e na linha 5

Exportar para excel com Abas

Enviado: 31 Jan 2020 13:37
por bencz

Exportar para excel com Abas

Enviado: 06 Jan 2022 10:45
por kovalsk
O que eu estava procurando foi o que não foi respondido que é salvar a planilha e nem abrir na tela.