-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhase1Demo.java
More file actions
338 lines (310 loc) · 11.2 KB
/
Phase1Demo.java
File metadata and controls
338 lines (310 loc) · 11.2 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
package com.him;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHeight;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTrPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc;
public class Phase1Demo {
private static Map<Integer,String[]> defectDetailsMap=new TreeMap<Integer,String[]>();
private static Map<Integer,String[]> mailDetailsMap=new TreeMap<Integer,String[]>();
private static Map<Integer,String[]> highlightsDetailsMap=new TreeMap<Integer,String[]>();
private static Map<Integer,String[]> piDetailsMap=new TreeMap<Integer,String[]>();
private static Map<Integer,String[]> monthlyTicketDetailsMap=new TreeMap<Integer,String[]>();
private static Map<Integer,String[]> categoryViseTicketDetailsMap=new TreeMap<Integer,String[]>();
private static Map<Integer,String[]> competencyDetailsMap=new TreeMap<Integer,String[]>();
private static Map<Integer,String[]> barGraphDetailsMap=new TreeMap<Integer,String[]>();
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
XWPFDocument doc= new XWPFDocument();
FileOutputStream out = new FileOutputStream(new File("C:\\L3ProjectFile\\Dashboard.docx"));
int totalSheet=readFileData();
writeFileData(doc,totalSheet);
doc.write(out);
out.close();
System.out.println("Dashboard.docx written successfully");
}
public static int readFileData() throws Exception
{
System.out.println("File Reading Started");
//Create Workbook instance holding reference to .xlsx file
int totalNumberOfSheet=0,valueOfSheet=0;
try
{
String str=null;
int k=1;int keyValue=1;int srNumber=1;
FileInputStream file = new FileInputStream(new File("C:\\L3ProjectFile\\L3CompleteExcel.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(file);
totalNumberOfSheet=workbook.getNumberOfSheets();
System.out.println("Total Sheet:: "+totalNumberOfSheet);
for(int i=0;i<totalNumberOfSheet;i++)
{
System.out.println("************ Sheet "+(i+1)+"************** start");
XSSFSheet sheet = workbook.getSheetAt(i);
//Iterate through each rows one by one
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext())
{
Row row = rowIterator.next();
//For each row, iterate through all the columns
if(row.getRowNum()==0){
continue; //just skip the rows if row number is 0 or 1
}
Iterator<Cell> cellIterator = row.cellIterator();
String obj[]=new String[100];
obj[0]=""+srNumber;
while (cellIterator.hasNext())
{
Cell cell = cellIterator.next();
//Check the cell type and format accordingly
switch (cell.getCellType())
{
case Cell.CELL_TYPE_NUMERIC:
obj[k]=String.valueOf(cell.getNumericCellValue());
k++;
System.out.print(cell.getNumericCellValue() + "\t");
break;
case Cell.CELL_TYPE_STRING:
str=cell.getStringCellValue();
obj[k]=str;
k++;
System.out.print(str + "\t");
break;
}
}//Cell End
if(valueOfSheet==0){
if(obj[0]!=null && obj[1]!=null && obj[2]!=null && obj[3]!=null && obj[4]!=null){
defectDetailsMap.put(keyValue,obj);
}
}
else if(valueOfSheet==1){
if(obj[0]!=null && obj[1]!=null && obj[2]!=null){
mailDetailsMap.put(keyValue,obj);
}
}
else if(valueOfSheet==2){
if(obj[0]!=null && obj[1]!=null && obj[2]!=null){
highlightsDetailsMap.put(keyValue,obj);
}
}
else if(valueOfSheet==3){
if(obj[0]!=null && obj[1]!=null && obj[2]!=null){
monthlyTicketDetailsMap.put(keyValue,obj);
}
}
else if(valueOfSheet==4){
if(obj[0]!=null && obj[1]!=null && obj[2]!=null){
piDetailsMap.put(keyValue,obj);
}
}
k=1;
keyValue++;
srNumber++;
System.out.println("");
}//Row End
System.out.println("************ Sheet "+(i+1)+"************** End\n");
valueOfSheet++;
keyValue=1;
srNumber=1;
}//Sheet End
file.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return totalNumberOfSheet;
}
public static void writeFileData(XWPFDocument doc,int totalsheet)
{
for(int i=0;i<totalsheet;i++)
{
createHeader(doc,i);
createStyledTable(doc,i);
}
}
public static void createHeader(XWPFDocument doc,int value){
XWPFParagraph paragraph = doc.createParagraph();
paragraph.setAlignment(ParagraphAlignment.CENTER);
XWPFRun run=paragraph.createRun();
run.setFontSize(15);
run.setColor("0000A0");
run.setBold(true);
if(value==0){
run.setText("L3 Defect Details\n");
}
else if(value==1){
run.setText("L3 Mail Issues\n");
}
else if(value==2){
run.setText("L3 Highlights\n");
}
else if(value==3){
run.setText("L3 Monthly Ticket Count Details\n");
}
else if(value==4){
run.setText("L3-PI Details\n");
}
}
public static void createStyledTable(XWPFDocument doc,int value){
List convertedList=null;
int size=0;
if(value==0){
size=defectDetailsMap.size();
convertedList=convertMapDataToList(defectDetailsMap,value);
}
else if(value==1){
size=mailDetailsMap.size();
convertedList=convertMapDataToList(mailDetailsMap,value);
}
else if(value==2){
size=highlightsDetailsMap.size();
convertedList=convertMapDataToList(highlightsDetailsMap,value);
}
else if(value==3){
size=monthlyTicketDetailsMap.size();
convertedList=convertMapDataToList(monthlyTicketDetailsMap,value);
}
else if(value==4){
size=piDetailsMap.size();
convertedList=convertMapDataToList(piDetailsMap,value);
}
// Create a new table with 6 rows and 3 columns
int nRows = size+1;
int nCols =((String[])convertedList.get(0)).length;
System.out.println("Total Row :: "+nRows+" cell:: "+nCols);
XWPFTable table = doc.createTable(nRows, nCols);
// Set the table style. If the style is not defined, the table style
// will become "Normal".
CTTblPr tblPr = table.getCTTbl().getTblPr();
CTString styleStr = tblPr.addNewTblStyle();
styleStr.setVal("StyledTable");
// Get a list of the rows in the table
List<XWPFTableRow> rows = table.getRows();
int rowCt = 0;
int colCt = 0;
int arr=0;
for (XWPFTableRow row : rows) {
// get table row properties (trPr)
CTTrPr trPr = row.getCtRow().addNewTrPr();
// set row height; units = twentieth of a point, 360 = 0.25"
CTHeight ht = trPr.addNewTrHeight();
ht.setVal(BigInteger.valueOf(360));
String[] objArray=(String[]) convertedList.get(rowCt);
// get the cells in this row
List<XWPFTableCell> cells = row.getTableCells();
// add content to each cell
for (XWPFTableCell cell : cells) {
// get a table cell properties element (tcPr)
CTTcPr tcpr = cell.getCTTc().addNewTcPr();
// set vertical alignment to "center"
CTVerticalJc va = tcpr.addNewVAlign();
va.setVal(STVerticalJc.CENTER);
// create cell color element
CTShd ctshd = tcpr.addNewShd();
ctshd.setColor("auto");
ctshd.setVal(STShd.CLEAR);
if (rowCt == 0) {
// header row
ctshd.setFill("A7BFDE");
}
else if (rowCt % 2 == 0) {
// even row
ctshd.setFill("D3DFEE");
}
else {
// odd row
ctshd.setFill("EDF2F8");
}
// get 1st paragraph in cell's paragraph list
XWPFParagraph para = cell.getParagraphs().get(0);
// create a run to contain the content
XWPFRun rh = para.createRun();
if (rowCt == 0) {
// header row
rh.setFontSize(13);
rh.setText(objArray[arr]);
rh.setBold(true);
para.setAlignment(ParagraphAlignment.CENTER);
}
else {
rh.setText(objArray[arr]);
para.setAlignment(ParagraphAlignment.LEFT);
}
colCt++;
arr++;
} // for cell
colCt = 0;
arr=0;
rowCt++;
}//for row
XWPFParagraph paragraph = doc.createParagraph();
paragraph.setAlignment(ParagraphAlignment.CENTER);
XWPFRun run=paragraph.createRun();
run.setText("\n\n\n\n");
}
public static List<String []> convertMapDataToList(Map<Integer,String[]> data,int value)
{
List<String[]> totalList=new ArrayList<String[]>();
String str[]=null;
Map.Entry entry;
if(value==0){
str=new String[]{"S/No","Defect_Id","Issue Description","Solved By","Ticket count"};
}
else if(value==1){
str=new String[]{"S/No","Mail Issue","Solved By"};
}
else if(value==2){
str=new String[]{"S/No","Highlights","Solved By"};
}
else if(value==3){
str=new String[]{"S/No","Month","Ticket Count"};
}
else if(value==4){
str=new String[]{"S/No","PI","Solved By"};
}
totalList.add(str);
for(Object obj : data.entrySet())
{
entry = (Map.Entry)obj;
totalList.add((String[]) entry.getValue());
}
for(int i=1;i<totalList.size();i++)
{
String str1[]=totalList.get(i);
for(int j=0;j<str1.length;j++)
{
System.out.print(" value:: "+str1[j]);
}
System.out.println();
}
return totalList;
}
}