Last post Aug 15, 2017 03:58 AM by Leon Davis
Jun 21, 2017 09:10 AM|ASPNewbie.Net|LINK
I have a word template and use document.ReplaceText to replace text on the template with data from SQL DB to create a CV. Most of the details are simple to replace. I have an issue when it comes to Work Experience that can have multiple records in the DB.
To get the correct layout I have placed 10 tables in the document and replace the set tags with the info from the DB. The issue I have is that I need to remove all the tables that have no data in them after I have replaced all the text in the document and
I can't seem to get it right. This would happen if the person has worked in less that 10 places previously.
How do I remove empty tables, or is there a better way of doing this?
Jun 22, 2017 08:06 AM|Eric Du|LINK
According to your description, as far as I know, you want to create CV use word template through SQL DB data. But I have some doubts through your describe, I need confirm with you:
1. Word template? if it is office document or html document template?
If it is a html document, you worry empty tables occupy the document when no data from database. I think you could create tables dynamically through data in jQuery.
2. How to create table, using div or other controls?
3. Could you post the code you have done, we could make a modify based on your code!
Aug 12, 2017 09:44 PM|Stephen Eubanks|LINK
From your description I assume you are using Office COM to achieve your results. What you want to do is quite easy if you use a library that uses OpenXML and supports document generation based on templates. The templates can be done in MS Word, at runtime
they are merged with data to form a final documents (docx, pdf, xps).
Check out this link, to learn more about it: http://www.docentric.com/product/how-to-use
Aug 15, 2017 03:58 AM|Leon Davis|LINK
You can try the following solution to remove the empty tables in word document.
static void Main(string args)
Document doc = new Document();
foreach (Section section in doc.Sections)
int a = section.Tables.Count;
for (int m = 0; m < a; m++)
Table table = section.Tables[m] as Table;
bool result = Detect(table);
if (result == true)
private static bool Detect(Table table)
for (int i = 0; i < table.Rows.Count; i++)
for (int j = 0; j < table.Rows[i].Cells.Count; j++)
if (table.Rows[i].Cells[j].Paragraphs.Text != "")
Note this solution is provided by a free
word library, if you don't mind, you can give it a try.