欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

寫(xiě)excel文件-創(chuàng)新互聯(lián)

package excel;寫(xiě)excel文件

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

成都創(chuàng)新互聯(lián)主營(yíng)雙清網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都app軟件開(kāi)發(fā)公司,雙清h5小程序制作搭建,雙清網(wǎng)站營(yíng)銷(xiāo)推廣歡迎雙清等地區(qū)企業(yè)咨詢

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.util.CellRangeAddress;

public class ExcelFile {

public static List<Integer> findEquals(int[] result, int value) {
List<Integer> bigList = new ArrayList<Integer>();
for (int i = 0; i < result.length; i++) {
if (result[i] == value) {
bigList.add(i + 1);
}
}
return bigList;
}

public static void main(String[] args) {
// TODO Auto-generated method stub
HSSFWorkbook wb = new HSSFWorkbook();
FileOutputStream out = null;
FileReader in = null;
BufferedReader br = null;
List<String> content = new ArrayList<String>();
try {
out = new FileOutputStream("result.xls");
in = new FileReader("1.txt");
br = new BufferedReader(in);
String line = br.readLine();
while (line != null) {
content.add(line);
line = br.readLine();
}
int[] result = new int[30];
for (int i = content.size() - 1; i >= 0; i--) {

String[] lines = content.get(i).split(" ");
for (int j = 1; j < lines.length; j++) {
result[Integer.parseInt(lines[j]) - 1]++;
}
int[] sort = Arrays.copyOf(result, result.length);
Arrays.sort(sort);
HSSFSheet sheet = wb.createSheet(lines[0]);
for (int j = 0; j < result.length; j++) {
HSSFRow row = sheet.createRow(j);
HSSFCell cell = row.createCell(0);
cell.setCellValue(result[j]);
}

Map<Integer, Integer> tmpHash = new HashMap<Integer, Integer>();
if (i - 1 >= 0) {
String[] nextlines = content.get(i - 1).split(" ");
for (int j = 1; j < nextlines.length; j++) {
Integer key = Integer.parseInt(nextlines[j]);
if (tmpHash.get(result[key - 1]) != null) {
Integer value = tmpHash.get(result[key - 1]);
value = value + 1;
tmpHash.put(result[key - 1], value);
} else {
tmpHash.put(result[key - 1], 1);
}
}
}

for (int j = sort[0]; j <= sort[sort.length - 1]; j++) {
HSSFRow row = sheet.createRow(j + 39 - sort[0]);
HSSFCell cell = row.createCell(0);
HSSFCell formal = row.createCell(1);
cell.setCellValue(j);
formal.setCellFormula("COUNTIF(A1:A30,A" + (j + 40 - sort[0]) + ")");
if (tmpHash.get(j) != null) {
HSSFCell num = row.createCell(2);
num.setCellValue(tmpHash.get(j));
}
List tmp = findEquals(result,j);
HSSFCell numcell = row.createCell(3);
numcell.setCellValue(tmp.toString());
}

CellRangeAddress region = new CellRangeAddress(39, 45, 5, 8);
sheet.addMergedRegion(region);
HSSFRow row = sheet.getRow(39);
HSSFCell cell = row.createCell(5);

List<Integer> big = new ArrayList<Integer>();
for (int j = sort.length - 1; j > sort.length - 7; j--) {
List<Integer> bigtmp = findEquals(result, sort[j]);
for (Integer k : bigtmp) {
if (!big.contains(k))
big.add(k);
}
if (big.size() > 7) {
break;
}
}
StringBuffer tmp = new StringBuffer();
for (int j : big) {
tmp.append(j + " ");
}
tmp.append(" little:");
List<Integer> little = new ArrayList<Integer>();

for (int j = 0; j < 7; j++) {
List<Integer> littletmp = findEquals(result, sort[j]);
for (Integer k : littletmp) {
if (!little.contains(k))
little.add(k);
}
if (little.size() > 7) {
break;
}
}
for (int j : little) {
tmp.append(j + " ");
}
cell.setCellValue("big:" + tmp.toString());

Font font = wb.createFont();
// 設(shè)置字體樣式
font.setFontHeightInPoints((short) 12);
font.setFontName("Courier New");
font.setBold(true);
HSSFCellStyle style = wb.createCellStyle(); // 樣式對(duì)象
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平
style.setFont(font);
style.setWrapText(true);
cell.setCellStyle(style);
sheet.autoSizeColumn(3);

}

wb.write(out);
System.out.println("success!");
} catch (Exception e) {
e.printStackTrace();

} finally {
try {
out.close();
in.close();
br.close();
wb.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

}

標(biāo)題名稱:寫(xiě)excel文件-創(chuàng)新互聯(lián)
新聞來(lái)源:http://chinadenli.net/article22/cohgcc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)靜態(tài)網(wǎng)站品牌網(wǎng)站制作微信公眾號(hào)服務(wù)器托管自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)