iam working on application to create CV Word automatic by some Classes
So i create Class Name "ExperianceGenerate" This class use to create tables include pervious experience
i create in origin Word Template ${table_holder_1} to replace it by table include pervious experience
but unfortunately table generate in wrong location and Wrong dimensions
Main Class
- Code: Select all
import java.util.HashMap;
import java.util.Map;
public class Main2 {
public static void main(String[] args)
{
String filename="New Microsoft Word Document.docx";
String newFileName="testoutput.docx";
Map<String, String> map = new HashMap<String, String>();
map.put("${Name}", "SHADY WARDY");
map.put("${Phone}", "01154000641");
map.put("${Email}", "ShadyWardy@Gmail.com");
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 "+"\tHand over 1300 TK sites\n" +
"\u2023 "+"\tProject Cost Control\n" +
"\u2023 "+"\tQuality Control in all project phases\n" +
"\u2023 "+"\tProject planning regarding Sub Contractors resources and site requirements and mange site material\n" +
"\u2023 "+"\tControl site acceptance and billing\n" +
"\u2023 "+"\tClearness & Acceptance for Backlog and Problematic Sites\n" +
"\u2023 "+"\tCoordinate between all project Stakeholder\n" +
"\u2023 "+"\tInterface with Customer to full fill their requirements and get needed approvals.\n" +
"\u2023 "+"\tFollow with the consultant for issues that needs modification\n" +
"\u2023 "+"\tReview 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");
}
}
Used Class ExperianceGenerate
- Code: Select all
import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.TextRange;
public class ExperianceGenerate {
ExperianceGenerate(String filename, String newfilename,
String book_mark_number, String table_holder_number,
String Position, String Project, String Company , String Scope){
Document doc = new Document();
doc.loadFromFile(filename);
//Find the keyword. it may like this "${table_holder}".
//here I just use the whole paragraph for example.
TextSelection selection= doc.findString(table_holder_number,false,true);
//Get the TextRange of the key word
TextRange range=selection.getAsOneRange();
//Get the owner paragraph of the key word
Paragraph owner=range.getOwnerParagraph();
//Get the index of this range in the owner paragraph
int index=owner.getChildObjects().indexOf(range);
//Insert a temporary bookmark to include the key word
BookmarkStart start=new BookmarkStart(doc,book_mark_number);
BookmarkEnd end=new BookmarkEnd(doc,book_mark_number);
owner.getChildObjects().insert(index,start);
owner.getChildObjects().insert(index+2,end);
//init a new table object
Table table=new Table(doc,true);
//reset rows and columns
table.resetCells(5,2);
//put some values in the table
table.get(0,0).addParagraph().appendText("Position:").getCharacterFormat().setBold(true);
table.get(1,0).addParagraph().appendText("Project:").getCharacterFormat().setBold(true);
table.get(2,0).addParagraph().appendText("Company:").getCharacterFormat().setBold(true);
table.get(3,0).addParagraph().appendText("Scope:").getCharacterFormat().setBold(true);
table.get(0,1).addParagraph().appendText(Position).getCharacterFormat().setBold(false);
table.get(1,1).addParagraph().appendText(Project ).getCharacterFormat().setBold(false);
table.get(2,1).addParagraph().appendText(Company ).getCharacterFormat().setBold(false);
table.get(4,1).addParagraph().appendText(Scope ).getCharacterFormat().setBold(false);
table.applyHorizontalMerge(3,0,1);
table.applyHorizontalMerge(4,0,1);
table.get(0,0).setCellWidth(5,CellWidthType.Percentage);
//init a TextBodyPart object
TextBodyPart body=new TextBodyPart(doc);
//add the table to the body
body.getBodyItems().add(table);
//Find the bookmark by name
BookmarksNavigator navigator=new BookmarksNavigator(doc);
navigator.moveToBookmark(book_mark_number);
//Replace all content in the bookmark with the new body
navigator.replaceBookmarkContent(body);
// If you need, remove the bookmark after replacemenet
//doc.getBookmarks().remove(navigator.getCurrentBookmark());
Paragraph paragraph= navigator.getCurrentBookmark().getBookmarkEnd().getOwnerParagraph();
DocumentObject parent=paragraph.getOwner();
parent.getChildObjects().remove(paragraph);
//Save the file
doc.saveToFile(newfilename, FileFormat.Docx);
}
}