Página 1 de 1

Ler arquivo xlsx com abas

Enviado: 24 Ago 2016 15:04
por Jose Ricardo
Olá pessoal do Grupo.

Preciso de uma ajuda urgente.

Peguei um cliente para desenvolver um programa o qual ele recebe uma planilha xlsx que contém abas.

O sistema precisa ler esta planilha, permitir o cliente selecionar com qual aba irá trabalhar e após selecionar ler linha a linha desta planilha para gerar um txt de cada linha.

Alguém teria um exemplo pratico pra isso?


EDITADO


Já consegui com o samples so que tá acontecendo algo que não consigo solucionar

Na céluar está o valor 156,96 mas retorna 157, ou seja, está arredondado os valores

Ler arquivo xlsx com abas

Enviado: 03 Set 2016 08:26
por Mario Mesquita
Bom dia.

Convém verificar se a variável que recebe o valor da célula não está como inteiro, caso esteja convertida para string ou exportada com string, o que pode provocar o arredondamento.

Sds,
Mario.

Ler arquivo xlsx com abas

Enviado: 03 Set 2016 09:28
por JoséQuintas
Bom... eu uso ADO.... dá pra usar pra MySQL, SQL Server, Postgres, Access, DBF, Arquivo Texto e.... Excel.
Os nomes das abas são fixos?

Código: Selecionar todos

cnExcel:Open()
oDados := cnExcel:Execute( "SELECT * FROM [nomeaba$]" )
DO WHILE .NOT. oDados:Eof()
   ? oDados:Fields( 0 ):Value
   ? oDados:Fields( 1 ):Value
   oDados:MoveNext()
ENDDO
oDados:Close()
cnExcel:Close()

Ler arquivo xlsx com abas

Enviado: 19 Jun 2017 18:40
por depaula.jau
Boa noite!!!

Exporto diversos relatórios para o Excel e na maioria das vezes eles vão muito bem Obrigado.
Mas quando Array é muito Grande e tem vários elementos o uso do FOR deixa o processo muitíssimo lento.

Algum sabe se ha alguma outra forma de exportar os dados para o Excel de um jeito mais pratico ?

Principalmente quando se tem mais que 1000 registros:


Muito Obrigado

Ler arquivo xlsx com abas

Enviado: 19 Jun 2017 18:44
por depaula.jau
PS: Harbour 3.2 + Minigui - Ext + Mysql

Exemplo de uso:

Código: Selecionar todos

             // Cria planilha formato Excel
             oExcel:=CreateObject( "Excel.Application" )
             oExcel:WorkBooks:Add()
             oHoja :=oExcel:ActiveSheet()
             oHoja :Cells:Font:Name:= "Arial"
             oHoja :Cells:Font:Size:= 12
             oHoja :Cells:Font:Bold:= .T.

             oHoja:Cells( 1, 1 ):Value := "RENTABILIDADE SOBRE FATURAMENTO DE PRODUTOS"
             oHoja:Range("A1:T1"):Merge()
             oHoja:Cells( 1, 1 ):HorizontalAlignment:= -4108                    
             oHoja:Range('A1:T2'):Interior:ColorIndex:= 36

             oHoja:Cells( 1, 21 ):Value := "CUSTO DE PRODUÇÃO"
             oHoja:Range("U1:W1"):Merge()
             oHoja:Cells( 1, 21 ):HorizontalAlignment:= -4108                    
             oHoja:Range('U1:W2'):Interior:ColorIndex:= 37

             oHoja :Cells:Font:Name:= "Arial"
             oHoja :Cells:Font:Size:= 10

             // Cria Cabeçalho na planilha
             For i:=1 to Len(aCmp)
                oHoja:Cells(2,i):Value := aCmp[i]
                oHoja:Cells(2,i):Font:Bold := .T.
             Next i
				 
             WaitWindow('Aguarde!, Gerando planilha')               
*            // Mota Linhas detalhes				    
              For i:=1 to oQuery:LastRec()
                 oRow:= oQuery:GetRow(i)
                 nCusto := 0.00

*               // Carrega dados do Emitente
                If cQuebra<>oRow:FieldGet(1)
                   cQuery:="SELECT * FROM tb_cadastros WHERE cd_codigo = "+ClipValueSQL2(oRow:FieldGet(5))
                   xQuery:=oServer:Query( cQuery )
                   ErrorQuery("SELECT","Carrega dados do Emitente")
                   If !xQuery:EOF()
                      xRow:= xQuery:GetRow(1)
                      cUF := xRow:FieldGet(8)
                      xQuery:Destroy()
                   EndIf

                   oHoja:Cells(i+3,1):Value := oRow:FieldGet(1)     // Numero
                   oHoja:Cells(i+3,2):Value := oRow:FieldGet(2)     // Data Emissão
                   oHoja:Cells(i+3,3):Value := oRow:FieldGet(6)     // Cliente
                   oHoja:Cells(i+3,4):Value := cUF                  // UF
                   
					 EndIf
					 	    
*               // Carrega Custo de Produção
                cQuery:="SELECT * FROM tb_saldoestoque WHERE se_codigo = "+ClipValueSQL2(oRow:FieldGet(10))
                cQuery+=" AND se_competencia = "+ClipValueSQL2(STRZERO(MONTH(oRow:FieldGet(2)),2)+STR(YEAR(oRow:FieldGet(2)),4))
                xQuery:=oServer:Query( cQuery )
                ErrorQuery("SELECT","Carrega dados do Emitente")
                If !xQuery:EOF()
                   xRow  :=xQuery:GetRow(1)
                   nCusto:=xRow:FieldGet(4)
                   xQuery:Destroy()
                EndIf

*               // Define Conteudo das celulas                

                oHoja:Cells(i+3,09):NumberFormat:= '##,##0.000'
                oHoja:Cells(i+3,10):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,11):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,12):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,13):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,14):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,15):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,16):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,17):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,18):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,19):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,21):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,22):NumberFormat:= '##.##0,00'
                oHoja:Cells(i+3,23):NumberFormat:= '##.##0,00'


                oHoja:Cells(i+3,10):Value:= 0.00              // Valor Total da Nota 
                oHoja:Cells(i+3,15):Value:= 0.00              // Valor Amostras
                oHoja:Cells(i+3,16):Value:= 0.00              // Valor Bonificação

*               // Verifica o tipo de Emissão da Nota
                If (oRow:FieldGet(3) $ "5101|5102|6101|6102|5116|6116|5551|6551|6110|5110|6125|5125|6122|5122|6109|5109|5124|6124|5108|6108")
                   oHoja:Cells(i+3,10):Value:= oRow:FieldGet(16) - oRow:FieldGet(15) + oRow:FieldGet(25)  // Total Nota
                ElseIf (oRow:FieldGet(3) $ "5910|6910")
                   oHoja:Cells(i+3,16):Value:= oRow:FieldGet(16) - oRow:FieldGet(15) + oRow:FieldGet(25)  // Valor Bonificação
					 ElseIf (oRow:FieldGet(3) $ "5911|6911")
                   oHoja:Cells(i+3,15):Value:= oRow:FieldGet(16) - oRow:FieldGet(15) + oRow:FieldGet(25)  // Valor Amostras
                EndIf

                oHoja:Cells(i+3,5):Value := oRow:FieldGet(19)    // NCM
                oHoja:Cells(i+3,6):Value := oRow:FieldGet(10)    // Produto
                oHoja:Cells(i+3,7):Value := oRow:FieldGet(11)    // Descrição
                oHoja:Cells(i+3,8):Value := oRow:FieldGet(12)    // Unidade
                oHoja:Cells(i+3,9):Value := oRow:FieldGet(13)    // Quantidade
                oHoja:Cells(i+3,11):Value:= oRow:FieldGet(22)    // ICMS
                oHoja:Cells(i+3,12):Value:= oRow:FieldGet(25)    // IPI
                oHoja:Cells(i+3,13):Value:= 0.00                 // PIS
                oHoja:Cells(i+3,14):Value:= 0.00                 // COFINS
                oHoja:Cells(i+3,17):Value:= nCusto               // Custo de Produção
                oHoja:Cells(i+3,18):Value:= oRow:FieldGet(45)    // Custo de Ratio de Frete

                If lCusto 
                   cQuery:="SELECT * FROM tb_custoproducao WHERE cp_codigo = "+ClipValueSQL2(oRow:FieldGet(10))
					    cQuery+=" AND cp_competencia = "+ClipValueSQL2(BOM(cData))
                   xQuery:=oServer:Query( cQuery )
                   ErrorQuery("SELECT","Pesquisando informações de custo")
                   If !xQuery:EOF()
                      xRow :=xQuery:GetRow(1)
                      oHoja:Cells(i+3,19):Value:= Round((xRow:FieldGet(3)+xRow:FieldGet(4)+xRow:FieldGet(5) ) / xRow:FieldGet(7) ,4)  // CIF
                      oHoja:Cells(i+3,20):Value:= Left(xRow:FieldGet(6),7)

                      oHoja:Cells(i+3,21):Value:= Round(xRow:FieldGet(3) / xRow:FieldGet(7) ,4)  // CIF
                      oHoja:Cells(i+3,22):Value:= Round(xRow:FieldGet(4) / xRow:FieldGet(7) ,4)  // CIF
                      oHoja:Cells(i+3,23):Value:= Round(xRow:FieldGet(5) / xRow:FieldGet(7) ,4)  // CIF

                      xQuery:Destroy()
                   Else
						    cQuery:="SELECT * FROM tb_custoproducao WHERE cp_codigo = "+ClipValueSQL2(oRow:FieldGet(10))
						    cQuery+="ORDER BY tb_custoproducao.cp_competencia DESC"    
                      xQuery:=oServer:Query( cQuery )
                      ErrorQuery("SELECT","Pesquisando informações de custo")
                      If !xQuery:EOF()
                         xRow :=xQuery:GetRow(1)
                         oHoja:Cells(i+3,19):Value:= Round((xRow:FieldGet(3)+xRow:FieldGet(4)+xRow:FieldGet(5) ) / xRow:FieldGet(7) ,4)  // CIF
                         oHoja:Cells(i+3,20):Value:= Left(xRow:FieldGet(6),7)

                         oHoja:Cells(i+3,21):Value:= Round(xRow:FieldGet(3) / xRow:FieldGet(7) ,4)  // CIF
                         oHoja:Cells(i+3,22):Value:= Round(xRow:FieldGet(4) / xRow:FieldGet(7) ,4)  // CIF
                         oHoja:Cells(i+3,23):Value:= Round(xRow:FieldGet(5) / xRow:FieldGet(7) ,4)  // CIF

                         xQuery:Destroy()
                      Else
   		         oHoja:Cells(i+3,23):Value:= nCusto
		      EndIf
	   	 EndIf	  					                  
		EndIf
		          
                oHoja:Columns( 1 ) :AutoFit()
                oHoja:Columns( 2 ) :AutoFit()
                oHoja:Columns( 3 ) :AutoFit()
                oHoja:Columns( 4 ) :AutoFit()
                oHoja:Columns( 5 ) :AutoFit()
                oHoja:Columns( 6 ) :AutoFit()
                oHoja:Columns( 7 ) :AutoFit()
                oHoja:Columns( 8 ) :AutoFit()
                oHoja:Columns( 9 ) :AutoFit()
                oHoja:Columns( 10) :AutoFit()
                oHoja:Columns( 11) :AutoFit()
                oHoja:Columns( 12) :AutoFit()
                oHoja:Columns( 13) :AutoFit()
                oHoja:Columns( 14) :AutoFit()
                oHoja:Columns( 15) :AutoFit()
                oHoja:Columns( 16) :AutoFit()
                oHoja:Columns( 17) :AutoFit()
                oHoja:Columns( 18) :AutoFit()
                oHoja:Columns( 19) :AutoFit()
                oHoja:Columns( 20) :AutoFit()
                oHoja:Columns( 21) :AutoFit()
                oHoja:Columns( 22) :AutoFit()
                oHoja:Columns( 23) :AutoFit()
                
             Next i
             WaitWindow()               
             oQuery:Destroy()
             oHoja:Cells( 3 , 1 ):Select()
             oExcel:Visible := .T.

Ler arquivo xlsx com abas

Enviado: 19 Jun 2017 20:20
por JoséQuintas
Talvez exportar e depois formatar?

Código: Selecionar todos

oExcel:Execute( "INSERT INTO Planilha VALUES ( 1, 2, 3, 4 ),  ( 1, 2, 3, 4 ),  ..." )
Talvez XLSWriter ou algo assim?