admin管理员组

文章数量:1402803

I'm using the Clipboard API to copy styled HTML content with leading spaces into Microsoft PowerPoint, and I found that using a combination of   and mso-spacerun:yes works well — except for the first line (based on this question). For some reason, the indentation of the first paragraph gets collapsed down into at most one space when pasted into PowerPoint.

Here’s the full source code of what I’m doing:

const htmlText =
  // Indented with non-breaking spaces and mso-spacerun
  '<p><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;Three</span></p>' +
  '<p><span style="mso-spacerun:yes">&nbsp;&nbsp;Two</span></p>' +
  '<p><span style="mso-spacerun:yes">&nbsp;One</span></p>' +
  '<p><span style="mso-spacerun:yes">&nbsp;&nbsp;Two</span></p>'+
  '<p><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;Three</span></p>';

async function copyToClipboard() {
  try {
    const data = [
      new ClipboardItem({
        'text/html': new Blob([htmlText], { type: 'text/html' })
      })
    ];
    await navigator.clipboard.write(data);
    console.log('HTML copied to clipboard');
  } catch (err) {
    console.error('Failed to copy HTML:', err);
  }
}

When I paste this into PowerPoint:

  • The second, third, and fourth lines all keep their leading spaces as expected.
  • But the first line loses its indentation and appears left-aligned.

The following shows the result in powerpoint:

Has anyone else run into this?
Is there a workaround or specific formatting tweak that forces PowerPoint to respect the leading spaces on the first paragraph as well?

Thanks in advance!

本文标签: