Code Monkey home page Code Monkey logo

Comments (4)

valimaties avatar valimaties commented on July 23, 2024

No feedback about this issue?
Seems that first section is filled very fast, but starting with the second section, the fill of the table is very slow.
No one encountered this issue?
Am I doing something wrong?

from docx.

XceedBoucherS avatar XceedBoucherS commented on July 23, 2024

Hi,

Try using the table insertion in the docx after filling the table's Paragraph :
var p = sec.InsertParagraph(); p.InsertTableAfterSelf( table );
after the Append of "FieldX".

It should works.

I don't see this table filling being slow.
Thank you.

from docx.

valimaties avatar valimaties commented on July 23, 2024

I've tried your solution, but the table is append with all those rows as empty rows. But if I add the table in the doc before starting the population-loop, the paragraphs are displaying correctly after opening the docx file. Only that the populating job is very slow for the second section. And even slower for the next section, and so on...
Please make a test, with some random data. Fill a table with 1000 records, and group them in three sections, like three sub-tables. And try to populate after that a docx table for each datatable, in separate sections. For me it works very slow from the second section to the last one. And if I don't find a solution, I must find another way to save the data to a docx file, unfortunatelly, because I cannot wait 5 minutes for 1000 rows in a datatable. Is too much for me. 🙏

PS: I think something is happening with the latest version, because if I remember well, the version before didn't had the same lag.

from docx.

XceedBoucherS avatar XceedBoucherS commented on July 23, 2024

Hi,
I agree with you, 5 min of waiting is not acceptable. There could be something different in the latest version.

Could you build up the test you are talking about in the preceding post?
This way, I would test the same sample as you.
When I test something like the initial post of this thread, I don't see anything slow. Here's my sample :
`var doc = DocX.Create( "test.docx" );
var counter = -1;
while( ++counter < 4 )
{
doc.InsertSection();
}
var sec = doc.Sections[ 0 ];
for( int k = 0; k < 4; k++ )
{
sec = doc.Sections[ k ];
sec.PageLayout.Orientation = Orientation.Landscape;
sec.PageNumberType.PageNumberStart = 1;
sec.PageWidth = 800;
sec.MarginLeft = 20;
sec.MarginRight = 20;
sec.MarginTop = 20;
sec.MarginBottom = 20;
sec.InsertParagraph( "test" + k ).SpacingBefore( 20d ).Font( "Arial" ).FontSize( 10 ).Bold().SpacingAfter( 10d );
var table = doc.AddTable( 2, 9 );
table.SetTableCellMargin( TableCellMarginType.left, 1 );
table.SetTableCellMargin( TableCellMarginType.right, 1 );
table.SetTableCellMargin( TableCellMarginType.top, 1 );
table.SetTableCellMargin( TableCellMarginType.bottom, 1 );

    //table.Design = TableDesign.LightGrid;
    var headerRow = table.Rows.First();
   // headerRow.TableHeader = true;
    headerRow.Cells[ 0 ].Paragraphs[ 0 ].Append( "Field1" ).Bold().FontSize( 10 );
    headerRow.Cells[ 1 ].Paragraphs[ 0 ].Append( "Field2" ).Bold().FontSize( 10 );
    headerRow.Cells[ 2 ].Paragraphs[ 0 ].Append( "Field3" ).Bold().FontSize( 10 );
    headerRow.Cells[ 3 ].Paragraphs[ 0 ].Append( "Field4" ).Bold().FontSize( 10 );
    headerRow.Cells[ 4 ].Paragraphs[ 0 ].Append( "Field5" ).Bold().FontSize( 10 );
    headerRow.Cells[ 5 ].Paragraphs[ 0 ].Append( "Field6" ).Bold().FontSize( 10 );
    headerRow.Cells[ 6 ].Paragraphs[ 0 ].Append( "Field7" ).Bold().FontSize( 10 );
    headerRow.Cells[ 7 ].Paragraphs[ 0 ].Append( "Field8" ).Bold().FontSize( 10 );
    headerRow.Cells[ 8 ].Paragraphs[ 0 ].Append( "Field9" ).Bold().FontSize( 10 );

    var p = sec.InsertParagraph();
    p.InsertTableAfterSelf( table );
  }

  doc.Save();`

Thank you for your help

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.