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
package mobvista.prd.datasource.table;
import com.google.common.collect.Lists;
import org.apache.poi.hssf.usermodel.*;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
/**
* Created by Administrator on 2017/3/3 0003.
*/
public class CreateMInterestTable {
public static void main(String[] args) throws IOException {
List<String> list = readCountry("./mCountInterest.txt");
FileOutputStream fos = new FileOutputStream("./M系统Top30国家兴趣.xls");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
List<String> head = Lists.newArrayList();//表头
head.add("Country");
head.add("Interest Tag 1");
head.add("Interest Tag 2");
head.add("Mintegral device");
int columnHead = 0;
HSSFRow rowOne = s.createRow(0);
for (String column : head) {
HSSFCell cell = rowOne.createCell(columnHead, 0);
HSSFRichTextString hts = new HSSFRichTextString(column);
cell.setCellValue(hts);
columnHead++;
}
int row = 1;
for (String column : list) {
columnHead = 0;
rowOne = s.createRow(row);
String[] fields = column.split("\t", -1);
int num = 0;
for (String field : fields) {
HSSFCell cell = rowOne.createCell(columnHead, 0);
if (num == 0) {
String country = field.split(":",-1)[0];
cell = rowOne.createCell(columnHead, 0);
HSSFRichTextString hts = new HSSFRichTextString(country);
cell.setCellValue(hts);
columnHead++;
String interestOne = field.split(":",-1)[1];
cell = rowOne.createCell(columnHead, 0);
hts = new HSSFRichTextString(interestOne);
cell.setCellValue(hts);
columnHead++;
if (field.split(":",-1).length == 3) {
String interestTwo = field.split(":",-1)[2];
cell = rowOne.createCell(columnHead, 0);
hts = new HSSFRichTextString(interestTwo);
cell.setCellValue(hts);
columnHead++;
} else {
columnHead++;
}
num++;
continue;
}
HSSFRichTextString hts = new HSSFRichTextString(field);
cell.setCellValue(hts);
columnHead++;
}
row++;
}
wb.write(fos);
fos.flush();
fos.close();
}
public static List<String> readCountry(String file) throws IOException {
List<String> list = Lists.newArrayList();
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String s = br.readLine();
while (s != null) {
String[] fields = s.split("\t", -1);
String one;
if (fields[2] == null || fields[2].equals("NULL") || fields[2].equals("")) {
one = fields[0] + ":" + fields[1];
} else {
one = fields[0] + ":" + fields[1] + ":" + fields[2];
}
list.add(one + "\t" + fields[3]);
s = br.readLine();
}
br.close();
fr.close();
return list;
}
}