-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWrite.java
More file actions
100 lines (61 loc) · 2.45 KB
/
Write.java
File metadata and controls
100 lines (61 loc) · 2.45 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
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
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.Row;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
/**
* Box_Excel
*
* @author Wiliam Andersson
* @version 6 mars 2017
*
* Write klassen skriver ut datan i cellerna för varje kund och sparar det sedan
* i respektive mapp i molnlagringen för att sedan kunna användas av kunderna.
*
*/
public class Write {
public static void write(int amount, String url, String mapp) throws IOException {
SXSSFWorkbook workbook = new SXSSFWorkbook();
SXSSFSheet sheet = workbook.createSheet("Appendix 1");
sheet.createFreezePane(0,0);
workbook.getSheetAt(workbook.getActiveSheetIndex()).createFreezePane(0, 1);
Row row1 = sheet.createRow(0);
for(int u = 0; u <Read.colNum; u++) {
Cell cell1 = row1.createCell(u);
//Ökar storleken på första raden
row1.setHeightInPoints(35);
cell1.setCellValue(Read.top[u]);
}
//Inititerar en cellstill och sätter typsnittet till fet.
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
style.setFont(font);
//Här sätts de översta cellerna till fet.
for(int i = 0; i < Read.colNum; i++)
{
row1.getCell(i).setCellStyle(style);
}
for(int j = 0; j < Read.customersLength[amount+1]; j++)
{
Row row = sheet.createRow(j+1);
for(int i = 0; i < Read.colNum; i++)
{
Cell cell = row.createCell(i);
cell.setCellValue(Read.data[amount] [j] [i].toString());
}
}
//fryser första raden
workbook.getSheetAt(workbook.getActiveSheetIndex()).createFreezePane(0, 1);
//Här skrivs filerna ut med sitta bestämda namn enligt standard. (Excel_fil_v1_"kundnamnet".xlsx)
workbook.write(new FileOutputStream(url + "/" + mapp + "/" + "Excel_fil_lista_" + Read.data[amount] [0] [0] + ".xlsx"));
workbook.close();
Read.data[amount] = null;
}
}