Coder Social home page Coder Social logo

Comments (7)

mjarczewski avatar mjarczewski commented on May 17, 2024 2

Finally I have a workaround for .netCore.
The problem is in generated document.xml. Following code:
var p0 = doc.Paragraphs[0];
var r0 = p0.CreateRun();
r0.AddPicture(image, 6, "logo.png", Units.ToEMU(width), Units.ToEMU(height));
generates xml node:
<wp:docPr name="Drawing 0" descr="logo.png"/>
Attribute id is missing. When you change this node to:
<wp:docPr name="Drawing 0" id="0" descr="logo.png"/>
everything should work. This happens even if you already have images in your doc and only for first record. I couldn’t find the reason and way to fix it (probably something in export part), but if you change this id to other value it will work:
var p0 = doc.Paragraphs[0];
var r0 = p0.CreateRun();
r0.AddPicture(image, 6, "logo.png", Units.ToEMU(width), Units.ToEMU(height));
var docPr = ((NPOI.OpenXmlFormats.Dml.WordProcessing.CT_Drawing)r0.GetCTR().Items[0]) .inline[0].docPr;
docPr.id = 1000;
This is required only for first image in file. If you have more images following code should work too:
var p0 = doc.Paragraphs[0];
var r0 = p0.CreateRun();
r0.AddPicture(image, 6, "logo.png", Units.ToEMU(width), Units.ToEMU(height));
var docPr = ((NPOI.OpenXmlFormats.Dml.WordProcessing.CT_Drawing)r0.GetCTR().Items[0]) .inline[0].docPr;
docPr.id = 1000;
var p1 = doc.Paragraphs[1];
var r1 = p1.CreateRun();
r1.AddPicture(image2, 6, "cat.png", Units.ToEMU(width2), Units.ToEMU(height2));

from npoi.

LGpan avatar LGpan commented on May 17, 2024

I have the same problem.Have you solved your problem?

from npoi.

DaleBingham avatar DaleBingham commented on May 17, 2024

No I have not yet done that. I see some workaround in the Java version of POI but nothing for the .net core version. I saw a note on "use updated DLLs" for the windows version but I am on Mac OSX.

Sorry just saw this note. Been fixing other things on that same project.

from npoi.

elydium avatar elydium commented on May 17, 2024

Has anyone been able to find a workaround for this in .NET Core?

from npoi.

DaleBingham avatar DaleBingham commented on May 17, 2024

from npoi.

elydium avatar elydium commented on May 17, 2024

Thanks Dale, I'll give it a try.

from npoi.

0xhelium avatar 0xhelium commented on May 17, 2024

Finally I have a workaround for .netCore.
The problem is in generated document.xml. Following code:
var p0 = doc.Paragraphs[0];
var r0 = p0.CreateRun();
r0.AddPicture(image, 6, "logo.png", Units.ToEMU(width), Units.ToEMU(height));
generates xml node:
<wp:docPr name="Drawing 0" descr="logo.png"/>
Attribute id is missing. When you change this node to:
<wp:docPr name="Drawing 0" id="0" descr="logo.png"/>
everything should work. This happens even if you already have images in your doc and only for first record. I couldn’t find the reason and way to fix it (probably something in export part), but if you change this id to other value it will work:
var p0 = doc.Paragraphs[0];
var r0 = p0.CreateRun();
r0.AddPicture(image, 6, "logo.png", Units.ToEMU(width), Units.ToEMU(height));
var docPr = ((NPOI.OpenXmlFormats.Dml.WordProcessing.CT_Drawing)r0.GetCTR().Items[0]) .inline[0].docPr;
docPr.id = 1000;
This is required only for first image in file. If you have more images following code should work too:
var p0 = doc.Paragraphs[0];
var r0 = p0.CreateRun();
r0.AddPicture(image, 6, "logo.png", Units.ToEMU(width), Units.ToEMU(height));
var docPr = ((NPOI.OpenXmlFormats.Dml.WordProcessing.CT_Drawing)r0.GetCTR().Items[0]) .inline[0].docPr;
docPr.id = 1000;
var p1 = doc.Paragraphs[1];
var r1 = p1.CreateRun();
r1.AddPicture(image2, 6, "cat.png", Units.ToEMU(width2), Units.ToEMU(height2));

works, thanku

from npoi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.