BusinessObjects Board

Document Converter (Various formats)

Scott,
Even Rtf doesn’t convert graphs.
The reason why we were trying to save it as text was because some of our clients wanted to recieve the reports in a txt format. I guess to use it with Excel later on.

the whole thing should work better with the new release of BO, I understand that you get a Export to Excel which exports everything: tables, graphs, etc…


Olivier Masse :fr: (BOB member since 2002-08-29)

Hi,

The Add-in works perfectly fine in converting to Xcel. The Format though is not retained after conversion.
Has anybody got any idea or suggestion pls let me know.

regds
Hyder

[Moderator edit to remove duplicate posts]


Hyder (BOB member since 2003-03-26)

Hello Hyder,
you said:

The next BO version should solve the issue if you may believe tehm.
A work around (without my Add-in) is to save it as HTML and open it with excel!!! Yes it’s possible and the layout will stays the same.

Have fun,
Olivier


OlivierV (BOB member since 2002-10-15)

Bump to get this on the list of stuff in the code forum.


Cindy Clayton :us: (BOB member since 2002-06-11)

Yes, it can be done with excel, currently I’m saving the report in a temporary html file, then I open it in Excel (not visible), raise a “save as” dialog to let the user choose filename and location, save it as native excel and kill temporary html file.
The format remains more or less the same, I’ve used HTMLTidy to correct html formatting errors, unhandled by Excel.


pabloj (BOB member since 2003-03-27)

Olivier / Avaksi,

Would you have any interest in having your download hosted here on BOB? We’ve put a new process in place to support storing add-ins / code samples, and I noticed you were hosting the document converter utility yourself. If you would like to have the download hosted here, just reply to this post. If you’d rather keep it the way it is, that is certainly acceptable as well.


BOB Downloads (BOB member since 2003-05-05)

Is there some code that can be added that will hide the bookmark panel when converting to pdf?

Thanks,

Joe


jwiorek (BOB member since 2002-08-15)

I would I convert this addin into a macro to be used within BCA? In other words, if I schedule a document with 20 tabs in BCA and I want this run overnight and produce 20 PDFs (1 PDF/TAB) how do I use this addin and not have a dialog box pop up?


casper_anderson8 (BOB member since 2002-11-27)

Its easier to just use something like the following code to do what you want.

This refreshes and saves all the tabs as pdf on the 'c:\ 'of the server…

Sub morepdf()

    ThisDocument.Refresh
    For i = 1 To ThisDocument.Reports.Count
        ThisDocument.Reports.Item(i).ExportAsPDF ("c:\" & ThisDocument.Name & "_" & ThisDocument.Reports.Item(i).Name)
    Next i

End Sub

avaksi :us: (BOB member since 2002-08-22)

The previously broken download link in this topic has been corrected. The download was previously hosted by the company of one of the authors, but has been moved here to forumtopics.com permanently.


BOB Downloads (BOB member since 2003-05-05)

Hello,

Let me say that this add-in has been very useful over the last few months. I have been excited about migrating to 6.X so we could utilize the Conversion to Excel and keep the graphics, but for now, it does not look like we are going to be upgrading any time soon. As a result, I would like to know if it would be too difficult to modify this converter to save as an Html file with an extension of .xls? My users would be infinitely happy if this were to be done and since my company did not deem the SDK necessary, I am a bit hand cuffed to assist.

A big thank you from those of us stuck in 5.1.X for awhile.


tkdrocks :us: (BOB member since 2003-06-10)

tkdrocks

The process is not as simple as saving the resultant .htm file with .xls extension. BO creates a directory structure for the document you export to html so even if you modify the root file name to a .xls extension that will not solve the problem. This is exacerbated if the document has multiple reports as each report goes into a separate folder when converted to html.

I am writing some code that is separate from the add-in as I don’t want to complicate the converter add-in any further. Please note that I have only tested this code on Win 2000 and version 5.1.6. I have added comments to the code but please feel free to post here if you have any questions or comments.


Sub ConvertHTMtoXLS()
'This procedure creates one xls file for a group of htm reports
On Error GoTo ErrorHandler

    Set Doc = ActiveDocument
    'This is the directory where the html and excel file are created.
    Direct = "C:\"
    Doc.ExportSheetsAsHtml (Direct & ActiveDocument.Name)
    
    Set vbexcel = CreateObject("Excel.Application")
    With vbexcel
        'Create a new workbook to import htm files into
        If Dir(Direct &amp; Doc.Name &amp; "_excel.xls") <> "" Then
            Kill Direct &amp; Doc.Name &amp; "_excel.xls"
        End If
        .Workbooks.Add
        .ActiveWorkbook.SaveAs Direct &amp; Doc.Name &amp; "_excel.xls"
        For i = 1 To Doc.Reports.Count
            Set Rep = Doc.Reports.Item(i)
            repname = convert(Rep.Name)
            .Workbooks.Open Direct &amp; Doc.Name &amp; "\" &amp; repname &amp; "\" &amp; repname &amp; ".htm"
            If Dir(Direct &amp; repname &amp; ".xls") <> "" Then
                Kill Direct &amp; repname &amp; ".xls"
            End If
            .ActiveWorkbook.SaveAs Direct &amp; repname &amp; ".xls"
            'Copy worksheets to the destination Excel document
            .Workbooks(repname &amp; ".xls").Sheets(repname).Move _
            Before:=.Workbooks(Doc.Name &amp; "_excel.xls").Sheets("Sheet1")
        Next i
        .ActiveWorkbook.Save
        .Workbooks.Close
        'Close Excel application object
        .Quit
    End With
    'Release object variable to free memory
    Set vbexcel = Nothing
    'Clean up all interim excel files
    For i = 1 To Doc.Reports.Count
        Set Rep = Doc.Reports.Item(i)
        repname = convert(Rep.Name)
        Kill Direct &amp; repname &amp; ".xls"
    Next i
    
   
    '*********************
    'Open the final report in Excel
    
    Set appwbXL = CreateObject("Excel.Application")
    appwbXL.Visible = True
    
    Set wbXL = appwbXL.Workbooks.Open(Direct &amp; Doc.Name &amp; "_excel.xls")
    wbXL.Activate
    
    '*********************
    
Exit Sub        ' Exit to avoid handler.
ErrorHandler:   ' Error-handling routine.
    MsgBox "Error Number: " &amp; Err.Number &amp; vbLf &amp; "Description: " &amp; Err.Description &amp; vbLf &amp; "Source: " &amp; Err.Source, vbCritical, "Error In Export"
    
End Sub

Function convert(b As String) As String
'This had to be created as html converts all spaces and weird characters to underscores
    repname = ""
    For i = 1 To Len(b)
        If Mid(b, i, 1) = " " Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "$" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "%" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "'" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "-" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "_" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "@" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "~" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "`" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "!" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "{" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "}" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "(" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = ")" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = ":" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "#" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "&amp;" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "+" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "," Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = ";" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "=" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "[" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "]" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "." Then
        repname = repname &amp; "_"
        Else
        repname = repname &amp; Mid(b, i, 1)
        End If
    Next i
    convert = repname
End Function

avaksi :us: (BOB member since 2002-08-22)

Thanks for taking the time to look at this.


tkdrocks :us: (BOB member since 2003-06-10)

Works great, 'tis a beautiful thing. This is much appreciated.


tkdrocks :us: (BOB member since 2003-06-10)

hye !

i’ve got some problem with this code :

i’ve got some Excel files…
there is 3 Excel i would like to make into one

each Excel file is determinate by it name and a department
like this :
rep1-tab1-22.xls
rep1-tab2-22.xls } = > rep-22.xls
rep1-tab3-22.xls /

rep2-tab1-29.xls


Sub ConvertHTMtoXLS(ldpt As String)
' Cette procedure crée 1 fichier xls par groupe de fichiers htm
On Error GoTo ErrorHandler

    Set doc = ActiveDocument
    ' repertoire des fichiers htm et du fichier xls
    Direct = "P:\test\prompt\"
    doc.ExportSheetsAsHtml (Direct &amp; ActiveDocument.Name &amp; "-" &amp; ldpt)
    
    Set vbExcel = CreateObject("Excel.Application")
    With vbExcel
        ' creation d’un nouveau “workbook” pour importer les fichiers htm dedans
        If Dir(Direct &amp; doc.Name &amp; "-" &amp; ldpt &amp; ".xls") <> "" Then
            Kill Direct &amp; doc.Name &amp; "-" &amp; ldpt &amp; ".xls"
        End If
        .Workbooks.Add
        .ActiveWorkbook.SaveAs Direct &amp; doc.Name &amp; "-" &amp; ldpt &amp; ".xls"
        
        'For i = 1 To doc.Reports.Count
            Set Rep = doc.Reports.Item(i)
            repname = convert(Rep.Name)
            .Workbooks.Open Direct &amp; doc.Name &amp; "-" &amp; ldpt &amp; "\" &amp; repname &amp; "\" &amp; repname &amp; ".htm"
            If Dir(Direct &amp; doc.Name &amp; "-" &amp; repname &amp; "-" &amp; ldpt &amp; ".xls") <> "" Then
                Kill Direct &amp; doc.Name &amp; "-" &amp; repname &amp; "-" &amp; ldpt &amp; ".xls"
            End If
            .ActiveWorkbook.SaveAs Direct &amp; doc.Name &amp; "-" &amp; repname &amp; "-" &amp; ldpt &amp; ".xls"
            	‘ Copie la feuille de calcul dans le document Excel cible
            .Workbooks(repname &amp; "-" &amp; ldpt &amp; ".xls").Sheets(repname).Move _
            Before:=.Workbooks(doc.Name &amp; "-" &amp; ldpt &amp; ".xls").Sheets("Sheet1")
        Next i
        .ActiveWorkbook.Save
        .Workbooks.Close
        ' Ferme l’object d’application Excel 
        .Quit
    End With
    ' libère la mémoire
    Set vbExcel = Nothing
    ' supprime  les fichiers Excel qui ne sont plus utile
    For i = 1 To doc.Reports.Count
        Set Rep = doc.Reports.Item(i)
        repname = convert(Rep.Name)
        Kill Direct &amp; doc.Name &amp; "-" &amp; repname &amp; "-" &amp; ldpt &amp; ".xls"
    Next i
        
Exit Sub        ' Exit to avoid handler.
ErrorHandler:   ' Error-handling routine.
    MsgBox "Numero erreur : " &amp; Err.Number &amp; vbLf &amp; "Description : " &amp; Err.Description &amp; vbLf &amp; "Source : " &amp; Err.Source, vbCritical, "Error In Export"
    
End Sub

Function convert(b As String) As String
' transforme tout les caractères spéciaux HTML en “_”
    repname = ""
    For i = 1 To Len(b)
        If Mid(b, i, 1) = " " Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "$" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "%" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "'" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "-" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "_" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "@" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "~" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "`" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "!" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "{" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "}" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "(" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = ")" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = ":" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "#" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "&amp;" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "+" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "," Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = ";" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "=" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "[" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "]" Then
        repname = repname &amp; "_"
        ElseIf Mid(b, i, 1) = "." Then
        repname = repname &amp; "_"
        Else
        repname = repname &amp; Mid(b, i, 1)
  
      End If
    Next i
    convert = rename

End Function

so, this code don’t woks,

i’va got 2 problem.

error number 1004 - do to space and accent in report names…
so, i’ve change it… it’s OK…

error number 9 : “l’indice n’appartient pas à la sélection”
in english : " index does not belong to the selection "

any idea ??? :confused:

thanks.

have a nice day…


jbachet (BOB member since 2004-04-16)

Please comment out the error handler and run this code interactively and give me the line number where the error is taking place. You may wish to add some breakpoints in the code as well (F9).

Please note that I have been using this code for some time now with English names. As you noticed French accents will certainly cause it to break.


avaksi :us: (BOB member since 2002-08-22)

it’s ok for the french accent…

and finaly, i found out an other solution.

i export each report into an Excel file.

then, have a macro xhich create a new Excel file and import each “old” excel file into the new one.


jbachet (BOB member since 2004-04-16)

This is an excellent tool!

If I want to schedule a BO report to BCA: can I have the converter save the report as xls file? Is this possible to use converter? Thanks for your help!

Can ZABO users use the converter tool.

R


BOGURUG :us: (BOB member since 2003-09-15)

This add-in is great and works well with most of the reports; however, when I try to convert some of the reports to xls, it throws ‘Runtime Error 1004’. It is also creating a txt file in the destination along with the xls, but xls has 0 bytes size.

When I click on Debug, it shows the

If Dir(Direct & Rep.Name & “.xls”) <> “” Then
Kill Direct & Rep.Name & “.xls”
End If

in ConvertDocToXLS function.

Not sure if its a bug in the add-in or I am doing something wrong here. Would appreciate the help.

Thanks
JD


JLD (BOB member since 2004-10-13)

Thanks for a really useful tool. It has helped me provide a solution for a user who couldn’t have handled doing manual exports.

Just a word of warning though about a bug to do with regional settings…
There is a minor bug with the converter if you use non US date settings.
To reproduce the bug:
Create a report that brings back date values including:
07/03/2006.
Set your regional settings to be DD/MM/YYYY e.g. UK settings
Convert using Convert to XLS
The date will appear as 03/07/2006 in Excel.

This due to a :roll_eyes: feature in VBA where it applies US regional settings unless you advise otherwise. :reallymad:

The answer is to change the Workbooks.open command to this line:
.Workbooks.Open Direct & Rep.Name & “.txt”, Local:=True
The local:=True forces Excel to use the local regional settings.

There are three lines that need changing to support it.

Thanks again.


robbinma4 :uk: (BOB member since 2005-07-31)