Jump to content
Fivewin Brasil

FileXLS Fórmulas


informax

Recommended Posts

   Troquei a versão do FileXLS para que meus módulos Funcionem Corretamente no Windows 10 e as Fórmulas não aceitam as variáveis do Harbour. Só não dão erro se elas forem declaradas como Públicas, mas não efetuam Nenhum Cálculo e as Células permanecem em BRANCO. Alguém pode me ajudar ???

 

Link to comment
Share on other sites

Amigunhos,

informax Veja se meu código te dá alguma luz.

	Function XLSTabela()
   LOCAL oExcel, oHoja
   LOCAL nRow := 1, nCol
	   M->NUM_TEMP := STRZERO(RANDOM(9999),4)
   M->DBF_TEMP := cPathDados+"\PN"+M->NUM_TEMP+".DB$"
   M->NTX_TEMP := cPathDados+"\PN"+M->NUM_TEMP+".CD$"
   CursorWait()
	   oExcel := TOleAuto():New( "Excel.Application" )
   oExcel:WorkBooks:Add()
	   oHoja := oExcel:Get( "ActiveSheet" )
   nRows := oHoja:UsedRange:Rows:Count()
   nCols := oHoja:UsedRange:Columns:Count()
	   oHoja:PageSetup:Orientation  := 2
   oHoja:PageSetup:PrintGridlines := .t.
	   // Margens
   oHoja:PageSetup:LeftMargin   := 0.25
   oHoja:PageSetup:RightMargin  := 0.25
   oHoja:PageSetup:TopMargin    := 0.25
   oHoja:PageSetup:BottomMargin := 0.25
   oHoja:PageSetup:HeaderMargin := 0.25
   oHoja:PageSetup:FooterMargin := 0.25
	   // oExcel:WorkBooks:Add() 
   // oSheet = oExcel:ActiveSheet 
   // oSheet:Cells( 1, 1 ):Value = "This is the first page" 
   // oSheet:Rows( 2 ):PageBreak = xlPageBreakManual 
   // oSheet:Cells( 2, 1 ):Value = "This is the second page" 
   // oExcel:Visible = .T. 
	   // Area de Impressao
   oHoja:PageSetup:PrintArea = "$A$1:$O$60"
	   // Area de Impressao
   //oRange := oExcel:Range("A10:A10"):Select()
   //oHoja:HPageBreaks := oRange
   //oRange     := oHoja:Cells(60,15):Select()
   //oHoja:HPageBreaks:Add( oHoja:Range("A60:o60") )
   //oPageBreak:Add( oRange )
   //oHoja:HPageBreaks:Add( oHoja:Cells( 60, 14 ):Select() )
   //oHoja:VPageBreaks:Add( "" )
	   //oHoja:HPageBreaks:Add( "A60" )
   //oHoja:VPageBreaks:Add( "O60" )
	   // Define nome para planilha
   //oHoja:= oExcel:sheets:item(1) 
   oHoja:name:='Tabela de Precos' 
	   //oSheet:Range("A:A"):Set("ColumnWidth",32) // AJUSTA TAMAÑO UN RANGO A UN VALOR 
	   // Toda planilha
   oHoja:Cells:Font:Name := "Arial"
   oHoja:Cells:Font:Size := 8
	   dbSelectArea( "ESTOQUE" )
   @ tableXLS SELECT descricao,valorvenda ;
              FROM estoque TO (DBF_TEMP) 
              USE (DBF_TEMP) ALIAS tableXLS NEW 
              INDEX ON descricao TO (NTX_TEMP)
              SET INDEX TO (NTX_TEMP)
	   // Formatando o titulo
   oHoja:Cells( 1, 1 ):Value := CL_NOME
   oHoja:Cells( 1, 1 ):Font:Size := 24
   oHoja:Cells( 1, 1 ):Font:Name := "Arial"
   oHoja:Range( "A1:O1" ):HorizontalAlignment := 7
   oHoja:Cells( 1, 1 ):Select()
	   nRow := 2
   nCol := 1
   DO WHILE .T. // EOF()
      if nRow = 2
         //oSheet:Range("A:A"):Set("ColumnWidth",32) // AJUSTA TAMAÑO UN RANGO A UN VALOR 
         // Colocando nomes nas colunas
         oHoja:Cells( nRow, nCol+0 ):Value := "DESCRICAO"
         oHoja:Cells( nRow, nCol+1 ):Value := "PRECO"
         oHoja:Cells( nRow, nCol+2 ):Value := "QT"
         // Formatando estilo
         oHoja:Cells( nRow, nCol+0 ):Font:Bold := .T. // :Font:Size / :Font:Color
         oHoja:Cells( nRow, nCol+1 ):Font:Bold := .T.
         oHoja:Cells( nRow, nCol+2 ):Font:Bold := .T.
         // Formatando tamanho
         oHoja:Cells( nRow, nCol+0 ):ColumnWidth := 22
         oHoja:Cells( nRow, nCol+1 ):ColumnWidth := 6
         oHoja:Cells( nRow, nCol+2 ):ColumnWidth := 5
         oHoja:Cells( nRow, nCol+3 ):ColumnWidth := 0.25
         // Formatando tamanho
         oHoja:Cells( nRow, nCol+0 ):Interior:ColorIndex := 6
         oHoja:Cells( nRow, nCol+1 ):Interior:ColorIndex := 6
         oHoja:Cells( nRow, nCol+2 ):Interior:ColorIndex := 6
         //
         nRow := 3
      endif
      // Formatando um campo
      oHoja:Cells( nRow, nCol+0 ):Value := descricao
      oHoja:Cells( nRow, nCol+1 ):NumberFormat := "##.##0,00"
      oHoja:Cells( nRow, nCol+1 ):Value := valorvenda
      // Calcula quantidade * valorvenda
      oHoja:Cells( nRow, nCol+3 ):NumberFormat := "##.##0,00"
      oHoja:Cells( nRow, nCol+3 ):Value := "="+chr(64+nCol+1)+alltrim(str(nRow))+"*"+chr(64+nCol+2)+alltrim(str(nRow))
      // Somatoria dos subtotais
      //oHoja:Cells( nRow, nCol+1 ):NumberFormat := "##.##0,00"
      //oHoja:Cells( nRow, nCol+1 ):Value := "=soma("+chr(64+nCol+2)+"3:"+chr(64+nCol+2)+"57)"
      //
      oHoja:Cells( nRow, nCol+0 ):Font:Bold := .T.
      oHoja:Cells( nRow, nCol+1 ):Font:Bold := .T.
      //
      oHoja:Cells( nRow, nCol+2 ):Interior:ColorIndex := 6
      //
      nRow := nRow + 1
      if eof()
         exit
      endif
      SKIP
   ENDDO
   //
   oHoja:Cells( 59, 1 ):Value        := "SUBTOTAL"
   oHoja:Cells( 59, 1 ):Font:Bold    := .T.
   oHoja:Cells( 59, 1 ):Font:Size    := 10
   oHoja:Cells( 60, 1 ):NumberFormat := "####.##0,00"
   oHoja:Cells( 60, 1 ):Value        := "=B58+F58+J58+N58"
   oHoja:Cells( 60, 1 ):Font:Italic  := .T.
   oHoja:Cells( 60, 1 ):Font:Bold    := .T.
   //
   oHoja:Cells( 59, 5 ):Value        := "DESCONTO"
   oHoja:Cells( 59, 5 ):Font:Bold    := .T.
   oHoja:Cells( 59, 5 ):Font:Size    := 10
   oHoja:Cells( 60, 5 ):NumberFormat := "####.##0,00"
   //oHoja:Cells( 60, 5 ):Value        := "=B58+F58+J58+N58"
   oHoja:Cells( 60, 5 ):Font:Italic  := .T.
   oHoja:Cells( 60, 5 ):Font:Bold    := .T.
   //
   oHoja:Cells( 59, 9 ):Value        := "TOTAL GERAL"
   oHoja:Cells( 59, 9 ):Font:Bold    := .T.
   oHoja:Cells( 59, 9 ):Font:Size    := 10
   oHoja:Cells( 60, 9 ):NumberFormat := "####.##0,00"
   oHoja:Cells( 60, 9 ):Value        := "=A60-(A60*(E60*0,01))"
   oHoja:Cells( 60, 9 ):Font:Italic  := .T.
   oHoja:Cells( 60, 9 ):Font:Bold    := .T.
   //
   dbSelectArea( "ESTOQUE" )
   //
   oExcel:Visible := .T.
   //oHoja:PrintOut() // Funciona OK
   //oExcel:WorkBooks:SaveAs(cFilePath(GetModuleFileName(GetInstance()))+"\FABRICA.xls")
   oHoja:End()
   oExcel:End()
   //
   CursorArrow()
   RETURN

 

Link to comment
Share on other sites

Em 03/03/2022 at 04:04, rochinha disse:

Amigunhos,

informax Veja se meu código te dá alguma luz.

 


	Function XLSTabela()
   LOCAL oExcel, oHoja
   LOCAL nRow := 1, nCol
	   M->NUM_TEMP := STRZERO(RANDOM(9999),4)
   M->DBF_TEMP := cPathDados+"\PN"+M->NUM_TEMP+".DB$"
   M->NTX_TEMP := cPathDados+"\PN"+M->NUM_TEMP+".CD$"
   CursorWait()
	   oExcel := TOleAuto():New( "Excel.Application" )
   oExcel:WorkBooks:Add()
	   oHoja := oExcel:Get( "ActiveSheet" )
   nRows := oHoja:UsedRange:Rows:Count()
   nCols := oHoja:UsedRange:Columns:Count()
	   oHoja:PageSetup:Orientation  := 2
   oHoja:PageSetup:PrintGridlines := .t.
	   // Margens
   oHoja:PageSetup:LeftMargin   := 0.25
   oHoja:PageSetup:RightMargin  := 0.25
   oHoja:PageSetup:TopMargin    := 0.25
   oHoja:PageSetup:BottomMargin := 0.25
   oHoja:PageSetup:HeaderMargin := 0.25
   oHoja:PageSetup:FooterMargin := 0.25
	   // oExcel:WorkBooks:Add() 
   // oSheet = oExcel:ActiveSheet 
   // oSheet:Cells( 1, 1 ):Value = "This is the first page" 
   // oSheet:Rows( 2 ):PageBreak = xlPageBreakManual 
   // oSheet:Cells( 2, 1 ):Value = "This is the second page" 
   // oExcel:Visible = .T. 
	   // Area de Impressao
   oHoja:PageSetup:PrintArea = "$A$1:$O$60"
	   // Area de Impressao
   //oRange := oExcel:Range("A10:A10"):Select()
   //oHoja:HPageBreaks := oRange
   //oRange     := oHoja:Cells(60,15):Select()
   //oHoja:HPageBreaks:Add( oHoja:Range("A60:o60") )
   //oPageBreak:Add( oRange )
   //oHoja:HPageBreaks:Add( oHoja:Cells( 60, 14 ):Select() )
   //oHoja:VPageBreaks:Add( "" )
	   //oHoja:HPageBreaks:Add( "A60" )
   //oHoja:VPageBreaks:Add( "O60" )
	   // Define nome para planilha
   //oHoja:= oExcel:sheets:item(1) 
   oHoja:name:='Tabela de Precos' 
	   //oSheet:Range("A:A"):Set("ColumnWidth",32) // AJUSTA TAMAÑO UN RANGO A UN VALOR 
	   // Toda planilha
   oHoja:Cells:Font:Name := "Arial"
   oHoja:Cells:Font:Size := 8
	   dbSelectArea( "ESTOQUE" )
   @ tableXLS SELECT descricao,valorvenda ;
              FROM estoque TO (DBF_TEMP) 
              USE (DBF_TEMP) ALIAS tableXLS NEW 
              INDEX ON descricao TO (NTX_TEMP)
              SET INDEX TO (NTX_TEMP)
	   // Formatando o titulo
   oHoja:Cells( 1, 1 ):Value := CL_NOME
   oHoja:Cells( 1, 1 ):Font:Size := 24
   oHoja:Cells( 1, 1 ):Font:Name := "Arial"
   oHoja:Range( "A1:O1" ):HorizontalAlignment := 7
   oHoja:Cells( 1, 1 ):Select()
	   nRow := 2
   nCol := 1
   DO WHILE .T. // EOF()
      if nRow = 2
         //oSheet:Range("A:A"):Set("ColumnWidth",32) // AJUSTA TAMAÑO UN RANGO A UN VALOR 
         // Colocando nomes nas colunas
         oHoja:Cells( nRow, nCol+0 ):Value := "DESCRICAO"
         oHoja:Cells( nRow, nCol+1 ):Value := "PRECO"
         oHoja:Cells( nRow, nCol+2 ):Value := "QT"
         // Formatando estilo
         oHoja:Cells( nRow, nCol+0 ):Font:Bold := .T. // :Font:Size / :Font:Color
         oHoja:Cells( nRow, nCol+1 ):Font:Bold := .T.
         oHoja:Cells( nRow, nCol+2 ):Font:Bold := .T.
         // Formatando tamanho
         oHoja:Cells( nRow, nCol+0 ):ColumnWidth := 22
         oHoja:Cells( nRow, nCol+1 ):ColumnWidth := 6
         oHoja:Cells( nRow, nCol+2 ):ColumnWidth := 5
         oHoja:Cells( nRow, nCol+3 ):ColumnWidth := 0.25
         // Formatando tamanho
         oHoja:Cells( nRow, nCol+0 ):Interior:ColorIndex := 6
         oHoja:Cells( nRow, nCol+1 ):Interior:ColorIndex := 6
         oHoja:Cells( nRow, nCol+2 ):Interior:ColorIndex := 6
         //
         nRow := 3
      endif
      // Formatando um campo
      oHoja:Cells( nRow, nCol+0 ):Value := descricao
      oHoja:Cells( nRow, nCol+1 ):NumberFormat := "##.##0,00"
      oHoja:Cells( nRow, nCol+1 ):Value := valorvenda
      // Calcula quantidade * valorvenda
      oHoja:Cells( nRow, nCol+3 ):NumberFormat := "##.##0,00"
      oHoja:Cells( nRow, nCol+3 ):Value := "="+chr(64+nCol+1)+alltrim(str(nRow))+"*"+chr(64+nCol+2)+alltrim(str(nRow))
      // Somatoria dos subtotais
      //oHoja:Cells( nRow, nCol+1 ):NumberFormat := "##.##0,00"
      //oHoja:Cells( nRow, nCol+1 ):Value := "=soma("+chr(64+nCol+2)+"3:"+chr(64+nCol+2)+"57)"
      //
      oHoja:Cells( nRow, nCol+0 ):Font:Bold := .T.
      oHoja:Cells( nRow, nCol+1 ):Font:Bold := .T.
      //
      oHoja:Cells( nRow, nCol+2 ):Interior:ColorIndex := 6
      //
      nRow := nRow + 1
      if eof()
         exit
      endif
      SKIP
   ENDDO
   //
   oHoja:Cells( 59, 1 ):Value        := "SUBTOTAL"
   oHoja:Cells( 59, 1 ):Font:Bold    := .T.
   oHoja:Cells( 59, 1 ):Font:Size    := 10
   oHoja:Cells( 60, 1 ):NumberFormat := "####.##0,00"
   oHoja:Cells( 60, 1 ):Value        := "=B58+F58+J58+N58"
   oHoja:Cells( 60, 1 ):Font:Italic  := .T.
   oHoja:Cells( 60, 1 ):Font:Bold    := .T.
   //
   oHoja:Cells( 59, 5 ):Value        := "DESCONTO"
   oHoja:Cells( 59, 5 ):Font:Bold    := .T.
   oHoja:Cells( 59, 5 ):Font:Size    := 10
   oHoja:Cells( 60, 5 ):NumberFormat := "####.##0,00"
   //oHoja:Cells( 60, 5 ):Value        := "=B58+F58+J58+N58"
   oHoja:Cells( 60, 5 ):Font:Italic  := .T.
   oHoja:Cells( 60, 5 ):Font:Bold    := .T.
   //
   oHoja:Cells( 59, 9 ):Value        := "TOTAL GERAL"
   oHoja:Cells( 59, 9 ):Font:Bold    := .T.
   oHoja:Cells( 59, 9 ):Font:Size    := 10
   oHoja:Cells( 60, 9 ):NumberFormat := "####.##0,00"
   oHoja:Cells( 60, 9 ):Value        := "=A60-(A60*(E60*0,01))"
   oHoja:Cells( 60, 9 ):Font:Italic  := .T.
   oHoja:Cells( 60, 9 ):Font:Bold    := .T.
   //
   dbSelectArea( "ESTOQUE" )
   //
   oExcel:Visible := .T.
   //oHoja:PrintOut() // Funciona OK
   //oExcel:WorkBooks:SaveAs(cFilePath(GetModuleFileName(GetInstance()))+"\FABRICA.xls")
   oHoja:End()
   oExcel:End()
   //
   CursorArrow()
   RETURN

 

 

Muito interessante amigo Rochinha e testarei assim que possível. Muito obrigado.

 

Link to comment
Share on other sites

Amiguinhos,

Andre Meneghetti 

O codigo abaixo é somente um trecho que filtra alguns dados e campos para minimizar o peso de uso das tabelas. Nada impede de colocar suas filtragens som SET FILTER etc.

   @ tableXLS SELECT descricao,valorvenda ;              FROM estoque TO (DBF_TEMP)               USE (DBF_TEMP) ALIAS tableXLS NEW               INDEX ON descricao TO (NTX_TEMP)              SET INDEX TO (NTX_TEMP)	   // Formatando o titulo
	

O resto é código normal.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...