Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The image in the docx document is not displaying. The text wrapping setting needs to be configured. #1453

Open
1 task
ColdCodeHah opened this issue Dec 4, 2024 · 1 comment

Comments

@ColdCodeHah
Copy link

NPOI Version

2.7.2

File Type

  • DOCX

Issue Description

I am using NPOI 2.7.2 in ASP.NET Core 3.1 to insert a JPG image into a specific row using the following code.

foreach (var paragraph in doc.Paragraphs)
{
    foreach (var run in paragraph.Runs)
    {
        if (run.Text.Contains(placeholder))
        {
            run.SetText(run.Text.Replace(placeholder, ""));
            
            using (FileStream ms = new FileStream(imagePath, FileMode.Open, FileAccess.Read))
            {
                var pic = run.AddPicture(ms, (int)PictureType.JPEG, "jpg", imageWidth * 9525, imageHeight * 9525);
            }
            
            paragraph.VerticalAlignment = TextAlignment.TOP;
            paragraph.Alignment = ParagraphAlignment.CENTER;
            break;  // 跳出当前循环,防止重复处理同一段落
        }
    }
}

The saved Word document is shown in the image below.

image

The image is blank and does not display. It needs to be selected, and its text wrapping setting must be configured before it will appear.

@ColdCodeHah
Copy link
Author

If you have time, could you please take a look? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant