web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Convert HTML to csv/ex...
Power Automate
Unanswered

Convert HTML to csv/excel with formatting style

(0) ShareShare
ReportReport
Posted on by

Hi All,

 

I have to flow like this, i want to convert html to csv / excel file with formatting style. But i don't have clue. 

vividichtarosa_0-1718249557527.png

 

Categories:
I have the same question (0)
  • almharba Profile Picture
    2 on at

    I started by parsing the HTML content and extracting the table data. Then, I used Export-Csv for the CSV part and the EPPlus library for creating an Excel file with formatting. Here's a snippet of how I did it:

     

     

    # Sample HTML content
    $htmlContent = @"
    <table>
     <tr>
     <td style="background-color:#ff5733;">A1</td>
     <td>B1</td>
     <td>C1</td>
     </tr>
     <tr>
     <td>A2</td>
     <td style="background-color:#33ff57;">B2</td>
     <td>C2</td>
     </tr>
    </table>
    "@
    
    # Load HTML and parse it
    [xml]$html = $htmlContent
    $rows = $html.table.tr
    
    # Extract data and style
    $data = @()
    foreach ($row in $rows) {
     $cols = $row.td
     $data += [pscustomobject]@{
     Column1 = $cols[0].'#text'
     Column2 = $cols[1].'#text'
     Column3 = $cols[2].'#text'
     Style1 = $cols[0].style
     Style2 = $cols[1].style
     Style3 = $cols[2].style
     }
    }
    
    # Export to CSV
    $data | Select-Object Column1, Column2, Column3 | Export-Csv -Path "output.csv" -NoTypeInformation
    
    # For Excel with formatting, using EPPlus library
    Import-Module -Name ImportExcel
    
    $excelPath = "output.xlsx"
    $excel = New-ExcelPackage -Path $excelPath
    $worksheet = $excel.Workbook.Worksheets.Add("Sheet1")
    
    # Write data to Excel
    $rowIndex = 1
    foreach ($row in $data) {
     $worksheet.Cells["A$rowIndex"].Value = $row.Column1
     $worksheet.Cells["B$rowIndex"].Value = $row.Column2
     $worksheet.Cells["C$rowIndex"].Value = $row.Column3
     
     if ($row.Style1 -match "background-color:(#[A-Fa-f0-9]{6})") {
     $worksheet.Cells["A$rowIndex"].Style.Fill.PatternType = 'Solid'
     $worksheet.Cells["A$rowIndex"].Style.Fill.BackgroundColor.SetColor([System.Drawing.Color]::FromName($matches[1]))
     }
     if ($row.Style2 -match "background-color:(#[A-Fa-f0-9]{6})") {
     $worksheet.Cells["B$rowIndex"].Style.Fill.PatternType = 'Solid'
     $worksheet.Cells["B$rowIndex"].Style.Fill.BackgroundColor.SetColor([System.Drawing.Color]::FromName($matches[1]))
     }
     if ($row.Style3 -match "background-color:(#[A-Fa-f0-9]{6})") {
     $worksheet.Cells["C$rowIndex"].Style.Fill.PatternType = 'Solid'
     $worksheet.Cells["C$rowIndex"].Style.Fill.BackgroundColor.SetColor([System.Drawing.Color]::FromName($matches[1]))
     }
     $rowIndex++
    }
    
    $excel.Save()

     

    This approach allowed me to keep the cell formatting from the HTML in the Excel output. If you only need a plain CSV without formatting, the Export-Csv cmdlet is straightforward and does the job. contact 

  • vividichtarosa Profile Picture
    on at

    hi @almharba ,

    thanks for your explain, can you explain with power automate action?

  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @vividichtarosa ,

     

    To create a CSV file or an Excel file, we need data in the form of an Array. However, for Power Automate, an HTML Table is just a string and there isn't a built-in method to directly convert an HTML table into an Array. If you want to convert an HTML Table into an array, you need to find a way to parse it and extract the data from it.

     

    I think this link will help you a lot:

    https://powerusers.microsoft.com/t5/Building-Flows/Extract-data-from-an-HTML-table/td-p/2309788

     

    Best Regards,
    Bof

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 632

#2
Haque Profile Picture

Haque 458

#3
Valantis Profile Picture

Valantis 357

Last 30 days Overall leaderboard