Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.
Sat Aug 27, 2022 4:09 pm
Dears,
iam woring on application , please i need your support to delete some words and remove blank line
in the below code i succed to remove word with blank but i canot remove blank line
- Code: Select all
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.documents.TextSelection;
import com.spire.doc.interfaces.IDocument;
import java.util.HashMap;
import java.util.Map;
public class Main2 {
public static void main(String[] args)
{
String filename="SampleCv_1.docx";
String newFileName="SampleCv_2.docx";
Document document = new Document(filename);
//Load the sample Word document
document.loadFromFile(filename);
//Remove the second paragraph of the first section
document.replace("${table_holder_1}","", false, true);
//Save the document
document.saveToFile(newFileName, FileFormat.Docx_2013);
}
}
Login to view the files attached to this post.
-

shadywardy
-
- Posts: 19
- Joined: Thu Aug 18, 2022 2:25 pm
Mon Aug 29, 2022 6:34 am
Hello shadywardy,
Thanks for your inquiry.
You can refer to the following code to remove the whole paragraph where the "${table_holder_1}" is, including the blank line. If you have any further questions, please feel free to contact us.
- Code: Select all
//Create a document
Document document = new Document();
// Load the document from disk.
document.loadFromFile("SampleCv_1.docx");
Section section1 = document.getSections().get(0);
//Find text.
TextSelection[] textSelections = document.findAllString("${table_holder_1}", false, true);
for (TextSelection seletion : textSelections) {
// Get the paragraph
Paragraph para = seletion.getAsOneRange().getOwnerParagraph();
// Get the para index
int index = section1.getBody().getChildObjects().indexOf(para);
// Delete the index
section1.getBody().getChildObjects().removeAt(index);
// Save to file.
document.saveToFile("output.docx", FileFormat.Docx_2013);
Sincerely
Simple
E-iceblue support team
-


Simple.Li
-
- Posts: 248
- Joined: Fri Jul 01, 2022 2:33 am
Fri Sep 02, 2022 9:35 am
Hello shadywardy,
Could you please let us know how is your issue going? Thanks in advance for your feedback and time.
Sincerely,
Simple
E-iceblue support team
-


Simple.Li
-
- Posts: 248
- Joined: Fri Jul 01, 2022 2:33 am
Fri Sep 02, 2022 6:26 pm
sorry it didnot work , the aim of qestion that i make to remove useless word like in attached i need to remove this word " ${table_holder_2} " or " ${table_holder_3} " or " ${table_holder_4} " ......etc
main class
- Code: Select all
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.TextSelection;
import com.spire.doc.interfaces.IDocument;
import java.util.HashMap;
import java.util.Map;
public class Main2
{
public static void main(String[] args) {
String filename = "CV.docx";
String newFileName = "CV_output.docx";
Map<String, String> map = new HashMap<String, String>();
map.put("${Name}", "SHADY WARDY");
map.put("${Phone}", "01154000641");
map.put("${Email}", "[email protected]");
map.put("${Address}", "37 AboElFadel St - Shoubra Masr - Cairo");
map.put("${linkedin}", "Linkedin.com");
map.put("${ Mother_tongue}", "Arabic");
map.put("${Second_Languages}", "English");
map.put("${degree}", "Civil Engineering");
map.put("${Faculty}", "Cairo Engineering");
map.put("${Year}", "2013");
map.put("${major}", "Civil");
map.put("${Project_Name}", "Constraction Project Mangmengt");
map.put("${Project_Grade}", "Excellent");
map.put("${General grade}", "Very Good");
map.put("${Certificate_1}", "PMPFWEJDFBJKWBFJK");
String book_mark_number = "table_bookmark_1";
String table_holder_number = "${table_holder_1}";
String Position = "Senior Civil Engineer";
String Project = "New Telecom Tower";
String Company = "ZTE";
String Scope =
"\u2023 " + "Hand over 1300 TK sites\n" +
"\u2023 " + "Project Cost Control\n" +
"\u2023 " + "Quality Control in all project phases\n" +
"\u2023 " + "Project planning regarding Sub Contractors resources and site requirements and mange site material\n" +
"\u2023 " + "Control site acceptance and billing\n" +
"\u2023 " + "Clearness & Acceptance for Backlog and Problematic Sites\n" +
"\u2023 " + "Coordinate between all project Stakeholder\n" +
"\u2023 " + "Interface with Customer to full fill their requirements and get needed approvals.\n" +
"\u2023 " + "Follow with the consultant for issues that needs modification\n" +
"\u2023 " + "Review and Audit Site folder Element ( As-built , Consultant Report , Consultant Certificate , Material Certificate , Test report & Certificates… )\n";
new ExperianceGenerate(filename, newFileName, book_mark_number, table_holder_number, Position, Project, Company, Scope);
new WordTemplateCreator().findReplaceWord(newFileName, newFileName, map);
new WordTemplateCreator().findReplaceImage(newFileName, newFileName, "website.jpg");
//Create a document
Document document = new Document();
// Load the document from disk.
document.loadFromFile(newFileName);
Section section1 = document.getSections().get(0);
//Find text.
for(int i=2 ; i<13;i++) /// i add this function to make itration
{
TextSelection[] textSelections = document.findAllString("${table_holder_"+i+"}", false, true);
for (TextSelection seletion : textSelections)
{
// Get the paragraph
Paragraph para = seletion.getAsOneRange().getOwnerParagraph();
// Get the para index
int index = section1.getBody().getChildObjects().indexOf(para);
// Delete the index
section1.getBody().getChildObjects().removeAt(index);
// Save to file.
document.saveToFile(newFileName, FileFormat.Docx_2013);
}
}
}
}
Login to view the files attached to this post.
-

shadywardy
-
- Posts: 19
- Joined: Thu Aug 18, 2022 2:25 pm
Mon Sep 05, 2022 8:31 am
Hello shadywardy,
Thanks for your reply.
You can refer to the following code to remove the mentioned paragraphs from your new word file. If you have any further questions, please feel free to contact us.
- Code: Select all
Document document = new Document();
document.loadFromFile("data/CV.docx");
//Find text.
for(int i=12 ; i>0;i--)
{
TextSelection[] textSelections = document.findAllString("${table_holder_" + i + "}", false, true);
for (TextSelection seletion : textSelections) {
Paragraph para = seletion.getAsOneRange().getOwnerParagraph();
TableCell tc =(TableCell)para.getOwner() ;
int index= tc.getParagraphs().indexOf(para);
tc.getParagraphs().removeAt(index);
}
}
document.saveToFile("output/output.docx", FileFormat.Docx);
Sincerely,
Simple
E-iceblue support team
-


Simple.Li
-
- Posts: 248
- Joined: Fri Jul 01, 2022 2:33 am