question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AddAlternativeFormatImportPart - AlternativeFormatImportPartType.Html = generate empty line

See original GitHub issue

I have the following method to add an HTML content

public static void AddHtml(this Paragraph paragraph, WordprocessingDocument doc, string content)
{
    var ms = new MemoryStream(new UTF8Encoding(true).GetPreamble().Concat(Encoding.UTF8.GetBytes($"<html>{content}</html>")).ToArray());

    string altChunkId = "div_" + new Random().Next(int.MinValue, int.MaxValue);
    var part = doc.MainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Html, altChunkId);
    part.FeedData(ms);

    paragraph.Append(new Run(new AltChunk { Id = altChunkId }));
}

however it is always generating an extra line right after the HTML content image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
drma-devcommented, Nov 2, 2021

yes

1reaction
drma-devcommented, Oct 29, 2021

was not it. I had to add to body before changing the paragraph.

protected static void AppendParagraphHtml(WordprocessingDocument doc, string content)
{
    var paragraph = new Paragraph();

    doc.MainDocumentPart.Document.Body.AppendChild(paragraph);

    paragraph.AddHtml(doc, content);           
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

AlternativeFormatImportPartType.Html = generate empty ...
I have the following method to add an HTML content public static void AddHtml(this Paragraph paragraph, WordprocessingDocument doc, string content) { var ms ......
Read more >
C# Open XML HTML to DOCX Spacing
AddAlternativeFormatImportPart (AlternativeFormatImportPartType.Html ... (This prevents an empty First Line) mainDocumenPart.Document.Body.
Read more >
I need to add a style in a word document by creating ...
I am creating a word doc with below code:- private void OpenWordDocument(DataTable dataTable, string xlsxFilePath, string xlsxReportTitle, ...
Read more >
Convert HTML string from database to Word document ...
I am working on a project in asp.net with c#. I take data from mysql database in html format but I need to...
Read more >
html to Word Document Converter using Open XML SDK
AddAlternativeFormatImportPart (AlternativeFormatImportPartType.Html, altChunkId); using (Stream chunkStream = chunk.GetStream(FileMode.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found