Open XML iterated table binding to word document - openxml

I have to bind iterated tables to word document using open xml. I.I can able to bind single table to word document.
i am able to bind single table header 1 shown in image using book mark.
Could you please provide some ideas to bind multiple tables dynamically.Here in above image header 1 ,header 2 are dynamic ..IT may goes until header N..
Can any one provide some ideas to how to proceed on this .

I think you are looking for something like this -
foreach(HeaderPart headerPart in docGenerated.MainDocumentPart.HeaderParts)
{
foreach(Table table in headerPart.Header.Descendants<Table>())
{
// do whatever you want to do with your table.
}
}

Related

How to include Images in a word doc by using a field that references a second word doc that in turn has fields which reference the images?

I'll give an example with two images. In reality I have to do this several times with thousands of images each time.
So I have two images on my desktop and I open a word file and I insert those two images using fields like so:
{ INCLUDEPICTURE "C:\\Users\\me\\Desktop\\image_a" }
and
{ INCLUDEPICTURE "C:\\Users\\me\\Desktop\\image_a" }
I then save this word document as two_images_test.docx. In a new document I want to create a field with the path to two_images_test.docx in order to be able to display the two images in this new document. I figured this would do it:
{ INCLUDEPICTURE "C:\\Users\\me\\Desktop\\two_images_test.docx" }
but alas, it doesn't work and I get an error message saything that the linked image cannot be displayed bla bla bla... Can anyone help me with this? Many thanks in advance!
To link two or more Word documents together, you should use INCLUDETEXT fields, not INCLUDEPICTURE fields. If you want to link a specific range, bookmark that ranges in the source document and specify the bookmark in the INCLUDETEXT field.
For more on the INCLUDETEXT field, see: https://support.microsoft.com/en-us/office/field-codes-includetext-field-1c34d6d6-0de3-4b5c-916a-2ff950fb629e
To use INCLUDETEXT fields and INCLUDEPICTURE fields with relative paths, see: http://www.msofficeforums.com/word/38722-word-fields-relative-paths-external-files.html

How to insert a clickable link into a table?

I'm wondering if it's doable to insert a clickable link into a table. I'm acutely aware that one can insert a link which will be clickable in SSMS but that's not what I want to accomplish. I'd like the link to be clickable in application. I've searched the Internet but I've only come across the articles about adding HTML tags to the INSERT statement which enables to open the link in SSMS.
create table #link (a varchar(max))
INSERT into #link
VALUES ('Y'
)
You can insert whatever you want into the database columns. But the action "Open this link on a click event!" is something your application has to do.
To put it even closer: The action "Take this string, paint just the text on the screen, let it look like a hyper link and navigate to the hidden URL on a click!" is something bound to a HTML engine. Pass HTML to any browser and the browser will do all this implicitly. But your database is just a container for data...
I would either use a column typed XML and treat the HTML as XHTML, or - this would be much! better - use two columns and create the link either within a query or - again better - in your application.
Assume a table like this:
DECLARE #TheLinkTable TABLE(ID INT IDENTITY,LinkText NVARCHAR(1000),LinkAddress NVARCHAR(1000));
INSERT INTO #TheLinkTable VALUES('Y','http://www.google.com/');
You can use a query like this
SELECT LinkAddress AS [a/#href]
,LinkText AS [a]
FROM #TheLinkTable
FOR XML PATH('');
And you might read into this answer, if you'd need a HTML-table actually.
But - as said above - I'd just read both values from separated columns and build the clickable link in the application.

Access 2010 - enter references to form elements as the value of a text field

Is there a way to take a value from a field on a form and use it as a reference to a different field in the same form, and not just literally? I want to be able to manually enter something like [txtFlavor] in one field and have it show the actual flavor, the value of the field named "txtFlavor" in another field, and not just the string "[txtFlavor]". I'm basically trying to store some vba references (terminology?) in a table so I can bring up a string of text with references to values on the form.
I have been asked to create a system that will store letter templates in Access 2010 and allow users to choose a record with personal information and insert that info into a template letter, preferably displaying it on a form immediately in plain text. I already proposed using reports to do this but that was unacceptable to the end users. They really just want a form that combines
a) contact records, one at a time
with
b) letter templates, one at a time
I've been trying to store the template info with it's form references in a table, but I have yet to be able to make references pull data from another text field on the form.
Is it possible and/or sensible to try to store something like the following in a table, or to enter it into a field on a form?
[txtFlavor] & " is dull but popular."
and then have it show up elsewhere in the form as
Vanilla is dull but popular.
I sure feel dumb and am sure I've missed something obvious. Everything I do is just repeated literally and not interpreted as a reference.
You could get your users to create their templates using 'tags' as placeholders for the database information, in a similar way to how you would design a merge document in Word. So in your example above, the template document would look like:
{Flavor} is dull but popular.
When it comes time to create the merged result you would need to use the Replace function to change these tags to actual data values. So if you had a read-only text box on your form, the control source could be:
=Replace([txtTemplate], "{Flavor}", [Flavor])
I assume you would have lots of potential tags, so using this approach you would need to nest the Replace functions. I have split my nesting across multiple lines to make it a bit more readable:
=Replace(
Replace(
Replace([txtTemplate], "{EmpName}", [EmpName]),
"{EmpAddress}", [EmpAddress]),
"{EmpPhone}", [EmpPhone])
If you had many more database fields/tags this would start to become very unwieldy so I would recommend using some VBA to make life easier, maybe something along the lines of:
Dim rsSource As Recordset
Dim strMerge As String
Dim intField As Integer
'Assuming your form has a field called EmpNo (numeric data) that you can use to pull data...
Set rsSource = CurrentDb.OpenRecordset ("Select EmpName, EmpAddress, EmpPhone From Employees Where EmpNo = " & Me.EmpNo)
strMerge = txtTemplate
For intField = 0 to rsSource.Fields.Count - 1
strMerge = Replace(strMerge, "{" & rsSource(intField).Name & "}", rsSource(intField))
Next intField
txtMerge = strMerge
rsSource.Close
Set rsSource = Nothing
You could put this code in the AfterUpdate event of your txtTemplate text box and it would update the contents of the txtMerge text box. You either need your tag names to match your database columns, or else you could alias the columns in the Select statement so they match the tag names.

Word 2010 Show Table only in footer of last page

I've a template for word. In header and footer I've got logos of my company. The data of word is generating automatically from ERP program (that works great).
I only want to show some table with data on last page. I've tried this this method But it only works for text. When I'm updating the field the table and it's content disappear.
Anyone knows how to apply this method on table? It must to be automatic.
The same method works for block level content such as paragraphs or tables. Simply follow the same steps but instead of typing "Initials" insert your table there. Make sure to use speechmarks in the conditional e.g it should look like this { IF {PAGE} = {NUMPAGES} "" "(table)" }

Zend Framework Dynamically added fields of a form and populate

I have been attempting to create a form where a user can simply press a button and the form will add a new field for the user to use. I have 2 of these dynamically added field types.
Firstly a field where a user can upload files, by pressing the add button another field is pasted underneath the current field and is ready for use.
I have followed an old guide on how to get this done with a bit of ajax and jQuery.
This guide to be exact: http://www.jeremykendall.net/2009/01/19/dynamically-adding-elements-to-zend-form/
As you can see it's from 2009 and a bit outdated yet it still works under the current Zend Framework version 1.11.11
The problem however arises now that i want an edit / update version of the form. I need to populate it's fields but first of all i need to create enough fields for the data to be stored in. So when there's 3 files that have been uploaded it should create 2 additional fields and place the 3 file names in these fields ready to be edited and updated. Simply using $form->populate($stuff) is not going to work
I just have no idea how to accomplish this and the tutorial on dynamically added fields only goes as far as the addAction and not how to create the editAction under these conditions.
Is there any tutorial out there on how to create and manage forms such as these? I'm sure i am not the only one who's had the idea to builds these kind of forms?
I can add my code if there's a request for it but it's the same as the example from the guide, just a different set of elements in the form.
Adding a small example of it's use.
A user adds an item with 3 files, these files are uploaded along with a filename so in the database it appears like this : File_Id : '1' , File_Name : 'SomeFile' , File_location : 'somewhere/on/my/pc/SomeFile.txt'.
Now the user realizes he forgot a file or wants to delete a file from that list, he goes to the edit page and here i want the form to display the previously added filenames. So if there's 3 files it shows 3 and when there's 2 it shows 2 etc. How do i build a form to dynamically add fields based on the number of uploaded files and then populate them?
Any advice on how to handle this is well appreciated :)
You can make use of the semi-magic setXxx() methods of the form.
Inside the form:
public function setFiles($files) {
foreach ($files as $file) {
$this->addElement(/* add a file element */);
//do other stuff, like decorators to show the file name, etc.
}
}
In your controller:
$files = $model->getFiles();
$form = new Form_EditFiles(array('files' => $files));
By passing an array with key files you will make the form try to call the method named setFiles(), which you have conveniently provided above.
This should push you in the right direction, or so I hope at least.
If I understand you correctly you want to populate file upload fields, which is not possible because of security reasons.
Edit:
You can add Elements inside of the Controller via $form->addElement() (basicly just like the $this->addElement() statements in the Tutorial)