锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久婷婷国产,日韩一卡二卡三卡,亚洲视频1区2区http://www.aygfsteel.com/shimingming/J2EE鐩稿叧鎶鏈葷粨zh-cnTue, 03 Jun 2025 18:18:16 GMTTue, 03 Jun 2025 18:18:16 GMT60- POI鎿嶄綔http://www.aygfsteel.com/shimingming/archive/2012/08/20/385860.html鍙叉槑鏄?/dc:creator>鍙叉槑鏄?/author>Mon, 20 Aug 2012 07:09:00 GMThttp://www.aygfsteel.com/shimingming/archive/2012/08/20/385860.htmlhttp://www.aygfsteel.com/shimingming/comments/385860.htmlhttp://www.aygfsteel.com/shimingming/archive/2012/08/20/385860.html#Feedback0http://www.aygfsteel.com/shimingming/comments/commentRss/385860.htmlhttp://www.aygfsteel.com/shimingming/services/trackbacks/385860.html
鍏堣幏鍙栧伐浣滆杽瀵硅薄:
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFCellStyle setBorder = wb.createCellStyle();
涓銆佽緗儗鏅壊錛?br />
setBorder.setFillForegroundColor((short) 13);// 璁劇疆鑳屾櫙鑹?br />
setBorder.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
浜屻佽緗竟妗?
setBorder.setBorderBottom(HSSFCellStyle.BORDER_THIN); //涓嬭竟妗?br />
setBorder.setBorderLeft(HSSFCellStyle.BORDER_THIN);//宸﹁竟妗?br />
setBorder.setBorderTop(HSSFCellStyle.BORDER_THIN);//涓婅竟妗?br />
setBorder.setBorderRight(HSSFCellStyle.BORDER_THIN);//鍙寵竟妗?br />
涓夈佽緗眳涓?
setBorder.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 灞呬腑
鍥涖佽緗瓧浣?
HSSFFont font = wb.createFont();
font.setFontName("榛戜綋");
font.setFontHeightInPoints((short) 16);//璁劇疆瀛椾綋澶у皬
HSSFFont font2 = wb.createFont();
font2.setFontName("浠垮畫_GB2312");
font2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//綺椾綋鏄劇ず
font2.setFontHeightInPoints((short) 12);
setBorder.setFont(font);//閫夋嫨闇瑕佺敤鍒扮殑瀛椾綋鏍煎紡
浜斻佽緗垪瀹?
sheet.setColumnWidth(0, 3766); //絎竴涓弬鏁頒唬琛ㄥ垪id(浠?寮濮?,絎?涓弬鏁頒唬琛ㄥ搴﹀?br />
鍏佽緗嚜鍔ㄦ崲琛?
setBorder.setWrapText(true);//璁劇疆鑷姩鎹㈣
涓冦佸悎騫跺崟鍏冩牸:
Region region1 = new Region(0, (short) 0, 0, (short) 6);
//鍙傛暟1錛氳鍙?鍙傛暟2錛氳搗濮嬪垪鍙?鍙傛暟3錛氳鍙?鍙傛暟4錛氱粓姝㈠垪鍙?br />
sheet.addMergedRegion(region1);
闄勪竴涓畬鏁寸殑渚嬪瓙錛?br />
package cn.com.util;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.usermodel.CellStyle;
import java.io.FileOutputStream;
import javax.servlet.http.HttpServlet;
public class CreateXL extends HttpServlet {
/** Excel 鏂囦歡瑕佸瓨鏀劇殑浣嶇疆錛屽亣瀹氬湪D鐩樹笅 */
public static String outputFile = "c:test.xls";
private void cteateCell(HSSFWorkbook wb, HSSFRow row, short col, String val) {
HSSFCell cell = row.createCell(col);
// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(val);
HSSFCellStyle cellstyle = wb.createCellStyle();
cellstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION);
cell.setCellStyle(cellstyle);
}
public static void main(String argv[]) {
try {
// 鍒涘緩鏂扮殑Excel 宸ヤ綔綈?br />
HSSFWorkbook workbook = new HSSFWorkbook();
// 璁劇疆瀛椾綋
HSSFFont font = workbook.createFont();
// font.setColor(HSSFFont.COLOR_RED);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setFontHeightInPoints((short) 14);
// HSSFFont font2 = workbook.createFont();
// font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
// font.setFontHeightInPoints((short)14);
// 璁劇疆鏍峰紡
HSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFont(font);
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// HSSFCellStyle cellStyle2= workbook.createCellStyle();
// cellStyle.setFont(font2);
// cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// 鍦‥xcel宸ヤ綔綈夸腑寤轟竴宸ヤ綔琛紝鍏跺悕涓虹己鐪佸?br />
// 濡傝鏂板緩涓鍚嶄負"鏈堟姤琛?鐨勫伐浣滆〃錛屽叾璇彞涓猴細
HSSFSheet sheet = workbook.createSheet("鏈堟姤琛?);
CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 0, 0,
11);
sheet.addMergedRegion(cellRangeAddress);
//絎竴琛?br />
// 鍦ㄧ儲寮?鐨勪綅緗垱寤鴻錛堟渶欏剁鐨勮錛?br />
HSSFRow row = sheet.createRow(0);
// 鍦ㄧ儲寮?鐨勪綅緗垱寤哄崟鍏冩牸錛堝乏涓婄錛?br />
HSSFCell cell = row.createCell(0);
// 瀹氫箟鍗曞厓鏍間負瀛楃涓茬被鍨?br />
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellStyle(cellStyle);
// 鍦ㄥ崟鍏冩牸涓緭鍏ヤ竴浜涘唴瀹?br />
cell.setCellValue(new HSSFRichTextString("鍖椾含浜垮崱鑱旂鎶鍙戝睍鏈夐檺鍏徃灝忓尯闂ㄧ緇翠慨鏈堟姤琛?));
//絎簩琛?br />
cellRangeAddress = new CellRangeAddress(1, 1, 3, 6);
sheet.addMergedRegion(cellRangeAddress);
row = sheet.createRow(1);
HSSFCell datecell = row.createCell(3);
datecell.setCellType(HSSFCell.CELL_TYPE_STRING);
datecell.setCellStyle(cellStyle);
datecell.setCellValue("鏃墮棿闂撮殧xxxxx");
cellRangeAddress = new CellRangeAddress(1, 1, 9,
10);
sheet.addMergedRegion(cellRangeAddress);
row.createCell(9).setCellValue("鍗曚綅錛氬厓");
//絎笁琛?br />
row=sheet.createRow(2);
row.createCell(0).setCellValue("涓銆?);
row.createCell(1).setCellValue("鍩烘湰璧勬枡");
//絎?琛?br />
row=sheet.createRow(3);
row.createCell(1).setCellValue("灝忓尯鍚嶇О錛?);
cellRangeAddress=new CellRangeAddress(3,3,2,11);
sheet.addMergedRegion(cellRangeAddress);
row.createCell(2).setCellValue("xxxxx");
//絎?琛?br />
row=sheet.createRow(4);
row.createCell(1).setCellValue("搴ц惤鍦扮偣錛?);
cellRangeAddress=new CellRangeAddress(4,4,2,11);
sheet.addMergedRegion(cellRangeAddress);
row.createCell(2).setCellValue("xxxxx");
//絎?琛?br />
row=sheet.createRow(5);
row.createCell(1).setCellValue("寤烘垚騫存湀錛?);
cellRangeAddress=new CellRangeAddress(5,5,2,4);
sheet.addMergedRegion(cellRangeAddress);
row.createCell(2).setCellValue("騫存湀鏃ワ細xxxxx");
row.createCell(5).setCellValue("鑱旂郴浜?);
cellRangeAddress=new CellRangeAddress(5,5,6,8);
sheet.addMergedRegion(cellRangeAddress);
row.createCell(6).setCellValue("XXX");
row.createCell(9).setCellValue("鐢佃瘽");
cellRangeAddress=new CellRangeAddress(5,5,10,11);
sheet.addMergedRegion(cellRangeAddress);
row.createCell(10).setCellValue("XXX");
//絎?琛?br />
row=sheet.createRow(6);
row.createCell(1).setCellValue("浣忔埛錛?);
row.createCell(2).setCellValue("(XX)");
row.createCell(3).setCellValue("(鎴?");
cellRangeAddress=new CellRangeAddress(6,6,4,5);
sheet.addMergedRegion(cellRangeAddress);
row.createCell(4).setCellValue("鍏辮錛?nbsp; 錛?);
row.createCell(6).setCellValue("騫?);
cellRangeAddress=new CellRangeAddress(6,6,7,8);
sheet.addMergedRegion(cellRangeAddress);
row.createCell(7).setCellValue("鍙戝崱寮犳暟");
cellRangeAddress=new CellRangeAddress(6,6,9,10);
sheet.addMergedRegion(cellRangeAddress);
row.createCell(9).setCellValue("xxxx");
//絎?琛?br />
row=sheet.createRow(8);
row.createCell(0).setCellValue("浜屻?);
cellRangeAddress=new CellRangeAddress(8,8,1,2);
sheet.addMergedRegion(cellRangeAddress);
row.createCell(1).setCellValue("緇翠慨鐢ㄦ潗鏂欏彴璐?);
row.createCell(6).setCellValue("涓夈?);
cellRangeAddress=new CellRangeAddress(8,8,7,9);
sheet.addMergedRegion(cellRangeAddress);
row.createCell(7).setCellValue("緇翠慨宸ユ椂璁板綍");
//絎?0琛?br />
row=sheet.createRow(9);
row.createCell(0).setCellValue("鏃ユ湡");
row.createCell(1).setCellValue("緇翠慨浜嬮」");
row.createCell(2).setCellValue("鏉愭枡娓呭崟");
row.createCell(3).setCellValue("鏁伴噺");
row.createCell(4).setCellValue("鍗曚環");
row.createCell(5).setCellValue("鏉愭枡閲戦");
row.createCell(7).setCellValue("鏃ユ湡");
row.createCell(8).setCellValue("鎶宸?);
row.createCell(9).setCellValue("宸ユ椂鏁?);
row.createCell(10).setCellValue("鍗曚環");
row.createCell(11).setCellValue("宸ユ椂閲戦");
//濉厖鏁版嵁
for (int i = 0; i < 10; i++) {
row=sheet.createRow(9+i+1);
row.createCell(0).setCellValue("鏃ユ湡");
row.createCell(1).setCellValue("緇翠慨浜嬮」");
row.createCell(2).setCellValue("鏉愭枡娓呭崟");
row.createCell(3).setCellValue("鏁伴噺");
row.createCell(4).setCellValue("鍗曚環");
row.createCell(5).setCellValue("鏉愭枡閲戦");
row.createCell(7).setCellValue("鏃ユ湡");
row.createCell(8).setCellValue("鎶宸?);
row.createCell(9).setCellValue("宸ユ椂鏁?);
row.createCell(10).setCellValue("鍗曚環");
row.createCell(11).setCellValue("宸ユ椂閲戦");
}
//絎琻+10琛?br />
row=sheet.createRow(9+10+1);
//cellRangeAddress=new CellRangeAddress(19,19,0,4);
//sheet.addMergedRegion(cellRangeAddress);
row.createCell(0).setCellValue("绱:");
row.createCell(1).setCellValue("xxx");
row.createCell(7).setCellValue("绱:");
row.createCell(8).setCellValue("xxx");
// 鏂板緩涓杈撳嚭鏂囦歡嫻?br />
FileOutputStream fOut = new FileOutputStream(outputFile);
// 鎶婄浉搴旂殑Excel 宸ヤ綔綈垮瓨鐩?br />
workbook.write(fOut);
fOut.flush();
// 鎿嶄綔緇撴潫錛屽叧闂枃浠?br />
fOut.close();
System.out.println("鏂囦歡鐢熸垚...");
} catch (Exception e) {
System.out.println("宸茶繍琛?xlCreate() : " + e);
}
}
}

]]>
主站蜘蛛池模板:
芜湖县|
平安县|
周宁县|
都匀市|
嘉峪关市|
宝鸡市|
东至县|
罗甸县|
普洱|
修水县|
嘉义市|
阿巴嘎旗|
清丰县|
中卫市|
玉环县|
库车县|
康乐县|
五台县|
龙游县|
铁岭市|
襄垣县|
奇台县|
康保县|
临夏县|
三明市|
塘沽区|
台东市|
安塞县|
白朗县|
中江县|
鲁甸县|
中宁县|
安丘市|
博乐市|
海安县|
田林县|
龙里县|
营口市|
怀宁县|
英德市|
伊吾县|