DocX4: How to add table in word docx using Quick part field and write to that template with a table - docx4j

I would like to add table in my docx template. I know how to do it with just a simple field and how to use that template and write the value to it. But how can I create a table and write to the template. Assuming I have a list of Students object, how am I going to write it in a table?
This is how you add field name.
Quick Parts > Fields > Choose MergeField in the category and write the
desired field name
And here's how to write the value to it using docx4j
Map<DataFieldName, String> map = new HashMap<DataFieldName, String>();
map.put(new DataFieldName("myName"),"yourName");
MailMerger.setMERGEFIELDInOutput(MailMerger.OutputField.DEFAULT);
MailMerger.performMerge(template, map, true);
template.save(new File("C:/temp/OUT_SIMPLE.docx") );

Assuming you want one row per list item, the easiest way is to iterate through the list, writing your table rows.
To generate suitable code, create a Word document with the table looking as you want it, then generate corresponding code.
Alternatively, you could use OpenDoPE content control data binding, wrapping a repeat around a table row. This is a more generic solution, but with a learning curve...

Related

Update custom fields in an VBAP append structure via VA02

I have the following requirement. I need to save some parameters in the table VBAP. I've created additional fields in an append structure for that. Now, when a sales document is being saved, the parameters have to be updated as well.
For this I've been using USEREXIT_SAVE_DOCUMENT in the program SAPMV45A. There I loop over the table XVBAP where I set the fields.
This works as expected for existing positions. When a new position is being added the fields won't be updated and are empty.
What am I missing here? Do I have to use a different user exit for new positions?
Thanks in advance.
you can use "USEREXIT_MOVE_FIELD_TO_VBAP" in MV45AFZZ

How do I insert a table into a cell using word vba or a table within a table?

I am new on VBA, I am creating a script to generate a report from a DB, I have been able to assemble a general draft of my report but I need to insert a table into an existing cell inside a word document, I have been surfing around but I am unable either to do a websearch with the correct terms in order to find some guidance on how to achieve this, If I am able to do it with my mouse I am sure I am able to do it through scripting, any resources that would help me in the right direction will be deeply appreciated.
Ok I found a way, The secret is in the Range, to specify where do you want your nested table to be placed.
so, I am using Powershell so the syntax might vary a little
For creating the Table in the Document (assuming you already have a created document, if not you are missing that part which I am not going through since they already are several question/answer pairs on that subject).
$TableX = $oDoc.Tables.Add($oDoc.Bookmarks("TableX").Range, 4, 3)
So TableX is our actual table, then we are telling word to use the helper method on the oDoc (Which is the name of our document object) to add a table, with a Bookmark named TableX (I will again not do a large explanation on this one, just for practical purposes, we name the Bookmark so we can reference to the table by Bookmark name later if we need to add data to it or manipulate it in any way we need) and at the same time we are calling to the method Range which is going to tell the Document Object where do we want the table to be placed, since we have not defined the range explicitly it will insert it in the next available line on the document,
Finally we specify how many rows and columns we would like in the table.
That is what we need for creating a table, now the tricky part, how do we insert a nested table, and moreover how do we specify where do we want this second table to be nested.
Well, with this:
$oNestedTable = $oDoc.Tables.Add($TableX.Cell(4, 2).Range,7,3)
We name our nested table oNestedTable, then we are calling the same helper method we called before to add a new table to the document, but wait, look carefully at the differences, the range part of the command is pointing to a specific cell on in our first table, that is in the fourth row within the second cell, it is there where we are explicitly telling the document to insert a new table with 7 rows and 3 columns.
I hope this gives you some bare minimum guidance.
Regards
en

Qlikview Current selections box to use labels rather than table.fieldnames

In my Qlik View document I want to change the Current Selections information to use the Label applied to the field rather than the table.field format.
For example
PartsTable.PartNo
Would be
Part Number
Unfortunately there's no way to do this in the Current Selections object. However, you may have some alternatives depending on your requirements.
First of all, if you're just happy with seeing the current selections as text (rather than having the functionality of the Current Selections object), you can create a Text object and use the expression:
=replace(GetCurrentSelections(), 'PartsTable.PartNo', 'Part Number')
This will then look something like the below:
The other alternative is to use the RENAME statement in the load script after all your table loads are complete. RENAME allows you to rename a single field or a collection of fields by using a mapping table. The syntax for a single field is shown below:
RENAME FIELD oldname to newname
If you should need to rename more than one field at a time, you can expand this to:
RENAME FIELD oldname1 to newname1, oldname2 to newname2,...
More detail on the syntax including using a mapping table can be found in the QlikView installed help file.
For your example, I put together a small demo:
QUALIFY *;
PartsTable:
LOAD * INLINE [
PartNo
100
200
300
];
UNQUALIFY *;
RENAME FIELD PartsTable.PartNo to [Part Number];
This then results in:
RENAME is similar to the alias (AS) statement, except that you can first load all of your data, and then do the rename at the end. This will then rename your field so that it appears under its new name in any front-end controls (e.g. Current Selections etc.) However, this may not be suitable for you if you already have an existing field named Part Number in your script.

Lucene - Reading all field names that are stored

I need to populate a dropdown with all field names in a lucene index and need to show those values. I was able to do it successfully using
var luceneIndexReader IndexReader.Open("D:\path_to\index_directory", true);
var allAvailableFieldNames = luceneIndexReader.GetFieldNames(IndexReader.FieldOption.ALL);
Only problem is I need to include only 'Stored' fields in the drop down. This list includes all 'Indexed' and/or 'Stored' fields in it. Is there a way to query/search the indexes if a field has any 'stored' values and thereby filter out this list?
The problem is that every document in the index can have different fields containing stored fields. Since those are not storef as inverted index (they are stored per document) you can't retrieve them from the IndexReader. You need to retrieve one specific document, e.g. Document doc = indexReader.document(1); and call Fieldable fields[] = doc.getFields();. Then iterate over them and checking: field.isStored();.
Late at the party, but in the meanwhile you can just call FieldInfos# GetEnumerator()
See https://github.com/Shazwazza/lucenenet/blob/docs-update-jan2020/src/Lucene.Net/Index/FieldInfos.cs/#L168

how to display multivalued fields in velocity

I want to display a multivalued field in velocity.
The field is extracted from the oracle database.
My problem is that it does not display the values per line. Rather it just wraps the rows one after the other instead of creating a new line for a new row.
The follow code is what I used:
<div>#field('BugDescription')</div>
how do I break it down, so it's more readable?
Use the #foreach directive to loop through the values of a collection.