Date: prev next · Thread: first prev next last
2015 Archives by date, by thread · List index


These may help. Splits your report into separate PDFs. Works on the current document and assumes that your tables start with Group_Header and Detail. Have a look in Navigator to confirm and change thee macro below accordingly.



Sub CopyNamedTable(sName As String, oOrigDoc AS Object, oNewDoc As Object)
    Dim oTable 'Table to copy
    Dim oText 'Document's text object
    Dim oVCursor 'Current view cursor
    Dim o 'Transferable content

    oVCursor = oOrigDoc.CurrentController.getViewCursor()
    oText = oOrigDoc.getText()
    If NOT oOrigDoc.getTextTables().hasByName(sName) Then
        MsgBox "Sorry, the document does not contain table " & sName
        Exit Sub
    End If
    oTable = oOrigDoc.getTextTables().getByName(sName)
    REM Place the cursor in the start of the first cell.
    REM This is very easy!
    oOrigDoc.CurrentController.select(oTable)
    oVCursor.gotoEnd(True) 'Move to the end of the current cell.
    oVCursor.gotoEnd(True) 'Move to the end of the table.
    o = oOrigDoc.CurrentController.getTransferable()

    REM Copy Table into new Document
    oNewDoc.CurrentController.insertTransferable(o)

End Sub


Sub CopyAllTextTables ()

Dim oDoc As Object
Dim Enum As Object
Dim TextElement As Object
Dim noArgs() 'An empty array for the arguments
Dim sURL As String 'URL of the document to load
Dim aProps(0) as New com.sun.star.beans.PropertyValue
Dim strFirstName As String
Dim strLastName As String
Dim strStudentID As String

If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then
   GlobalScope.BasicLibraries.LoadLibrary("Tools")
End If

' Create document object
oOriginalDocument = ThisComponent
sURL = oOriginalDocument.getURL()
DirectoryName = DirectoryNameoutofPath(sURL, "/")
aProps(0).Name="FilterName"
aProps(0).Value = "writer_pdf_Export"

' Create enumeration object
Enum = oOriginalDocument.Text.createEnumeration
' loop over all text elements

While Enum.hasMoreElements
  TextElement = Enum.nextElement

    If TextElement.supportsService("com.sun.star.text.TextTable") Then
REM MsgBox "The current block contains a table called - " & TextElement.TableName
          strTableName=TextElement.TableName
          if (Mid(strTableName,1,5) = "Group") Then
              REM  Create a new swriter Document
              oTable = get_table_by_name(oOriginalDocument, strTableName)

            REM #############################################
            REM The row/column positions may be different in your document
REM The filename should also include StudentID to cater for when
            REM the concatenation of LastName & FirstName is not unique
            REM #############################################

              strFirstName=oTable.getCellByPosition(2,4).getString()
              strLastName=oTable.getCellByPosition(6,3).getString()
              strStudentID = ""
              REM strStudentID=oTable.getCellByPosition(?,?).getString()


            REM ###########################################

            sURL = "private:factory/swriter"
oNewDocument = StarDesktop.LoadComponentFromUrl(sURL, "_blank", 0, noArgs())
CopyNamedTable(strTableName,oOriginalDocument,oNewDocument)
          Else
CopyNamedTable(strTableName,oOriginalDocument,oNewDocument)
sURL = converttourl(DirectoryName & "/" & strLastName & strFirstName & strStudentID & ".pdf")
               oNewDocument.storetoUrl(sURL,aProps())
               oNewDocument.close(true)
          End If
If TextElement.supportsService("com.sun.star.text.Paragraph") Then
              REM Ignore Paragraphs
          End If
    End If

Wend

End Sub





On 29/06/15 13:16, Ed Beroset wrote:
Alex McMurchy wrote:
If that's still a problem edit the report to insert a page break before
"Schedule for".

In fact, using a report turned out to be a viable, if somewhat counterintuitive way to do what I wanted. When I click the "Sorting and Grouping" icon on the Report Builder screen, there is a "Keep Together" selection which I set to "Whole Group." This keeps each schedule on a separate page -- no mail-merge required.

The only unsolved problem is that what I actually wanted is for each schedule to be a separate PDF document that would be emailed to each student (the real database has each student's email address). I imagine that I may be able to solve that with a script (thanks very much for the one you sent -- I'll study it for inspiration!)

It also took me a bit of time to figure out how to place static text on each schedule, but once I realized that the only way to do that was to use label objects, and image objects for the school logo, it was just a matter of fiddling with the placement.

Another thing I noticed was that the filter that I'd set up within the document for my mailmerge attempt was apparently still in effect for the report. It took me a while to figure out why I was only getting a single record printed. Unfortunately there does not seem to be any indication or way to turn the filter off within Report Builder. Instead, I had to go into the document, reset filtering and then return to Report Builder. On one hand, that was not expected, but on the other hand, it was a convenient way to quickly look at a sample without having to generate the entire report each time.

Thanks once again.

Ed



--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.