Page 1 of 1

XHTML to Docx table borders

PostPosted: Fri Jan 25, 2013 1:03 am
by louffoster
I have a simple XHTML file that I am trying to convert to a docx. The process works, and I get a valid docx file, but I cannot seem to make the tables output *without* borders. I saw a few posts suggesting that the table css have border-top-style = none.

I tried this, but still get borders.
With this CSS in place, I even see the debug log of 'setting borders to none'.

I've tried this with 2.8.0 and 2.8.1.

Here is a simple sample of an html file that has borders in the docX out.

Code: Select all
<html>
    <head>
        <title>roses</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style>
            body {
               margin: 20px;
               font-family: "Times New Roman", Times, serif
            }
            table {
               border: 0;
               border-collapse: collapse;
               border-top-style: none;
            }
            ul {
               list-style: none;
            }
            .num-col {
               width: 65px;
               vertical-align: top;
               color: #BBB;
               font-weight: 100;
               font-size: 0.8em;
               text-align: right;
               padding-right: 10px;
               height: 17px;
            }
         </style>
    </head>

    <body>
      <h3>roses</h3>
       <div id="base-text">
          <table>
<tr><td class="num-col"> </td><td>Roses are crimson</td></tr>
<tr><td class="num-col"> </td><td>Violets are blue and purple</td></tr>
<tr><td class="num-col"> </td><td>Skunk cabbage</td></tr>
<tr><td class="num-col"> </td><td>And so do you too</td></tr>
          </table>
       </div>
       
       <div id="textual-notes">
          <h4>Textual Notes</h4>
          <ul>
                   <li>W1: rose2 - This is the base text.</li>
                   <li>W2: rose1</li>
          </ul>
       </div>
       
       <div id="apparatus">
          <table>
<tr><td class="num-col">1</td><td>crimson] W1; red: W2; </td></tr>
<tr><td class="num-col">2</td><td>and purple] W1; <i>not in </i>W2; </td></tr>
<tr><td class="num-col">3-4</td><td>cabbage And] W1; cabbage stinks And: W2; </td></tr>
<tr><td class="num-col">4</td><td>too] W1; <i>not in </i>W2; </td></tr>
          </table>
       </div>
    </body>
</html>

Re: XHTML to Docx table borders

PostPosted: Thu Jul 04, 2013 6:13 pm
by ivanp
I am facing the same problem too, is there any solution yet?

Re: XHTML to Docx table borders

PostPosted: Thu Jul 04, 2013 8:46 pm
by jason
What happens with a recent nightly build?

Re: XHTML to Docx table borders

PostPosted: Fri Jul 05, 2013 12:36 pm
by ivanp
jason wrote:What happens with a recent nightly build?

Hi jason,
I am using docx4j-nightly-20130702.jar, and using the following code to import xhtml and export as docx
Code: Select all
String inputfilepath = "c:/converted.xhtml";
    XHTMLImporter.setHyperlinkStyle("Hyperlink");
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
   NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
   wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
   ndp.unmarshalDefaultNumbering();
   wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(new File(inputfilepath), null, wordMLPackage));
   Map<String,Style> map = StyleDefinitionsPart.getKnownStyles();
    Collection<Style> col = map.values();
    for(Style s : col)
    {
       wordMLPackage.getMainDocumentPart().getPropertyResolver().activateStyle(s);
    }
   System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));
   //wordMLPackage.save(new java.io.File("c:/test.docx") );
   response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
   response.setHeader("Content-Disposition","attachment; filename=" + new String((fileName+".docx").getBytes("Big5"),"iso8859-1"));
   SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
   saver.save(response.getOutputStream());

and the xhtml contain some table like this:
Code: Select all
<table border="0">
<tbody>
<tr>
<td>Enrollment Id:</td>
<td>%enroll_id%</td>
</tr>
<tr>
<td>Enrolling Date:</td>
<td>%reg_dt%</td>
</tr>
<tr>
<td>Game Category:</td>
<td>%game_cat%</td>
</tr>
<tr>
<td>Team Name:</td>
<td>%team_name%</td>
</tr>
<tr>
<td>Enrolling Donation:</td>
<td>%donation%</td>
</tr>
<tr>
<td>Contact Address:</td>
<td>%contact_address%</td>
</tr>
</tbody>
</table>

And the table border still exist
Thanks for your help

Re: XHTML to Docx table borders

PostPosted: Sat Jul 06, 2013 7:49 pm
by jason
With your table, "<table style="border-top-style: none;">" does the trick.

https://github.com/mr-mig/docx4j/commit ... 862e7c5cf1 is how someone else implemented border="0" handling

cheers .. Jason