How to split table cells in Open Xml? - openxml

I have a document with a table. I need to be able to add columns to a specific row, while maintaining the original table width.
Essentially I need to SPLIT table cells. How can I do this using open xml for a word document?
I tried
var tc = new TableCell();
tc.Append(new Paragraph(new Run(new Text("Hi"))));
row.Append(tc);
I tried just adding more cells, however it acts as new column and increases the size of the table.

First of all create a table in microsoft word and split cell there. Now open your word document in OpenXML SDK Development Tool which can be downloaded from here. If you look at the relevent cell in OpenXML, you will find the answer to your problem. Just copy code from OpenXML and make any necessory changes according to your requirements.

Related

Conditional Formatting in Microsoft Word 2016 Table Cells

I have a table and it is for a test plan I am doing for a project, there is a column at the end of the table where the 2 values in it will be Y (passed the criteria) or N (didn't pass the criteria)
Is there a way in Microsoft Word to change the colour of the text on the row with the value of N at the end, this makes it easier to spot the places where it failed the criteria.
I know you can do the find and replace method but I was wondering if there was a way to do this automatically so when the user enters N it changes the whole row to red and when they enter Y it changes it back to normal.
Here is a screenshot of my table:
A point in the right direction to an article I may have missed or a direct answer would be greatly appreciated, thanks.
I see four ways you can go from here:
Either you create a VBA Macro which automatically jumps in once you change something in your document and updates the table. This will force you to save the document with the file extension *.docm.
Or you create two styles (of type character) which automatically format the table Cell and it's content as you like. You would need to guide the users how to use those styles by advising them or you could also provide separate buttons within your document to call a macro which would apply those styles. Also here the macro option would force you to save the document with the file extension *.docm.
Another option would be to use a Word document with an OLE Microsoft Excel object. The drawback is the users would need to know how to use this embedded Excel object.
The third way you could go is to use Microsoft Excel and use the inbuilt Conditional Formatting of Excel. If you need the results to be in a Word document you would still be able to copy the table back to Word.
Note:
I especially mention the document file extension *.docm because this can cause your document to appear dangerous when you send it by email. Perform a google search to read more about Microsoft Office documents containing macros.

How to make repeated content control through OpenDoPE add-in

I have table with one row of content controls. I need to repeat the row as per the data xml using OpenDoPE add-in of MS Word
See the below table and xml mapping which I have done.
Currently there is one row node in xml so one row of content-control is enough. But when I add more row nodes in xml the content control is not repeating.
Help me to resolve this
Looks like you are using the "first/oldest" AddIn from https://opendope.org/implementations.html
There is a description of how to use it at http://www.opendope.org/WordAddIn_walkthrough.pdf
But you are probably better off using http://www.opendope.org/downloads/authoring-friendly/setup.exe which uses the drag/drop approach Microsoft introduced in Word 2013.
This answer uses that. (Before installing it, first uninstall the old one, using Windows "Programs and Features").
Using sample XML:
<myxml>
<rows>
<row>
<name>Abh</name>
<company>Standout</company>
<designation>Dev</designation>
</row>
<row>
<name>Name2</name>
<company>Co2</company>
<designation>Design2</designation>
</row>
</rows>
</myxml>
(note the rows element) and name, company and designation already mapped as per your question:
select the table row, then in the XML Mapping task pane, right click on row (ie the first of the siblings to be repeated, not the parent), choose Repeat > Insert Content Control:
In Design Mode, you should now see:
(note the od:repeat around the three table cells)
Save the docx, then you can try using https://github.com/plutext/docx4j/blob/master/src/samples/docx4j/org/docx4j/samples/ContentControlBindingExtensionsOld.java (update line 69 to point at your docx).
Any way I found myself a solution to this. The problem was regarding the designing of repeated content control in my template docx. I just created a rich text content control and placed my entire row (which contains the name, company, designation content controls) inside it and mapped as repeated. This resolved my problem. See the below content control design
Here is the xml mapping of name field
here is the xml mapping of repeated content controll (row)

How to create a row record with a word attachment in a table?

In my java web jsf seam jboss application, I want to add a row in a table with some data fields such as date type, String etc, but one field will be a word attachment, does anybody know any example of how to do it? thanks a lot for any help,
Basically, there is a loop to create some rows of data in a table, before each table row data creation, I will create a word file and saved to a local path(the physical file path is hardcoded), then I will create a table row and attach this word file to that row. the loop will continue until the end of loop.
I appreciate if anybody can know any resource or example codes.
Thanks a lot,

Selecting different columns in SWT Table, using JFace TableViewer

I have a 2-column SWT Table that uses TableViewer. Trouble is that I can only select (and edit) cells in the first column -- clicking on the second column does nothing.
I read from somewhere (lost the link) that there's no easy way to get such functionality (!) -- you're supposed to mess around with several extra concepts if you want to select (and edit) different columns in your table.
This snippet
(http://www.goneeded.com/snippet/eclipse/JFace/Viewers/Snippet035TableCursorCellHighlighter.html)
seems to be relevant, but it's not clear which part of it is necessary and it has depenendencies to other snippets. I tried to get it working but it did nothing.
Seems that new table editing and cell-selecting features were added in Eclipse 3.3 -- is there a tutorial or smth available on how to use them? The snippets are too cryptic for me.
You should be able to edit and select cells independently. You might have the SWT.FULL_SELECTION style bit set on the Table constructor. That forces every selection to span the whole row instead of a single cell.
I'd check out this tutorial for more on TableViewers:
http://www.eclipse.org/articles/Article-Table-viewer/table_viewer.html

PdfpTable vs. Table (vs. SimpleTable?)

I am writing code that generates both PDF and RTF documents, depending on the user's selection. The information in both documents is the same.
Until now, we were using classes like Table, Cell, HeaderFooter, etc., which are rendered into the correct form by the documentwriter (either PdfWriter or RtfWriter2).
However, the further I get into trying to make changes (mostly because the upgrade to iText 2.1 left the spacing a little quirky), the more I'm being told to "use PdfpTable", or "Use pageEvents to set headers". It seems like a lot of the generic classes are being deprecated.
I am thinking of revamping the code to separate out the table creations for PDF and RTF. However, all the iText tutorial stuff seems to actually recommend using Table in an instance where both PDF and RTF documents are needed.
Additionally, it appears that while there is a PdfpTable class, there is nothing similar for RTF, so I would be using Table anyway, which would leave me vulnerable to all the quirks that come along with the now unsupported Table class.
Basically, what are the benefits/downsides of separating the code into two sections -- one to create PDF documents, and one to create the same documents in an RTF format, if that was selected? And where does SimpleTable come in to all of this? Will it give me the flexibility that I need?
Thanks!
From the book iText In Action, end of chapter 6:
If you look at the iText API, you’ll also find some other table classes. com.lowagie.text.Table is the original table class; it dates from the early iText days. It uses class com.lowagie.text.pdf.PdfTable internally to render a table to PDF (don’t confuse this class with PdfPTable).
There’s also the newer SimpleTable class, which tries to form a link between
PdfPTable and Table. It’s able to translate itself to a PdfPTable if you add it to a
document that writes PDF or to a Table if you’re producing HTML or RTF. [...]
The major disadvantage of the Table class is that it’s no longer supported. Different
people have fixed most of the known issues, but today not a single person
understands if and how all the Table-methods work. If you decide to use this class,
you’re more or less on your own, and you’ll encounter lots of quirky layout issues
based on historical design decisions. However, this doesn’t mean you can’t make
good use of the Table class.
Advantages of the Table class
With the Table class, you can generate a table structure that can be rendered in
PDF, RTF, and HTML. If you compare the results, you’ll see there are small differences
in the way the table is rendered. This is normal; not every table feature is
supported in every document format.
You can generate a table in PDF, HTML, or RTF using the same code.
You can set padding and spacing the way it’s done in HTML.
You can use the row span without having to resort to nested table.
You can change the number of columns even after you’ve added cells.
You can add cells at specific positions (the number of rows is augmented
dynamically).
You can delete a column before adding the table to the document.
You can let iText add the Table as if it was a PdfPTable.
You get a PdfPTable object based on the Table object.
As opposed to PdfPTable, you can add cells to a Table in a random order, and add
or delete columns if needed. You can even translate a Table to a PdfPTable if you
didn’t use setRowspan().
There’s also the SimpleTable, class, which is a simplified version of (PdfP)-Table. When adding a SimpleTable to a PDF document, iText first attempts to add
the table as a PdfPTable; if this fails, it’s added as a Table. When adding a SimpleTable to an RTF or HTML document, it’s added as a Table. SimpleTable differs
from the Table and PdfPTable in the sense that it reintroduces the concept of rows.
This can be handy if you’re parsing an XML file that has a table-row-cell structure.
If the tag corresponding with the rows has attributes, you don’t have to define this
property for each cell in the row separately; you can set the property for the entire
row at once.
Summary
PdfPTable should be your first choice; but depending on the requirements defined for your project, there can be good reasons to opt for Table or SimpleTable.