Page 1 sur 1

Création dynamic table dans RT

MessagePublié: 27 Oct 2013 à 16:34
par camilleB
Bonjour à tous!
J'essaie de contourner les limitations d'une vue intégrée single cat. dans une form à l'impression. En effet toutes les lignes de la vue ne sont pas imprimées!
J'ai donc décidé de passer par un form avec un RT et de créer un tableau avec les lignes de la vue.
N'ayant aucune expérience avec le RT en LS j'ai fouiné un peu et j'ai trouvé une base qui contenait ce que je voulais avec un peu d'adaptation.

Fonction de création du tableau
Code : Tout sélectionner
Function createReport() As Integer
   On Error Goto errHandler
%REM
Create a 'report' document in this database, create the report table in the new document, and populate the header row.
%END REM
   createReport = True                                                            ' Function returns TRUE unless we hit an error
   
   Dim color As NotesColorObject                                                ' Color object is used for setting cell colors in table
   Dim columnHeader(8) As String                                                ' This array will hold the text for the column titles
   
   ' Dimension the styles array from 1 to the number of columns in the table. Our example table will have 4 columns.
   Dim tableColStyles(1 To 8) As NotesRichTextParagraphStyle
   
   columnHeader(1) = "Date"                                             ' Initialize column header values
   columnHeader(2) = "Type extourne"
   columnHeader(3) = "Libéllé"
   columnHeader(4) = "Num. Facture"
   columnHeader(5) = "Mt HT"
   columnHeader(6) = "TVA"
   columnHeader(7) = "Mt TTC"
   columnHeader(8) = "Mt TTC validé"
   
   Set report = New NotesDocument( db )                                       ' Create new report doc in this database
   report.Form = "FrmPrintExt"      
                                                ' Set new doc to use Report form
   'report.rptTitle = db.Title & " - " & Cstr(Now)                                    ' Stub in a report title
   Set body = New NotesRichTextItem( report, "body" )                           ' Create blank rich text field - this will hold the table
   
   ' To set each column's width, create an array of NotesRichTextParagraphStyle. Each array element corresponds to one column
   ' in the table. This array will be passed to the AppendTable method when the table is created, in order to create a fixed-width
   ' table. Without passing this parameter, the table would be created as an auto-width table.
   
   ' Populate the array of NotesRichTextParagraphStyle - one array element (one NotesRichTextParagraphStyle) for each column.
   
   For i = 1 To COLUMN_COUNT Step 1
      Set tableColStyles(i) = session.CreateRichTextParagraphStyle            ' Create the rt paragraph style for this column
      tableColStyles(i).FirstLineLeftMargin = 0                                    ' Set left margin for the first line of each cell in column
      tableColStyles(i).LeftMargin = 0                                             ' Set left margin for all but the first line of each cell in column
      Select Case i
      Case 1
         ' Each Case corresponds to a table column. Mutiply RULER_ONE_INCH times whatever the column width should be.
         tableColStyles(i).RightMargin = RULER_ONE_INCH * 1
      Case 2
         tableColStyles(i).RightMargin = RULER_ONE_INCH * 1.5
         tableColStyles(i).Alignment = ALIGN_CENTER                           ' Center the 2nd column. This is just to show that you can :)
      Case 3
         tableColStyles(i).RightMargin = RULER_ONE_INCH * 1.5
      Case 4
         tableColStyles(i).RightMargin = RULER_ONE_INCH * 1
      Case 5
         tableColStyles(i).RightMargin = RULER_ONE_INCH * 1
      Case 6
         tableColStyles(i).RightMargin = RULER_ONE_INCH * 1
      Case 7
         tableColStyles(i).RightMargin = RULER_ONE_INCH * 1
      Case 8
         tableColStyles(i).RightMargin = RULER_ONE_INCH * 1
      End Select
      
   Next
   
   ' Create the new table in the rich text field that we added to our new document. The 1st parameter is the number of rows for the table,
   ' the 2nd parameter is the number of columns. We skip the 3rd parameter (array of strings for tab names if this were to be a tabbed
   ' table. We skip the 4th parameter (the left margin for the entire table). The 5th and final parameter is the array of paragraph styles
   ' that was created above - one paragraph style per table column.
   
   Call body.AppendTable( totalRows, COLUMN_COUNT,,, tableColStyles)
   
   Set rtNav = body.CreateNavigator                                                ' Create the NotesRichTextNavigator
   
   ' Move the current position to the 1st element of type TABLE from this rich text item. Of course, since the only table is
   ' the one we created, this moves the current position to the table we created.
   Call rtNav.GetFirstElement(RTELEM_TYPE_TABLE)
   
   ' Now that current position in the rich text item is moved to our new table, we can get a handle to the table
   Set rtTable= rtNav.GetElement()
   
   ' From Notes help: RichTextTable.TABLESTYLE_TOP applies Color to the top row and AlternateColor to all other cells.
   ' The allowed constant values for colors are listed in the Notes Help.
   rtTable.Style = TABLESTYLE_TOP
   Set color = session.CreateColorObject                                          ' Create color object for use in setting cell colors
   color.NotesColor = COLOR_LIGHT_GRAY
   Call rtTable.SetColor( color )                                                   ' Set the top row color to light gray background
   color.NotesColor = COLOR_WHITE
   Call rtTable.SetAlternateColor( color )                                          ' Set all rows after the top row to white background
   
    ' The next lines of code are used to populate the table header row.
   ' Move current position to the first cell of the table. There is no method of the RichTextTable to do this. We have to use the
   ' NotesRichTextNavigator methods to navigate around in the table - or anywhere else in the rich text item. Since we move the
   ' current position to this table earlier, moving to the first TABLECELL puts the current position to the first cell of this table.
   rtNav.FindFirstElement RTELEM_TYPE_TABLECELL                   ' Move to the first cell - row 1, col 1
   body.AppendStyle rtHelv8_Black_Bold                              ' Set the font to Helvetica, 8-point, bold black
   For col = 1 To COLUMN_COUNT Step 1
      ' The BeginInsert method usually moves the insertion point to the specific named element. When the parameter is
      ' a NotesRichTextNavigator element - as it is here - then the insertion point is moved to the beginning of the element
      ' at the current position within the NotesRichTextNavigator. So in this case, the insertion point is moved to the beginning
      ' of the table cell to which we've already navigated.
      body.BeginInsert rtNav
      body.AppendText columnHeader(col)                                 ' Write the text for this column's header
      body.EndInsert                                                         ' Move insertion point to the end of this cell
      rtNav.FindNextElement RTELEM_TYPE_TABLECELL             ' Move to the next cell
   Next
   Call report.Save(True,False)
finally:
   Exit Function
   
errHandler:
   createReport = False
   Dim strErrMsg As String
   Select Case Err
   Case Else
      strErrMsg = "Error #" & Err & Chr$(10) & Error$ & Chr$(10) & "Line #" & Erl & | in sub/function: "| & Lsi_info(2) & |"|
      Msgbox strErrMsg, 16, "Unexpected error"
   End Select
   
   Resume finally
   
End Function

Fonction d'écriture dans le tableau:
Code : Tout sélectionner
Function populateTable() As Integer
   On Error Goto errHandler
   populateTable = True                                                ' Function returns TRUE unless we hit an error
   Stop
   Call body.AppendStyle( rtHelvPlain8 )                              ' Set font to Helvetica, 8 point, black
   
   Set doc = dcUnSorted.GetFirstDocument                              ' Start navigating through the sorted document collection
   'rttable.AddRow
   'Dim rtnav As NotesRichTextNavigator
   'Set rtnav = body.CreateNavigator
   'Call rtnav.FindFirstElement(RTELEM_TYPE_TABLE)
   
   Do Until doc Is Nothing
        ' Populate table with one row of data per document
      
      For col = 1 To COLUMN_COUNT Step 1
         ' The 'createReport' function left the insertion point at the 1st cell of the 2nd row -- the
         ' row after the header row. The BeginInsert method below will place the insertion point at the
         ' beginning of the current element of the NotesRichTextNavigator.
         
         body.BeginInsert rtNav [b]<---- Erreur!!!!!![/b]
         Select Case col                                                ' Populate the detail cells of the table
         Case 1
            Call body.AppendText( doc.dateLigneExtourne(0) )
         Case 2
            Call body.AppendText( doc.TypeLigneExtourne(0) )
         Case 3
            Call body.AppendText( doc.libelleligneExtourne(0))
         Case 4
            Call body.AppendText( doc.numFactureLigneExtourne(0))
         Case 5
            Call body.AppendText( doc.montantLigneExtourneHT(0))
         Case 6
            Call body.AppendText( doc.TypeLigneTVA(0))
         Case 7
            Call body.AppendText( doc.MontantLigneExtourneTTC(0))
         Case 8
            Call body.AppendText( doc.MontantLigneExtourneTTCValide(0))
         End Select
         Call body.EndInsert
         
         Call rtNav.FindNextElement( RTELEM_TYPE_TABLECELL )   ' Move to the next table cell
      Next       
      Set doc = dcUnSorted.GetNextDocument( doc )                  ' Get the next document from the sorted collection
   Loop
   
finally:
   Exit Function
   
errHandler:
   populateTable = False
   Dim strErrMsg As String
   Select Case Err
   Case Else
      strErrMsg = "Error #" & Err & Chr$(10) & Error$ & Chr$(10) & "Line #" & Erl & | in sub/function: "| & Lsi_info(2) & |"|
      Msgbox strErrMsg, 16, "Unexpected error"
   End Select
   
   Resume finally
   
End Function

Tout ce passe bien jusqu'au : body.BeginInsert rtNav qui génère une erreur "Element ou navigation invalide"!
si je rajoute dans la fonction populate ceci: Dim rtnav As NotesRichTextNavigator
Set rtnav = body.CreateNavigator
Call rtnav.FindFirstElement(RTELEM_TYPE_TABLE)
j'insère les données dans la première colonne du tableau!!!
Je n'arrive pas à me mettre sur la ligne suivante dans le tableau. comment faire?

Merci de votre aide je sèche!!!!

Re: Création dynamic table dans RT

MessagePublié: 29 Oct 2013 à 20:37
par camilleB
Bonjour,
ok. les cellules sont parcourues séquentiellement!!! Donc rien qui permettent de se positionner sur une ligne quelconque sauf à calculer la position d'écriture en rajoutant à la
position courante le nb de cellules souhaités.
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL, n)
cdt