tableToExcel工具类,此工具类指定格式的表格进行转Excel

格式:其中不能带有thead,tbody和th标签

<table>
<tr>
<td>表头1</td>
<td>表头2</td>
<td>表头3</td>
<td>表头4</td>
</tr>
<tr>
<td>数据1</td>
<td>数据2</td>
<td>数据3</td>
<td>数据4</td>
</tr>
<tr>
<td>数据1</td>
<td>数据2</td>
<td>数据3</td>
<td>数据4</td>
</tr>
</table>

工具类:

package com.zx.erjiqualitydata;

import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFCell;
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.hssf.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Workbook;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.springframework.util.ClassUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; public class TableToExcel {
/**
* @author lusong
* @param sheetName
* @param html
* @param headNum表头的行数
* @throws FileNotFoundException
* zyn
* 2012-12-21 下午1:44:02
*/
public static String tableToExcel(String sheetName,String html,int headNum) throws FileNotFoundException{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet(sheetName);
CellStyle headStyle = createHeadStyle(wb);
CellStyle bodyStyle = createBodyStyle(wb);
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
String filePath = request.getSession().getServletContext().getRealPath("/static/document");
String path = filePath+"\\"+sheetName+".xlsx";
FileOutputStream os = new FileOutputStream(path);
SAXBuilder sb = new SAXBuilder();
try {
ByteArrayInputStream is = new ByteArrayInputStream(html.getBytes("UTF-8"));
Document document = sb.build(is);
//获取table节点
Element root = document.getRootElement();
//获取tr的list
List<Element> trList = root.getChildren("tr");
int[][] area = getCellArea(trList);
//循环创建行
for(int i=0;i<trList.size();i++){
HSSFRow row = sheet.createRow(i);
List<Element> tdList = trList.get(i).getChildren("td");
//该行td的序号
int tdIndex = 0;
for(int ii=0;ii<area[i].length;ii++){
row.createCell(ii);
HSSFCell cell = row.getCell(ii);
//判断是否为表头,使用对应的excel格式
if(i<headNum){
cell.setCellStyle(headStyle);
}else{
cell.setCellStyle(bodyStyle);
}
//如果对应的矩阵数字为1,则和横向前一单元格合并
if(area[i][ii]==1){
sheet.addMergedRegion(new CellRangeAddress(i,i,ii-1,ii));
}else if(area[i][ii]==2){//如果对应的矩阵数字为2,则和纵向的前一单元格合并
sheet.addMergedRegion(new CellRangeAddress(i-1,i,ii,ii));
}else{//如果为0,显示td中对应的文字,td序号加1
cell.setCellValue(getInnerText(tdList.get(tdIndex)));
tdIndex ++;
} } }
wb.write(os); } catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "static/document/"+sheetName+".xlsx";
} /**
* 导出excel表格二维数组:0为文字占用格,1为横向被合并格,2为纵向合并格
* @param trList
* @return
* zyn
* 2012-12-21 下午1:35:40
*/
private static int[][] getCellArea(List<Element> trList){
//获取table单元格矩阵
Element headtr = trList.get(0);
List<Element> headTdList = headtr.getChildren("td");
//每行的未经合并的单元格个数
int cols = 0;
for(Element e:headTdList){
int colspan = Integer.valueOf(null==e.getAttributeValue("colspan")?"0":e.getAttributeValue("colspan"));
if(colspan==0){
colspan =1;
}
cols += colspan;
}
//初始化单元格矩阵
int[][] area = new int[trList.size()][cols];
for(int i=0;i<trList.size();i++){
Element tr = trList.get(i);
List<Element> tdList = tr.getChildren("td");
//该行到ii个单元格为止被合并的单元格个数
int rowColspan = 0;
for(int ii=0;ii<tdList.size();ii++){
//本单元格跨度计算前的td数
int oldIndex = ii+rowColspan;
Element td = tdList.get(ii);
int colspan = Integer.valueOf(null==td.getAttributeValue("colspan")?"0":td.getAttributeValue("colspan"));
//colspan为0或者1证明未合并
colspan = colspan>1?colspan:1;
rowColspan += colspan-1;
//单元格需要被横向合并声明为1
for(int m=1;m<colspan;m++){
area[i][oldIndex+m]=1;
}
int rowspan = Integer.valueOf(null==td.getAttributeValue("rowspan")?"0":td.getAttributeValue("rowspan"));
rowspan = rowspan>1?rowspan:1;
//单元格需要被纵向向合并声明为2
for(int m=1;m<rowspan;m++){
area[m+i][oldIndex] = 2;
}
}
}
/*for(int a=0;a<area.length;a++){
for(int b =0;b<area[0].length;b++){
System.out.print(area[a][b]);
}
System.out.println("");
}*/
return area;
} /**-
* 设置表头样式
* @param wb
* @return
*/
private static CellStyle createHeadStyle(Workbook wb){
CellStyle style = wb.createCellStyle();
Font headerFont = wb.createFont();
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setFont(headerFont); style.setBorderRight(CellStyle.BORDER_THIN);
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderTop(CellStyle.BORDER_THIN);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
return style;
} /**-
* 设置表单记录样式
* @param wb
* @return
*/
private static CellStyle createBodyStyle(Workbook wb){
CellStyle style = wb.createCellStyle();
Font headerFont = wb.createFont();
headerFont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setFont(headerFont); style.setBorderRight(CellStyle.BORDER_THIN);
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderTop(CellStyle.BORDER_THIN);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
return style;
} private static String getInnerText(Element td){
String txt = "";
if(td.getText()==null || td.getText().equals("")){
if(null != td.getChildren()){
for(int i=0;i<td.getChildren().size();i++){
Element e = (Element)td.getChildren().get(i);
txt += getInnerText(e);
}
}
}else{
txt = td.getText();
}
return txt;
} public static void main(String[] args) throws FileNotFoundException {
// // TODO Auto-generated method stub
// TableToExcelUtil tu = new TableToExcelUtil();
// System.out.println(tu.getInnerHtml(\"<td><a>1</a></td>\"));
String tableHtmlString = "<table class=\"zx_total_table dataTable no-footer\" style=\"width: 100%; margin: 0px auto;\" id=\"rf_table\" role=\"grid\"><thead><tr role=\"row\" style=\"height: 0px;\"><th class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 241px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\">医疗机构名称</div></th><th class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 162px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\">级别</div></th><th class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 83px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\">类别</div></th><th class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 83px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\">属性</div></th><th class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 163px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\">所有制</div></th><th class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 441px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\">所在地</div></th></tr></thead><tbody><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>三级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>三级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>公有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>三级医院</td><td>综合</td><td>公立</td><td>公有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">省三院</td><td>二级医院</td><td>综合</td><td>公立</td><td>公有制</td><td>河北省-石家庄市-长安区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">省三院</td><td>二级医院</td><td>综合</td><td>公立</td><td>阿斯蒂芬</td><td>北京-北京市-东城区</td></tr></tbody>"; //tableToExcel("缴费统计", "<table ><tr role=\"row\" style=\"height: 0px;\"><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 174px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\"></div></td><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 174px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\"></div></td><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 89px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\"></div></td><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 90px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\"></div></td><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 174px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\"></div></td><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 472px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\"><div class=\"dataTables_sizing\" style=\"height:0;overflow:hidden;\"></div></td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>三级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>三级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>公有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>三级医院</td><td>综合</td><td>公立</td><td>公有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">省三院</td><td>二级医院</td><td>综合</td><td>公立</td><td>公有制</td><td>河北省-石家庄市-长安区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">省三院</td><td>二级医院</td><td>综合</td><td>公立</td><td>阿斯蒂芬</td><td>北京-北京市-东城区</td></tr></table>", 1);
tableToExcel("缴费统计", "<table class=\"zx_total_table dataTable no-footer\" style=\"width: 100%; margin: 0px auto;\" id=\"rf_table\" role=\"grid\"><tr role=\"row\" style=\"height: 0px;\"><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 241px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\">医疗机构名称</td><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 162px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\">级别</td><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 83px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\">类别</td><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 83px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\">属性</td><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 163px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\">所有制</td><td class=\"sorting\" aria-controls=\"rf_table\" rowspan=\"1\" colspan=\"1\" style=\"width: 441px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;\">所在地</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>三级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>三级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>公有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">河北二院</td><td>三级医院</td><td>综合</td><td>公立</td><td>公有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">河北二院</td><td>二级医院</td><td>综合</td><td>公立</td><td>私有制</td><td>河北省-石家庄市-裕华区</td></tr><tr role=\"row\" class=\"odd\"><td class=\"sorting_1\">省三院</td><td>二级医院</td><td>综合</td><td>公立</td><td>公有制</td><td>河北省-石家庄市-长安区</td></tr><tr role=\"row\" class=\"even\"><td class=\"sorting_1\">省三院</td><td>二级医院</td><td>综合</td><td>公立</td><td>阿斯蒂芬</td><td>北京-北京市-东城区</td></tr></table>", 1);
} }

html table导出到Excel中,走后台保存文件,js并调用另保存的更多相关文章

  1. html table表格导出excel的方法 html5 table导出Excel HTML用JS导出Excel的五种方法 html中table导出Excel 前端开发 将table内容导出到excel HTML table导出到Excel中的解决办法 js实现table导出Excel,保留table样式

    先上代码   <script type="text/javascript" language="javascript">   var idTmr; ...

  2. C# html的Table导出到Excel中

    C#中导出Excel分为两大类.一类是Winform的,一类是Web.今天说的这一种是Web中的一种,把页面上的Table部分导出到Excel中. Table导出Excel,简单点说,分为以下几步: ...

  3. HTML table导出到Excel中的解决办法

    第一部分:html+js 1.需要使用的表格数据(先不考虑动态生成的table) <table class="table tableStyles" id="tabl ...

  4. html table导出到Excel中,不走后台,js完成

    静态表格table <table class="table tableStyles" id="tables"> <caption>不正经 ...

  5. 【ASP.NET】C# 将HTML中Table导出到Excel(TableToExcel)

    首先,说下应用场景 就是,把页面呈现的Table 导出到Excel中.其中使用的原理是 前台使用ajax调用aspx后台,传递过去参数值,导出.使用的组件是NPOI. 前台调用: <script ...

  6. 将datagrid中数据导出到excel中 -------<<工作日志2014-6-6>>

    前台datagrid数据绑定 #region 导出到excel中    /// <summary>    /// 2014-6-6    /// </summary>    / ...

  7. HTML Table导出为Excel的方法

    HTML Table导出为Excel的方法: 直接上源码 <html> <head> <meta http-equiv="Content-Type" ...

  8. 将Datagridview中的数据导出至Excel中

        首先添加一个模块ImportToExcel,并添加引用         然后导入命名空间: Imports Microsoft.Office.Interop Imports System.Da ...

  9. html table 保存到excel中

    引用:HTML中的table导出为Excel文件 <!DOCTYPE html> <html lang="en"> <head> <met ...

随机推荐

  1. 使用注解来构造IoC容器-转

    新手,对于一些觉得有用的东西,直接转过来用了,自己理解的比较肤浅 使用注解来构造IoC容器 用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<co ...

  2. php memcache知识点总结

    $memcache = new Memcache; $memcache->connect('localhost',11211) or die('Could not connect'); //me ...

  3. Vue的watch和computed属性

    Vue的watch属性 Vue的watch属性可以用来监听data属性中数据的变化 <!DOCTYPE html> <html> <head> <meta c ...

  4. CSU - 1551 Longest Increasing Subsequence Again —— 线段树/树状数组 + 前缀和&后缀和

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551 题意: 给出一段序列, 删除其中一段连续的子序列(或者不删), 使得剩下的序列 ...

  5. Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和

    题目链接:http://codeforces.com/contest/731/problem/F F. Video Cards time limit per test 1 second memory ...

  6. Codeforces Round #376 (Div. 2) C. Socks —— 并查集 + 贪心

    题目链接:http://codeforces.com/contest/731/problem/C 题解: 1.看题目时,大概知道,不同的袜子会因为要在同一天穿而差生了关联(或者叫相互制约), 其中一条 ...

  7. Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题

    题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...

  8. Zookeeper实现Master选举(哨兵机制)

    master选举使用场景及结构 现在很多时候我们的服务需要7*24小时工作,假如一台机器挂了,我们希望能有其它机器顶替它继续工作.此类问题现在多采用master-salve模式,也就是常说的主从模式, ...

  9. 测试工程师面试题之:给你印象最深的Bug

    有人看到别人在侵淫面试技巧,什么<程序员面试宝典>,或者<面试测试工程师须知>等等,就会嗤之以鼻.他会觉得这不是“投机取巧”吗,最重要的还是踏实提高自己的能力. 非常同意这种看 ...

  10. java IO流文件的读写具体实例(转载)

    引言: 关于java IO流的操作是非常常见的,基本上每个项目都会用到,每次遇到都是去网上找一找就行了,屡试不爽.上次突然一个同事问了我java文件的读取,我一下子就懵了第一反应就是去网上找,虽然也能 ...