martedì 11 novembre 2014

VBA - TimeredShape with FadeIn - FadeOut effect

Oggi inizio la pubblicaizone di alcune procedure VBA che uso con Excel.
Quella di oggi serve per visualizzare una shape, più spesso una casella di testo, per un tempo determinato con un effetto dissolvenza in entrata e in uscita, un po' come quello della nova mail in arrivo di outlook.

Per il funzionamento di questa procedura servono alcune funzioni:

  1. Dichiarare la funzione sleep del kernel, che permetet di definire delle pause in millisecondi senza sprecare cpu.
  2. Procedura FadeInOut, che applica l'efeftto dissolvenza, i parametri sono:
    Oggetto shape al quale applicare l'effetto,
    valore Tree/False per indicare rispettivamente FadeIn o FadeOut,
    durata dell'effetto in msec.
  3. Funzione rgbLum che applica una luminosità in % ad un colore, i parametri sono:
    R,G,B (colore di base), L luminosità compresa tra 0 e 100
  4. Procedura splitRGB traduce nei 3 componenti rgb un colore, i parametri sono:
    l_RGBcolor: colore da trasformare,
    r,g,b: valori in output che conterrano le 3 componenti del colore.


I parametri della procedura principale TimeredShape sono:
Oggetto shape da mostrare;
Tempo di visualizzazione in msec (default 5)
Tempo dell'effetto dissolvenza


[english]
Today I begin the publication of some VBA procedure that I currently use.
TimeredShape is useful for displaying a shape with fadein effect, after waiting for a time in milliseconds hide that with fadeout effect.



Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub FadeInOut(s As Shape, _
              Optional bFadeIN As Boolean = True, _
              Optional lDelayMS As Long = 1000)
Dim i As Integer
Dim iBegin As Integer, iEnd As Integer, iStep As Integer
Dim lDelay As Long
Dim l_Trsp As Long                               ' Final Ttransparency / Trasparenza definitiva
Dim l_ForeColor As Long                          ' Border final color / Colore definitivo bordo
Dim bTrasp As Boolean                            ' Trasparenzy are applicable ? / Trasperenza applicabile ?
Const kScala As Integer = 100
  
  lDelay = CLng(lDelayMS / kScala)               ' Calculate step delay /Calcola il ritardo per ogni step
  Dim r As Integer, g As Integer, b As Integer
  
  l_ForeColor = s.Line.ForeColor                 ' Store line color / Determino il colore dell'oggetto
  splitRGB l_ForeColor, r, g, b                  ' Retrieve r,g,b components / Scompongo i valori RGB
  If s.AutoShapeType <> msoShapeMixed Then       ' Aplly only for fillable shape / Applico solo x shape con proprietà Fill
    l_Trsp = s.Fill.Transparency * kScala        ' Store transparency value / Valore Trasparenza dell'oggetto
    bTrasp = True
  Else
    l_Trsp = 0
    bTrasp = False
  End If
    
  If bFadeIN Then                                ' Define Fade paramters / Definisce i parametri per Fade In e Fade Out
    iBegin = kScala
    iEnd = 0
    iStep = -1
  Else
    iBegin = 0
    iEnd = kScala
    iStep = 1
  End If
  lDelay = lDelay * Abs(iStep)                   ' 
    
  s.Line.ForeColor.RGB = rgbLum(r, g, b, iBegin) ' Initialize colour / Inizializzo il colore
  If bTrasp Then
    s.Fill.Transparency = (l_Trsp + (100 - l_Trsp) * iBegin / kScala) / kScala
  End If
  s.Visible = True                               ' Show shape / Mostra l'oggetto
  For i = iBegin To iEnd Step iStep              ' Fade effect / Effetto dissolvenza
    s.Line.ForeColor.RGB = rgbLum(r, g, b, i)    ' Apply color to border line / Applico il colore alla linea del brodo
    If bTrasp Then                               ' Apply transparency / Applico la trasparenza se esiste fill
      s.Fill.Transparency = (l_Trsp + (100 - l_Trsp) * i / kScala) / kScala
    End If
    DoEvents
    Sleep lDelay
  Next i
  s.Visible = bFadeIN                            ' Show/Hide shape / Mostra/Nasconde oggetto
  If bFadeIN = False Then                        
    s.Line.ForeColor.RGB = l_ForeColor           ' Reapply original colour / Riapplico il colore originale
    If bTrasp Then                               ' 
      s.Fill.Transparency = l_Trsp / kScala      ' Reapply original transparency / Riapplico la trasparenza iniziale
    End If
  End If

    
End Sub
'
' Return color with luminance in % 100=White
' Restituisce il colore corrispondente con una luminosità in %  100%=bianco
'
Function rgbLum(r As Integer, g As Integer, b As Integer, l As Integer) As Long
' Red, Green, Blue, Luminance%
  rgbLum = RGB(r + (255 - r) * l / 100, g + (255 - g) * l / 100, b + (255 - b) * l / 100)
End Function
'
' Retrieve RGC colour component from RGB colour
' Scompone un colore RGB nei 3 componenti
'
Sub splitRGB(lRGBcolor As Long, r As Integer, g As Integer, b As Integer)
Dim s As String
  
  s = Right$("000000" & Hex$(lRGBcolor), 6)
  r = Val("&h" & Mid$(s, 1, 2))
  g = Val("&h" & Mid$(s, 3, 2))
  b = Val("&h" & Mid$(s, 5, 2))
End Sub
' ' Display a shape for a time in msec whith fade effect
' Mostra una shape per i millisecondi indicati + il doppio del tempo di dissolvenza indicato
'
Sub TimeredShape(s As Shape, Optional l_DisplayTimeMS As Long = 5000, Optional l_FadeTime As Long = 2000)
  FadeIn s, True, l_FadeTime
  Sleep l_DisplayTimeMS
  FadeInOut s, False, l_FadeTime
End Sub

mercoledì 22 ottobre 2014

Javascript Date

ENG: This are some usefull javascript date functions. I know that there are so many and best off that, but are the ones I often use in my job, so I decided to share and put them in convenient place.
In javascript  date variables are objects, assignment are by reference not by value, so you can't simply duplicate variable assigning it's value to another. The cloneDate function duplicates variables of date type.

ITA: Ho voluto raccogliere alcune utili funzioni javascript per la manipolazione delle date. Lo sò che ne esistono tante e migliori di queste, ma sono quelle che uso spesso per il mio lavoro, perciò ho deciso di condividerle e di metterle in posto comodo.
In javascript le date sono degli oggetti, l'assegnazione è per riferimento e non per valore, quindi non è possibile duplicare una variabile data assegnando il valore ad un'atra variabile.
La funzione cloneDate serve appunto per duplicare una variabile di tipo data.


cloneDate = function(d) {
// Duplicate Date Type Variable
  var dd = new Date();
  dd.setTime(d.getTime());
  return(dd);
}
yesterday = function() {
  var dd = new Date();
  dd.setDate(dd.getDate()-1);
  return(dd);
}
tomorrow = function() {
  var dd = new Date();
  dd.setDate(dd.getDate()+1);
  return(dd);
}
roundDo = function(d) {
// Arrotonda alla Domenica precedente
// Round date to the previous Sunday
  var dd = cloneDate(d);
  dd.setDate(dd.getDate() - dd.getDay());
  return(dd);
};
roundLu = function(d) {
// Arrotondo al Lunedì precedente
// Round to the previous Monday
  var dd = cloneDate(d);
  dd.setDate(dd.getDate() - 1);
  dd.setDate(dd.getDate() - dd.getDay() +1);
  return(dd);
};
roundMe = function(d) {
// Arrotondo al Mercoledì precedente
// Round to the previus Wednesday
  var dd = cloneDate(d);
  dd.setDate(dd.getDate() + 4);
  dd.setDate(dd.getDate() - dd.getDay() -4);
  return(dd);
};
roundGi = function(d) {
// Arrotondo al giovendì precedente
// Round to the previuos Thursday
  var dd = cloneDate(d);
  dd.setDate(dd.getDate() + 3);
  dd.setDate(dd.getDate() - dd.getDay() -3);
  return(dd); 
};
roundFirst = function(d) {
// Arrotonda la primo giorno del mese
// Round to the first day of month
  var dd = cloneDate(d);
  dd.setDate(1);
  return(dd); 
};
roundLast = function(d) {
// Arrotonda all'ultimo giorno del mese
// Round to the last day of month
  var dd = cloneDate(d);
  dd.setDate(1);
  dd.setMonth(d.getMonth()+1);
  dd.setDate(0);
  var fmtdd=formatDT(dd);
  var fmtM2=formatDT(dateM2);
  if (date.compare(dd, dateM2) > 0){
    dd=dateM2;
  }
  return(dd); 
};
roundLastCompleteMonth = function() {
// Primo giorno dell'ultimo mese completo 
// First day of the last completed month 
  var d = new Date();
  return(new Date(d.getFullYear(), d.getMonth() - 1, 1));
}; 

venerdì 18 luglio 2014

Barcode Encoding (CODE128 e EAN)

Barcode Econdig  in pure PL/SQL 
(without CIABAR32.DLL)

This is a little PL/SQL package contain some function for encode barcode for printing using barcode font. It support only EAN and CODE128, the only I use.
Supported font are ean13.ttf, code128.ttf, CIA128 family and CIA EAN family.
Remeber! CIA font are protected by copyright , uses it only you bought them and you cannot use CIABAR32.dll.

Thanks to grandzebu for some pieces of code.

Your comments, corrections and suggestions are always welcome.

Downlaod Souce code

lunedì 14 luglio 2014

AS_PDF3_V5 new features

AS_PDF3_V5 new features 

Hello everyone, a few days ago I posted the SQL for create PDF document directly from PL/SQL, based on original package by .
Now I've added some new features (version 3.5.2):
  • Procedure query2table now accept CLOB query fields, treat this as images and locate it into array of cells, using horizontal and vertical alignment and risizing if specified.
  • New procedere query2labels that work like query2table but dispose record into multiple columns and rows. The scope is to create sheets with the same label with different contents like a mailing list.
  • Begin of multilanguage errore messages (English or Italian).
  • Added offsetY parameter to columns format type, it works like offsetX, but obviously acts on the ordered. Used in combination with cellRow and tRowHeight, allows the positioning of each individual field in an independent manner.
  • Added a simplified call to query2table and query2label whit colors parameter as a simpliest list of hex rgb colors comma separated,
    for example '000000,e0ffff,000000,000000,ffffff,000000,000000,d0d0d0,000000' .
 2014-11-13. little bugfix on log procedure
 2016-05-11. bugfix on callingh query2table with p_color parameter set to null
 2016-09-06  bugfix in recursive call of write (for text on multiple lines)
comments and corrections, as always, are welcome

Download Ultima versione (0.3.5.11)   Example  Documentation

AS_PDF3_V5 nuove funzionalità

Salve a tutti, qualche giorno fa ho postato il codice SQL per creare documenti PDF direttamente da PL/SQL, basato sul package originale di .
Ora ho aggiunto alcune nuove funzionalià:
  • Procedure query2table: ora la query acetta campi CLOB, li tratta come immagini e li posiziona all'interno della griglia, con la possibilità di allineamento orizzontale, verticale e ridimensionamento se specificato.
  • Nuova procedere query2labels: funziona come query2table, ma dispone i record su colonne e righe miltiple. Lo scopo è di realizare fogli di etichette un po' come farebbe un programma di mailing list per la stampa delle etichette indirizzi.
  • Inizio della gestione degli errori personalizzati con messaggi in Italiano e Inglese.
  • Aggiunto il parametro offsetY al record dei formati colonne, funziona come offsetX, ma ovviamente agisce sulle ordinate. Usato in combinazione con cellRow e tRowHeight, permette di posizionare ogni singolo campo in modo indipendente.
  • Aggiunta una chaimata più semplice per  query2table e query2label dove il parametro dei colori è una semplice lista di colori rgb separata da virgol,
    esempi: '000000,e0ffff,000000,000000,ffffff,000000,000000,d0d0d0,000000' .
2014-11-13. lieve bugfix alla procedura di log
2016-05-11. bugfix con parametro p_color null
2016-09-06  bugfix nelle chiamate ricorsive della procedura write (avvengono per il testo su più righe)
Come sempre commenti e correzioni saranno graditi.

Download Last version (0.3.5.11)    Esempio  Documentazione


Change Log
-------------------------------------------------------------------------------
** Date: 18-09-2014             Version:  0.3.5.03
**   bugfix and impovement suggested by Giuseppe Polo
**   +query2table               added Interline parameter
**    setCellFont               bugfix for Header
** Date: 26-09-2014             Version:  0.3.5.04
**   bugfix for recursive call of function Write
** Date: 29-09-2014             Version:  0.3.5.05
**   +query2table               added pFrame parameter ex:  'L=2pt; C=FF0000'
**                                       where L=Linesize and C=rgb hex colour
**   +query2table               p_colors also accept CSV string of rgb colours   
**   +set_Language              Set language for erorr messages.
**                                       (English, Italian)
**   +put_image                 add parameters p_cellWidth, p_cellheight
**   +Columns                   can contain blob IMAGE 
**   +FullJustify Alignment     for write and query2table functions
**
** Date: 25-11-2014             Version:  0.3.5.06
**   bugfix for query with more than 200 records
**   +query2table               Add optional parameter p_bulk_size:=200
**   +cursor2table              if = 0 buffer is autodetected,
**                              but query runs 2 times!
** Date: 24-06-2015             Version:  0.3.5.07
**   BugFix query2table         Reset rowHeith when
**                              RowHeight Min or Exacat as specified
** Date: 30-06-2015             Version:  0.3.5.08
**   BugFix PrepareRecord       Fix problem with rowHeight
** Date: 26-08-2015                    Version:  0.3.5.09
**   BugFix colorTable                 Fix problem with undefined collection
**   WARNING! if you change package name, propertly set g_package variabile
** Date: 14-12-2015                    Version:  0.3.5.10
**   Bugix in PrepareRecord
** Date: 11-05-2016                    Version:  0.3.5.11
**   Bugix error when calling with null colours
**   colorTable changed and moved before query2Table
**   query2table & query2label changed
**   when calling query2table you must use empty string '' instead of null for p_colors parameter
**

mercoledì 2 luglio 2014

as_pdv3_v5 (english)

PL/SQL package for create PDF

(versione italiana)
Some time ago I found this package to create PDF documents directly from PL / SQL. During this time I added some features for the creation of reports and today I wanted to publish my work.

Your comments, bug indication, correction of english,  are appreciated.



Thank to who made the original package.


Today I've added new features to the procedure query2table, now it accepts blob fields as image and insert it into cell grid, with resizing and alignment, see the NEW POST HERE.

Download my  Lastest vesion  and documentation.


This example create a PDF with breaking on the first field;
it doesn't need table because it uses random data.

-- Created on 25/06/2014 by VALR 
declare 

        i              INTEGER;
        v_vFileName    VARCHAR2(255);
        v_vOddColor    VARCHAR2(6) := 'd0d0d0';
        v_vHeadColor   VARCHAR2(6) := 'e0ffff';
        v_vOraDir      VARCHAR2(50) := 'PDF';
        v_vPageProc    VARCHAR2(32000);
        r_Fmt  as_pdf3_v5.tp_columns:=as_pdf3_v5.tp_columns();
        v_vSQL varchar2(4000);
begin
  v_vFileName    := 'Test_as_pf3_v5.pdf';
  -- Define Sheet Format 
  as_pdf3_v5.init;
  as_pdf3_v5.set_page_format('A4');
  as_pdf3_v5.set_page_orientation('P');
  as_pdf3_v5.set_margins(30, 10, 15, 10, 'mm');
     
  -- Define Header and Footer
  v_vPageProc := q'[
  begin
    §.set_font('helvetica', 'B', 10 );
    §.put_txt('mm',  5, 5, 'Valerio Rossetti');
    §.put_txt('mm',  90, 5, 'Data: ');
    §.set_font('helvetica', 'N', 10);
    §.put_txt('mm', 115,5, ']'||to_char(sysdate,'dd/mm/yy')||q'[');    
    §.put_txt('mm', 175,5, 'Page #PAGE_NR# of #PAGE_COUNT#');
  end;
  ]';
     
  as_pdf3_v5.set_page_proc(v_vPageProc);
  
  --If you use barcode font, remove comment 
  --as_pdf3_v5.load_ttf_font('PDF', 'ean13.ttf', 'CID', TRUE);

    -- Define column format
    begin
      r_fmt.extend(9);
      i:=1; -- (riga di rottura
      r_fmt(i).colWidth:=25;
      r_fmt(i).colLabel:='cod mkt';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='L';
      r_fmt(i).tAlignVert:='B';
      r_fmt(i).tFontSize:=8;
      r_fmt(i).tCHeight := 7;
      r_fmt(i).hCHeight := 7;
      r_fmt(i).cellRow := 1;
      
      i:=i+1;--2
      r_fmt(i).colWidth:=20;
      r_fmt(i).colLabel:='cod_art';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='R';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignVert:='T';
      --r_fmt(i).offsetX := 0;
      r_fmt(i).tCHeight := 7;
      r_fmt(i).hCHeight := 7;
      
      i:=i+1;--3
      r_fmt(i).colWidth:=22;
      r_fmt(i).colLabel:='pz imb';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='R';
      r_fmt(i).tAlignVert:='M';
      
      i:=i+1;--4
      r_fmt(i).colWidth:=12;
      r_fmt(i).colLabel:='udm V';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='C';
      r_fmt(i).tAlignVert:='B';
      r_fmt(i).tBorder := as_pdf3_v5.BorderType('TB');
      
      i:=i+1;--5
      r_fmt(i).colWidth:=15;
      r_fmt(i).colLabel:='udm Lt';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='C';
      r_fmt(i).tAlignVert:='B';
      
      i:=i+1;--6
      r_fmt(i).colWidth:=20;
      r_fmt(i).colLabel:='prz. vend.';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='R';
      r_fmt(i).tAlignVert:='B';
      i:=i+1;--7
      r_fmt(i).colWidth:=20;
      r_fmt(i).colLabel:='prz. cost';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='R';
      r_fmt(i).tAlignVert:='B';
      i:=i+1;--8
      r_fmt(i).colWidth:=16;
      r_fmt(i).colLabel:='margin';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='R';
      r_fmt(i).tAlignVert:='B';
      r_fmt(i).tBorder := 15;
      i:=i+1;--9
      r_fmt(i).colWidth:=150;
      r_fmt(i).colLabel:='product descrition';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='L';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).hCHeight := 8;
      r_fmt(i).tAlignment:='L';
      r_fmt(i).tAlignVert:='C';
      r_fmt(i).tFontSize:=8;
      r_fmt(i).offsetX := 0;
      r_fmt(i).tCHeight := 8;
      r_fmt(i).cellRow:=2;
      r_fmt(i).tBorder := as_pdf3_v5.BorderType('LRBT');

    end;

     v_vSQL := q'[
SELECT cod_mkt,
       c_art, 
       pcs_imb,
       udm_vend,
       udm_list,
       prz_vend,
       prz_vend*.8 prz_cost,
       prz_vend*.2 margin,
       description
from (       
SELECT case when rownum <5 then '5201001' else '5201003' end cod_mkt,
             rownum*1000+rownum*124 c_art, 
             (trunc(rownum/3)+1)*4  pcs_imb,
             'N'  udm_vend,
             'KG' udm_list,
             round(dbms_random.value(40,2),2) prz_vend,
             round(dbms_random.value(8,2),2)  margin,
             'ART '||to_char(rownum*1000+rownum*124) description
        FROM DUAL d CONNECT BY ROWNUM <= 10
)
order by 1
   ]';
   dbms_output.put_line(v_vSQL);
         
   as_pdf3_v5.query2table(v_vSQL,
     r_fmt,
     as_pdf3_v5.tp_colors('000000',v_vHeadColor,'000000',
                          '000000','ffffff','000000', 
                          '000000',v_vOddColor,'000000'),
     15,15, 'mm',0,1
     );
         
    as_pdf3_v5.save_pdf(v_vOraDir, v_vFileName, TRUE);
  END;

mercoledì 25 giugno 2014

as_pdv3_v5 (italiano)

Un package PL/SQL per creare PDF

(english version)
Tempo fa ho trovato questo package per la creazione di documenti PDF direttamente da PL/SQL, con il tempo ho aggiunto alcune funzionalità per la realizzazione di report ed oggi ho voluto pubblicare il mio lavoro.
Ringrazio che ha realizzato il package originale.

La versione descritta di questo post è stata corretta ed aggiornata, consultate il nouvo POST per la descrizione delle nuove funzionalità
Download Codice (ultima versione)  e della documentazione.



questo è un esempio per la creazione di un PDF con rottura sul primo campo;
non ha bisogno di tavole perché usa dati casuali.

-- Created on 25/06/2014 by VALR 
declare 

        i              INTEGER;
        v_vFileName    VARCHAR2(255);
        v_vOddColor    VARCHAR2(6) := 'd0d0d0';
        v_vHeadColor   VARCHAR2(6) := 'e0ffff';
        v_vOraDir      VARCHAR2(50) := 'PDF';
        v_vPageProc    VARCHAR2(32000);
        r_Fmt  as_pdf3_v5.tp_columns:=as_pdf3_v5.tp_columns();
        v_vSQL varchar2(4000);
begin
  v_vFileName    := 'Test_as_pf3_v5.pdf';
  -- FORMATTAZZIONE FOGLIO
  as_pdf3_v5.init;
  as_pdf3_v5.set_page_format('A4');
  as_pdf3_v5.set_page_orientation('P');
  as_pdf3_v5.set_margins(30, 10, 15, 10, 'mm');
     
  -- Definisco Intestazione e piede Pagina
  v_vPageProc := q'[
  begin
    §.set_font('helvetica', 'B', 10 );
    §.put_txt('mm',  5, 5, 'Valerio Rossetti');
    §.put_txt('mm',  90, 5, 'Data: ');
    §.set_font('helvetica', 'N', 10);
    §.put_txt('mm', 115,5, ']'||to_char(sysdate,'dd/mm/yy')||q'[');    
    §.put_txt('mm', 175,5, 'Pagina #PAGE_NR# di #PAGE_COUNT#');
  end;
  ]';
     
  as_pdf3_v5.set_page_proc(v_vPageProc);
  
  --Se vuoi usare dei font per i barcode    
  --as_pdf3_v5.load_ttf_font('PDF', 'ean13.ttf', 'CID', TRUE);

    -- Definizione dei formati
    begin
      r_fmt.extend(9);
      i:=1; -- (riga di rottura
      r_fmt(i).colWidth:=25;
      r_fmt(i).colLabel:='cod mkt';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='L';
      r_fmt(i).tAlignVert:='B';
      r_fmt(i).tFontSize:=8;
      r_fmt(i).tCHeight := 7;
      r_fmt(i).hCHeight := 7;
      r_fmt(i).cellRow := 1;
      
      i:=i+1;--2
      r_fmt(i).colWidth:=20;
      r_fmt(i).colLabel:='cod_art';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='R';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignVert:='T';
      --r_fmt(i).offsetX := 0;
      r_fmt(i).tCHeight := 7;
      r_fmt(i).hCHeight := 7;
      
      i:=i+1;--3
      r_fmt(i).colWidth:=22;
      r_fmt(i).colLabel:='pz imb';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='R';
      r_fmt(i).tAlignVert:='M';
      
      i:=i+1;--4
      r_fmt(i).colWidth:=12;
      r_fmt(i).colLabel:='udm V';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='C';
      r_fmt(i).tAlignVert:='B';
      r_fmt(i).tBorder := as_pdf3_v5.BorderType('TB');
      
      i:=i+1;--5
      r_fmt(i).colWidth:=15;
      r_fmt(i).colLabel:='udm Lt';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='C';
      r_fmt(i).tAlignVert:='B';
      
      i:=i+1;--6
      r_fmt(i).colWidth:=20;
      r_fmt(i).colLabel:='prz. vend.';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='R';
      r_fmt(i).tAlignVert:='B';
      i:=i+1;--7
      r_fmt(i).colWidth:=20;
      r_fmt(i).colLabel:='prz. costo.';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='R';
      r_fmt(i).tAlignVert:='B';
      i:=i+1;--8
      r_fmt(i).colWidth:=16;
      r_fmt(i).colLabel:='margine';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='C';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).tAlignment:='R';
      r_fmt(i).tAlignVert:='B';
      r_fmt(i).tBorder := 15;
      i:=i+1;--9
      r_fmt(i).colWidth:=150;
      r_fmt(i).colLabel:='des.prodotto';
      r_fmt(i).hFontStyle:='B';
      r_fmt(i).hFontSize:=10;
      r_fmt(i).hAlignment:='L';
      r_fmt(i).hAlignVert:='T';
      r_fmt(i).hCHeight := 8;
      r_fmt(i).tAlignment:='L';
      r_fmt(i).tAlignVert:='C';
      r_fmt(i).tFontSize:=8;
      r_fmt(i).offsetX := 0;
      r_fmt(i).tCHeight := 8;
      r_fmt(i).cellRow:=2;
      r_fmt(i).tBorder := as_pdf3_v5.BorderType('LRBT');

    end;

     v_vSQL := q'[
SELECT cod_mkt,
       c_art, 
       pezzi_imb,
       udm_vendita,
       udm_listino,
       prz_vendita,
       prz_vendita*.8 prz_costo,
       prz_vendita*.2 margine,
       descrizione
from (       
SELECT case when rownum <5 then '5201001' else '5201003' end cod_mkt,
             rownum*1000+rownum*124 c_art, 
             (trunc(rownum/3)+1)*4  pezzi_imb,
             'N'  udm_vendita,
             'KG' udm_listino,
             round(dbms_random.value(40,2),2) prz_vendita,
             round(dbms_random.value(8,2),2) margine,
             'ARTICOLO '||to_char(rownum*1000+rownum*124) descrizione
        FROM DUAL d CONNECT BY ROWNUM <= 10
)
order by 1
   ]';
   dbms_output.put_line(v_vSQL);
         
   as_pdf3_v5.query2table(v_vSQL,
     r_fmt,
     as_pdf3_v5.tp_colors('000000',v_vHeadColor,'000000',
                          '000000','ffffff','000000',
                          '000000',v_vOddColor,'000000'),
     15,15, 'mm',0,1
     );
         
    as_pdf3_v5.save_pdf(v_vOraDir, v_vFileName, TRUE);
  END;