-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocWriter.java
More file actions
114 lines (97 loc) · 4.23 KB
/
DocWriter.java
File metadata and controls
114 lines (97 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package kitordersystem;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.*;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
/**
* Created by tsmoffat on 21/02/2016.
* A class to essentially dump the contents of the database to a spreadsheet
* in order to facilitate easy order sheet creation. This can be done as Word
* has an import from Excel option, although there is a possibility that the
* spreadsheet itself will be used as the order sheet
*/
public class DocWriter {
public DocWriter() throws Exception{
XWPFDocument document = new XWPFDocument();
DateFormat df = new SimpleDateFormat("yyyy/MM/dd_HH.mm.ss");
Date dateobj = new Date();
Connection conn = new getConnection().getConnection();
ResultSet rs;
String query;
Workbook wb = new XSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream
("Tilehurst_Order_Raw_" + df.format(dateobj) + ".xlsx");
for (int i=1; i<9; i++){
String stmt = "USE mydb";
conn.createStatement().executeQuery(stmt);
stmt="SELECT Item from Items where idItems = " + i;
rs = conn.createStatement().executeQuery(stmt);
rs.next();
String item = rs.getString("Item");
Sheet sheet1 = wb.createSheet(item);
XSSFRow row;
Map< String, Object[] > orderInfo =
new TreeMap< String, Object[] >();
orderInfo.put("1", new Object[] {item});
orderInfo.put("2", new Object[] {"Name", "Size", "Printed On"});
stmt = "SELECT c.Name, o.OrderSize, o.NameOnGarment FROM Orders o" +
" INNER JOIN Customers c on o.CustomerID " +
"= c.ID where o.Orders = " + i;
wb.write(fileOut);
while(rs.next()){
int j = 3;
String size = rs.getString("OrderSize");
String name = rs.getString("Name");
String nameOnBack = rs.getString("NameOnGarment");
String rowNum = Integer.toString(j);
orderInfo.put(rowNum, new Object[] {name, size, nameOnBack});
wb.write(fileOut);
}
wb.write(fileOut);
}
wb.write(fileOut);
fileOut.close();
wb.close();
XWPFTable table1 = document.createTable();
XWPFParagraph paragraph1 = document.createParagraph();
String stmt = "USE mydb;";
conn.createStatement().executeQuery(stmt);
query = "SELECT Item from Items where idItems = 1";
rs = conn.createStatement().executeQuery(query);
rs.next();
String item1 = rs.getString("Item");
XWPFRun paraRun1 = paragraph1.createRun();
paraRun1.setBold(true);
paraRun1.setUnderline(UnderlinePatterns.SINGLE);
paragraph1.setAlignment(ParagraphAlignment.CENTER);
paraRun1.setText(item1);
System.out.println(1);
XWPFTableRow trOne1 = table1.getRow(0);
trOne1.getCell(0).setText("Name");
trOne1.addNewTableCell().setText("Size");
trOne1.addNewTableCell().setText("Name on Back");
query = "SELECT c.Name, o.OrderSize, o.NameOnGarment FROM Orders " +
"o INNER JOIN Customers c on o.CustomerID" +
" = c.ID where o.Orders = 1";
rs = conn.createStatement().executeQuery(query);
while(rs.next()) {
String size = rs.getString("OrderSize");
String name = rs.getString("Name");
String nameOnBack = rs.getString("NameOnGarment");
XWPFTableRow tRow = table1.createRow();
tRow.getCell(0).setText(name);
tRow.getCell(1).setText(size);
tRow.getCell(2).setText(nameOnBack);
}
return;
}
}