Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7594355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:23:43+00:00 2026-05-30T21:23:43+00:00

I’m working on a Microsoft word 2007 Document. my Objectives are to fill :

  • 0

I’m working on a Microsoft word 2007 Document.

my Objectives are to fill :

  1. Table cell.
  2. A Paragraph line.

so,my code does this work but the problem is when i write the file using FileOutputStream, it writes only one of my objectives (the last modification only).

here is an Image of the Header :

enter image description here

and here is the code i used :

    try{

InputStream input = new FileInputStream("c:\\doslot.docx");
XWPFDocument document=new XWPFDocument(input);
 //*********************inserting the 2nd line**************************
  XWPFHeader head = document.getHeaderList().get(0);
    List<XWPFParagraph> para= head.getParagraphs();
    XWPFRun pararun=para.get(0).createRun();
    pararun.setText("DOSSIER DE LOT GLUSCAN® N°FG-4040400A");
 //*********************inserting the header thrid table cell*************************
   XWPFHeader headd = document.getHeaderList().get(1);
    List<XWPFTable> tables = headd.getTables();
    List<XWPFTableRow> rows = tables.get(0).getRows();
  XWPFTableCell cell =    rows.get(0).getTableCell(rows.get(0).getTableCells().get(3).getCTTc());
    XWPFParagraph p =cell.addParagraph();
    XWPFRun pararuno=p.createRun();
    pararuno.setText("some text");


    FileOutputStream out = new FileOutputStream("c:\\fin.docx");
    document.write(out);
    out.close();


     }catch(Exception ex){
         ex.printStackTrace();
     }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:23:44+00:00Added an answer on May 30, 2026 at 9:23 pm

    The problem is that List<XWPFTableCell> cell = rows.get(0).getTableCells(); returns newly created list, XWPFTableRow.getTableCells() says:

    create and return a list of all XWPFTableCell who belongs to this row

    And ofcourse comments do lie, while code does not, so sources say:

    public List<XWPFTableCell> getTableCells(){
        if(tableCells == null){
            //Here it is created
            List<XWPFTableCell> cells = new ArrayList<XWPFTableCell>();
            for (CTTc tableCell : ctRow.getTcList()) {
                cells.add(new XWPFTableCell(tableCell, this, table.getPart()));
            }
            this.tableCells = cells;
        }
        return tableCells;
    }
    

    And for your help there is a XWPFTableRow.getTableCell(CTTc cell), where you pass CTTc cell, and method definitely returns an existing object:

    public XWPFTableCell getTableCell(CTTc cell) {
        for(int i=0; i<tableCells.size(); i++){
            if(tableCells.get(i).getCTTc() == cell) return tableCells.get(i); 
        }
        return null;
    }
    

    You can achieve CTTc cell by invoking XWPFTableCell.getCTTc() and then modify it directly.

    The code to directly access existing cell would be:

    XWPFTableCell cell = 
        rows.getTableCell(rows.get(0).getTableCells().get(3).getCTTc());
    

    I did not try or compile this code, so I am not sure if it is correct, but I trust my OO knowledge and sources. By all means this should do it. If it does – please correct the code to make sure it is correct and compilable.

    FTR, I think that there should be more convenient way doing this, it is quite common to edit the cells and I think it should not be so complicated, I would suggest trying some tutorials on XWPFTable and its manipulation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I need to clean up various Word 'smart' characters in user input, including but
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.