Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions dynamictable/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import javax.xml.bind.annotation.*;
public class Employee
{
private String Name;
private String Title;
private String Address;
private String HomePhone;
private String Photo;
@XmlElement(name = "Name")
/**
* Gets the employee name.
*/
public String getName()
{
return Name;
}
/**
* Sets the employee name.
*
* @param name Name of the employee.
*/
public void setName(String name)
{
this.Name = name;
}
@XmlElement(name = "Title")
/**
* Gets the designation of the employee.
*/
public String getTitle()
{
return Title;
}
/**
* Sets the designation of the employee.
*
* @param title Designation of the employee.
*/
public void setTitle(String title)
{
this.Title = title;
}
@XmlElement(name = "Address")
/**
* Gets the address of the employee.
*/
public String getAddress()
{
return Address;
}
/**
* Sets the address of the employee.
*
* @param address Address of the employee.
*/
public void setAddress(String address)
{
this.Address = address;
}
@XmlElement(name = "HomePhone")
/**
* Gets the contact number of the employee.
*/
public String getHomePhone()
{
return HomePhone;
}
/**
* Sets the contact number of the employee.
*
* @param homePhone Contact number of the employee.
*/
public void setHomePhone(String homePhone)
{
this.HomePhone = homePhone;
}
@XmlElement(name = "Photo")
/**
* Gets the photo of the employee.
*/
public String getPhoto()
{
return Photo;
}
/**
* Sets the photo of the employee.
*
* @param photo Photo of the employee.
*/
public void setPhoto(String photo)
{
this.Photo = photo;
}
/**
* Initializes a new instance of the Employee class with the specified name,
* title, address, contact number and photo.
*
* @param name Name of the employee.
* @param title Designation of the employee.
* @param address Address of the employee.
* @param homePhone Contact number of the employee.
* @param photo Photo of the employee.
*
*/
public Employee(String name, String title, String address, String homePhone, String photo)
{
this.Name = name;
this.Title = title;
this.Address = address;
this.HomePhone = homePhone;
this.Photo = photo;
}
/**
* Initializes a new instance of the Employee class.
*/
public Employee()
{
}
}
92 changes: 28 additions & 64 deletions dynamictable/Employees.java
Original file line number Diff line number Diff line change
@@ -1,76 +1,40 @@
import java.util.List;
import javax.xml.bind.annotation.*;
@XmlRootElement(name = "Employees")
public class Employees
{
private String m_name;
private String m_title;
private String m_address;
private String m_homePhone;
private String m_photo;
// Gets the employee name.
public String getName() throws Exception {
return m_name;
}
// Sets the employee name.
public String setName(String value) throws Exception {
m_name = value;
return value;
}
// Gets the designation of the employee.
public String getTitle() throws Exception {
return m_title;
}
// Sets the designation of the employee.
public String setTitle(String value) throws Exception {
m_title = value;
return value;
}
// Gets the address of the employee.
public String getAddress() throws Exception {
return m_address;
}
// Sets the address of the employee.
public String setAddress(String value) throws Exception {
m_address = value;
return value;
}
// Gets the contact number of the employee.
public String getHomePhone() throws Exception {
return m_homePhone;
}
// Sets the contact number of the employee.
public String setHomePhone(String value) throws Exception {
m_homePhone = value;
return value;
}
// Gets the photo of the employee.
public String getPhoto() throws Exception {
return m_photo;
}
// Sets the photo of the employee.
public String setPhoto(String value) throws Exception {
m_photo = value;
return value;
private List<Employee> Employee;
/**
* Gets the list of employees.
*/
@XmlElement(name = "Employee")
public List<Employee> getEmployees()
{
return Employee;
}
/**
* Initializes a new instance of the Employees class with the specified name,
* title, address, contact number and photo.
* Sets the list of employees.
*
* @param name Name of the employee.
* @param title Designation of the employee.
* @param address Address of the employee.
* @param homePhone Contact number of the employee.
* @param photo Photo of the employee.
* @throws Exception
* @param employee List of employee.
*/
public Employees(String name, String title, String address, String homePhone, String photo) throws Exception {
m_name = name;
m_title = title;
m_address = address;
m_homePhone = homePhone;
m_photo = photo;
public void setEmployees(List<Employee> employee)
{
this.Employee = employee;
}
/**
* Initializes a new instance of the Employees class.
*/
public Employees() throws Exception {
public Employees()
{
}
/**
* Initializes a new instance of the Employees class with the specified list of
* employee.
*
* @param employees List of employee.
*/
public Employees(List<Employee> employees)
{
this.Employee = employees;
}
}
122 changes: 17 additions & 105 deletions dynamictable/WordTable.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
import java.io.*;
import java.util.List;
import javax.xml.bind.*;
import com.syncfusion.docio.*;
import com.syncfusion.javahelper.system.*;
import com.syncfusion.javahelper.system.collections.generic.ListSupport;
import com.syncfusion.javahelper.system.io.*;
import com.syncfusion.javahelper.system.xml.*;

public class WordTable{
public static void main(String[] args) throws Exception {
public class WordTable
{
public static void main(String[] args) throws Exception
{
// Loads the XML file.
File file = new File(getDataDir("EmployeesList.xml"));
// Create a new instance for the JAXBContext.
JAXBContext jaxbContext = JAXBContext.newInstance(Employees.class);
// Reads the XML file.
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Employees employees = (Employees) jaxbUnmarshaller.unmarshal(file);
// Gets the list of employee details.
List<Employee> employeeList = employees.getEmployees();
// Loads the template document.
WordDocument document = new WordDocument(getDataDir("WordTable_Template.docx"));
// Creates a list of employee details.
ListSupport<Employees> employeeDetails = getEmployeeDetails();
// Iterates each item in the list.
for (Employees employee : employeeDetails)
for (Employee employee : employeeList)
{
// Accesses the table in the document.
IWTable table = document.getSections().get(0).getTables().get(0);
// Initializes the paragraph and add new row to the table.
IWParagraph paragraph = null;
WTableRow newRow = null;
newRow = table.addRow();
table.addRow();
// Gets the employee photo and convert that base64 string to bytes.
byte[] bytes = ConvertSupport.fromBase64String(employee.getPhoto());
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
Expand All @@ -36,101 +43,6 @@ public static void main(String[] args) throws Exception {
document.close();
}

/**
*
* Gets the list of employee details.
*
*/
private static ListSupport<Employees> getEmployeeDetails() throws Exception {
// Gets list of employee details.
ListSupport<Employees> employees = new ListSupport<Employees>(Employees.class);
// Reads the xml document.
FileStreamSupport fs = new FileStreamSupport(getDataDir("EmployeesList.xml"), FileMode.Open, FileAccess.Read);
XmlReaderSupport reader = XmlReaderSupport.create(fs);
if (reader == null)
throw new Exception("reader");
while (reader.getNodeType() != XmlNodeType.Element)
reader.read();
if (reader.getLocalName() != "Employees")
throw new Exception(StringSupport.concat("Unexpected xml tag ", reader.getLocalName()));
reader.read();
while (reader.getNodeType() == XmlNodeType.Whitespace)
reader.read();
// Iterates to add the employee details in list.
while (reader.getLocalName() != "Employees")
{
if (reader.getNodeType() == XmlNodeType.Element)
{
switch (reader.getLocalName())
{
case "Employee":
employees.add(getEmployees(reader));
break;
}
}
else
{
reader.read();
if ((reader.getLocalName() == "Employees") && reader.getNodeType() == XmlNodeType.EndElement)
break;
}
}
return employees;
}

/**
*
* Gets the employees.
*
* @param reader Syncfusion's XML reader to read the XML files..
*/
private static Employees getEmployees(XmlReaderSupport reader) throws Exception {
if (reader == null)
throw new Exception("reader");
while (reader.getNodeType() != XmlNodeType.Element)
reader.read();
if (reader.getLocalName() != "Employee")
throw new Exception(StringSupport.concat("Unexpected xml tag ", reader.getLocalName()));
reader.read();
while (reader.getNodeType() == XmlNodeType.Whitespace)
reader.read();
Employees employee = new Employees();
while (reader.getLocalName() != "Employee")
{
if (reader.getNodeType() == XmlNodeType.Element)
{
switch (reader.getLocalName())
{
case "Name":
employee.setName(reader.readContentAsString());
break;
case "Title":
employee.setTitle(reader.readContentAsString());
break;
case "Address":
employee.setAddress(reader.readContentAsString());
break;
case "HomePhone":
employee.setHomePhone(reader.readContentAsString());
break;
case "Photo":
employee.setPhoto(reader.readContentAsString());
break;
default:
reader.skip();
break;
}
}
else
{
reader.read();
if ((reader.getLocalName() == "Employee") && reader.getNodeType() == XmlNodeType.EndElement)
break;
}
}
return employee;
}

/**
* Get the file path
*
Expand Down
Loading