Comments (7)
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.
I have the same problem.Have you solved your problem?
from npoi.
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.
Has anyone been able to find a workaround for this in .NET Core?
from npoi.
from npoi.
Thanks Dale, I'll give it a try.
from npoi.
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)
- Word document from .dotx Template
- NPOI version 1.2.2 not working with alpine 2.2
- Memory leak issue HOT 2
- A large amount of data is exported to excel
- [Word/*.docx] Can't set the correct font size
- [Word/.docx] How to clear a Cell in Word HOT 1
- Excel ICellStyle.Rotation not working
- create a new xlsx and write to memory stream HOT 5
- support for .net core 3.1
- In Excel, Result of GetPrintArea sometimes is null.
- How to set Date Range by NPOI?
- 插入图片无法设置格式 HOT 2
- 这个项目已经死亡了吗? HOT 2
- Please feedback issue to https://github.com/tonyqus/npoi
- Cannot "change" excel file
- @2.5.1 misbehavior of Comparision.Operator at DVConstraint.CreateDateConstraint for LibreOffice Calc v7.0.0.3(x64) HOT 2
- adding picture corrupts word document
- XSSFPicture.Resize method locks application execution
- Probleme witch docx
- Cannot update file - error in a saved excel file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from npoi.