Coder Social home page Coder Social logo

Comments (7)

XceedBoucherS avatar XceedBoucherS commented on June 8, 2024

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.

johnnyontheweb avatar johnnyontheweb commented on June 8, 2024

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.

XceedBoucherS avatar XceedBoucherS commented on June 8, 2024

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.

johnnyontheweb avatar johnnyontheweb commented on June 8, 2024

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.

XceedBoucherS avatar XceedBoucherS commented on June 8, 2024

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.

johnnyontheweb avatar johnnyontheweb commented on June 8, 2024

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.

XceedBoucherS avatar XceedBoucherS commented on June 8, 2024

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)

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.