How to insert table in Modern Pages using PnP Powershell in Office 365/Sharepoint Online?
Hello SharePointers,
Modern pages doesn’t support adding images in a table using text web part. To achieve that, We can use the below Pnp Powershell
Connect-PnPOnline -Url https://mysites.sharepoint.com/sites/Test -Credentials (Get-Credential)
Get-PnPClientSideComponent -Page Image.aspx |Format -Autosize
textWebpart = Get-PnPClientSideComponent -Page Image.aspx -InstanceId 1d5bfd23-766c-4e24-aa34-8e08527a29d7
$textWebpart.Text | clip
$htmlToInject = '
<div class="canvasRteResponsiveTable">
<div class="tableWrapper">
<table title="Table">
<tbody>
<tr>
<td>Name</td>
<td>Dept</td>
<td>City</td>
</tr>
<tr>
<td>Laks</td>
<td>TECH</td>
<td><img src="https://mysites.sharepoint.com/sites/Test/SiteAssets/logo-ota.png" ></td>
</tr>
<tr>
<td>Sethu</td>
<td>TECH</td>
<td><img src="https://mysites.sharepoint.com/sites/Test/SiteAssets/logo-ota.png" ></td>
</tr>
</tbody>
</table>
</div>
</div>
'
Set-PnPClientSideText -Page Image.aspx -InstanceId 1d5bfd23-766c-4e24-aa34-8e08527a29d7 -Text $htmlToInject
You just need to get the table content using get-PnpClientSide Text and manipulate the html contents by adding image tag and set the html content by Set-PnPClientSideText commands. Bravo! Done!
Happy SharePointing 🙂