Comments (7)
Hi,
There is no properties for getting the Paragraphs, Pictures, Tables and List while maintaining their order in a document.
The properties Pictures, Tables and Lists from Document will return the these elements in 3 distincts lists.
Your closest way of getting those element in order of appearance would be to parse the Document.Paragraphs and look for Pictures/Tables...in each Paragraphs.
Thank you
from docx.
Hi,
thanks for your reply. Could you be a little be more precise on how to identify if there's Pictures or Tables in each Paragraph?
I think it's not possible to get the order even by parsing each Paragraph, because the Tables, the Pictures and the Lists will be given in distinct lists even in each Paragraph - am I wrong?
thanks in advance
from docx.
Hello,
You are right, each paragraph will contain a list of Pictures/Tables...but the read pictures/Tables should be positionned in the order they are read from the ooxml of the document:
var doc = DocX.Load( "test.docx" );
foreach( var paragraph in doc.Paragraphs )
{
var pictures = paragraph.Pictures;
foreach( var picture in pictures)
{
Console.WriteLine( picture.Description );
}
}
Give it a try and see if it works. :-)
Thank you
from docx.
Hello,
thanks for the snippet, but it is not working.
For instance: I have a docx with a table, an empty line and finally another table. I used your code (slightly modified to list tables instead of pictures), but I cannot get in any way the empty line and its order with respect to the tables.
I think a future improvement would be of great importance for a large variety of cases, e.g. copy the content of a document in another by appending it and neglecting the first document formats/headers/footers/etc.
Actually, a document containing table + empty line + table can be appended or inserted in another document only iterating on the same type (pragraph or table or picture).
from docx.
Hi @johnnyontheweb,
I haven't test this with Tables, but I would expect the document to look like:
-a paragraph containing a table
-a paragraph containing an empty line
-a paragraph containing a table
Therefor, parsing the paragraphs would result in the knowing which table appears before the other one.
Or you have another kind of document composition. Could you share your docx so I could test it ?
Currently, DocX offer the possibility to append a document to another document by selecting which header/footer you want in the resulting document (the ones from the source, the ones from the target or keep both of them). Please have a look at Document.InsertDocument() method, it will append or insert a document to another one.
The commercial Xceed Words for .NET will also let you insert a document at a specific position in another document. You can try it for free for 15 days here : https://xceed.com/en/our-products/product/words-for-net
Just tell me if you need something not supported, we could add it to our todo list.
Thank you
from docx.
Thanks, I've already seen Document.InsertDocument() before posting here, but I'm not interested in it, because it does not fit exactly my purposes (in my case, all the layouts that have to be used are the ones from the target document, there's not a choice about headers only).
In any case, I did a complete test of your revised code, and before I was calling Document.Tables. Instead, there's not paragraph.Tables like paragraph.Pictures!
In addition, by copying paragraphs, also the text content of the tables are copied as simple text, outside cells!
I can confirm there's not possible to do what I want
from docx.
Hi,
In Paragraph, there is a property called FollowingTables, which lists the tables following this paragraph, in order they appears.
from docx.
Related Issues (20)
- Large Table building performance in v2.4 HOT 1
- Inserting hyperlinks completes yet resulting file is corrupted HOT 3
- replancetextwithobject error HOT 1
- System.OutOfMemoryException HOT 3
- Writing a long docx file HOT 1
- ReplaceText in Header/Footer broke in v 2.5.0 HOT 3
- KeepWithNextParagraph() is not working with table rows HOT 1
- Inserting HTML not supported HOT 1
- how to insert a audio or other binary files HOT 2
- [Table] Lost cell with InsertRow() fuction HOT 1
- Does the library support "if" conditions?
- Support for multi-type series icons HOT 3
- DocX.ConvertToPdf() does not convert inserted html content. HOT 5
- Replace Tag to image not work HOT 1
- InsertContent as append from Paragraph HOT 3
- Table.IndentFromLeft not working? HOT 4
- Issue Loading ListParagraph when using Document template HOT 1
- No way to add parallel images HOT 1
- Cannot Detect true page count HOT 1
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 docx.