Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ParseDocument() {
- var table = document.getElementById('allContact');
- var contactDTOList = new Array();
- var i =0;
- for (var r = 2, n = table.rows.length; r < n; r++) {
- if (table.rows[r].style.display !== 'none') {
- var s = table.rows[r].cells[0].innerHTML;
- var bits = s.split(/D/);
- var date = new Date(bits[0], --bits[1], bits[2], bits[3], bits[4], bits[5]);
- var contactDTO = {
- dateOfBirth:date.getTime(),
- firstName:table.rows[r].cells[1].innerHTML,
- lastName:table.rows[r].cells[2].innerHTML,
- email:table.rows[r].cells[3].innerHTML
- };
- contactDTOList.push(contactDTO);
- i++;
- }
- }
- $.ajax({
- type: 'POST',
- url: "/rest/bot5",
- data: JSON.stringify(contactDTOList),
- contentType: "application/json;charset=UTF-8",
- async: true,
- success: function () {
- }
- });
- }
- import org.springframework.http.MediaType;
- import org.springframework.web.bind.annotation.*;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.CellStyle;
- import org.apache.poi.ss.usermodel.Font;
- import org.apache.poi.ss.usermodel.IndexedColors;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- @RestController
- @RequestMapping(value = "/test")
- public class BotRestController {
- @PostMapping(value = "/bot5", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public FileOutputStream postOrderingTask(@RequestBody List<Contact> contactList) throws IOException {
- String[] columns = {"First Name", "Last Name", "Email", "Date Of Birth"};
- List<Contact> contacts = new ArrayList<Contact>();
- contacts.add(new Contact("Sylvain", "Saurel", "sylvain.saurel@gmail.com", "2018-09-25 16:28:47"));
- contacts.add(new Contact("Albert", "Dupond", "sylvain.saurel@gmail.com", "2018-09-25 17:28:47"));
- contacts.add(new Contact("Pierre", "Dupont", "sylvain.saurel@gmail.com", "2018-09-25 18:28:47"));
- contacts.add(new Contact("Mariano", "Diaz", "sylvain.saurel@gmail.com", "2018-09-25 19:28:47"));
- Workbook workbook = new XSSFWorkbook();
- Sheet sheet = workbook.createSheet("Contacts");
- Font headerFont = workbook.createFont();
- headerFont.setBold(true);
- headerFont.setFontHeightInPoints((short) 14);
- headerFont.setColor(IndexedColors.RED.getIndex());
- CellStyle headerCellStyle = workbook.createCellStyle();
- headerCellStyle.setFont(headerFont);
- // Create a Row
- Row headerRow = sheet.createRow(0);
- for (int i = 0; i < columns.length; i++) {
- Cell cell = headerRow.createCell(i);
- cell.setCellValue(columns[i]);
- cell.setCellStyle(headerCellStyle);
- }
- // Create Other rows and cells with contacts data
- int rowNum = 1;
- for (Contact contact : contacts) {
- Row row = sheet.createRow(rowNum++);
- row.createCell(0).setCellValue(contact.firstName);
- row.createCell(1).setCellValue(contact.lastName);
- row.createCell(2).setCellValue(contact.email);
- row.createCell(3).setCellValue(contact.dateOfBirth);
- }
- // Resize all columns to fit the content size
- for (int i = 0; i < columns.length; i++) {
- sheet.autoSizeColumn(i);
- }
- // Write the output to a file
- FileOutputStream fileOut = new FileOutputStream("contacts.xlsx");
- workbook.write(fileOut);
- fileOut.close();
- return fileOut;
- }
- }
Add Comment
Please, Sign In to add comment