Merge HTML files RRS feed

  • Question

  • Hello Everyone,

    I have a powershell script  that generates me an HTML file.

    The last line of the script is the following:

    ConvertTo-HTML -head $head -PostContent  $VAR1,$VAR2,$VAR3,$VAR4,$VAR5 ,$VAR6,$VAR7| Out-File -FilePath "c:\temp\Test1.html"

    No problem there. the test1.html is being generated without problems.

    Now, below the last line of the script i added the following in order to import an excel file from Sharepoint and convert it to HTML:

    $xlWorkbookxHtml = 44

    $excel = New-Object -ComObject excel.application
    $excel.visible = $false
    $folderpath = "https://Sharepoint.com/ExcelFile1.xlsx?Web=1"
    $workbook = $excel.workbooks.open($folderpath)

    $workbook.saveas("C:\temp\Test2.html", $xlWorkbookxHtml)

    $excel = $null

    There is no problem with the generation of that Test2.html file.
    It ´s being generated without problem in C:\Temp\Test2.html

    Now, the problem appears when i want to merge/combine those two HTML file into HTML file

    I´m using :

    (Get-Content "C:\temp\test1.html") + (Get-Content "c:\temp\test2.html") | Set-Content "C:\temp\Combined.html"

    Simply its ignoring the test2.html and in the combined.html just appears the content of the test1.html.

    Any idea? or any suggestion on how can i combine these two files? (I´m running it in Windows 7 or Windows 10 machines)
    Thank you in advance for your time and support.

    • Edited by Sebastian87 Sunday, November 18, 2018 4:52 AM
    Sunday, November 18, 2018 4:51 AM

All replies

  • I just realized that if generate the TEST2.HTM (instead of .HTML) file using the script below, then the GET-CONTENT funcion works OK and the  TEST1.HTML + TEST2.HTM are combined OK in the COMBINED.HTML file.

    I suspect that is related due to in the case of the TEST2.HTM is generated converting the XLSX file to CSV and then HTM....

    The new problem that i have, is that this TEST2.HTM as converted from CSV...is not respecting the colours and the format of the source XLSX file...and not looks so good the HTM....

    #Create and get my Excel Obj
    $excel = New-Object -comobject Excel.Application
    $UserWorkBook = $excel.Workbooks.Open("https://Sharepoint.com/ExcelFile1.xlsx?Web=1")

    #Select first Sheet
    $UserWorksheet = $UserWorkBook.Worksheets.Item(1)

    #HitList File name and type
    $hitlistCSV = "C:\temp\Test2.csv" #changed-grav
    $hitlistHTML = "C:\temp\Test2.htm" #changed-grav
    $xlCSV = 6  #changed-grav

    #Save, close, and clean up
    $UserWorksheet.SaveAs($hitlistCSV,$xlCSV) #changed-grav
    $excel = $null

    #new functionality, to import the CSV and then export as HTM
    #added-grav START
    $htmlData = Get-Content $hitlistCSV | ConvertFrom-CSV | ConvertTo-HTML
    Set-Content $hitlistHTML $htmlData
    Remove-Item $hitlistCSV
    #added-grav END

    Sunday, November 18, 2018 6:38 AM
  • This:

    $htmlData = Get-Content $hitlistCSV | ConvertFrom-CSV | ConvertTo-HTML
    Set-Content $hitlistHTML $htmlData

    Should be this:

    Import-Csv $hitlistCSV  | ConvertTo-HTML | Out-File $hitlistHTML

    TO merge html generate fragments and combine them using ConvertTo-Html

    help ConvertTo-Html  -Par Fragment


    Sunday, November 18, 2018 9:47 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,


    Just do it.

    Tuesday, November 27, 2018 2:45 AM