Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files from any .NET platform (C#, VB.NET, ASP.NET, .NET Core) and Java applications (J2SE and J2EE) with fast and high quality performance.

Wed Jun 20, 2012 1:36 pm

I have a file that I am doing search and replace on. I one of the elements that I am to replace is being replaced with an empty string I want to remove the entire line so that the remaining text continues to flow. How do I accomplish this.

Template file
<Name>
<Address1>
<Address2>
<City> <State> <ZIP>

the replacement out put:
My Name
14 Street Name
BO Box 33333
City, TX 88888

if Address2 does not exist I would like it to display as

My Name
14 Street Name
City, TX 88888

However right now the best I can get is

My Name
14 Street Name

City, TX 88888

itsupport
 
Posts: 10
Joined: Thu Jun 14, 2012 7:18 pm

Thu Jun 21, 2012 6:01 am

Hi,

Thanks for your inquiry.

You just need to add the code :
Code: Select all
doc.MailMerge.HideEmptyParagraphs = true
before you execute the mailmerge.

I attached a live demo to remove the blank line, please have a check.

If you still have any problems, please feel free to contact us.

Have a nice day.

BR
Suvi
e-iceblue support
You do not have the required permissions to view the files attached to this post.
User avatar

Suvi.Wu
 
Posts: 154
Joined: Thu Oct 20, 2011 2:53 am

Thu Jun 21, 2012 1:12 pm

Thanks for the reply. I forgot to state that this is not being done with mail merge. I have code that replaces the strings using the doc.Replace("<Street2>", myvalue);

if myvalue is empty string and the row does not have any additional text then I want the row to be removed. Will the code you provided work in this instance?

itsupport
 
Posts: 10
Joined: Thu Jun 14, 2012 7:18 pm

Mon Jun 25, 2012 5:04 am

Hi ,

Thanks for your feedback.

I am sorry to tell you that Spire.Doc can't remove the blank line when replace the string as the MS word can't either. So we recommand you use mailMerge to achieve your goal.

Sorry for the inconvenience.

In case of any ambiguity, please let us know.

Have a great day.

BR
Suvi
e-iceblue support
User avatar

Suvi.Wu
 
Posts: 154
Joined: Thu Oct 20, 2011 2:53 am

Return to Spire.Doc