public void testCascade2007() {
//得到第一级省名称,放在列表里
List list = UtilExcel.makeProvNameList();
String[] provinceArr =list.toArray(new String[]{});
// 创建一个excel
Workbook book = new XSSFWorkbook();
Font font2 = book.createFont();
//font2.setFontName("微软雅黑");
font2.setColor(Font.COLOR_RED);
Font font3 = book.createFont();
//font2.setFontName("微软雅黑");
font3.setColor(Font.COLOR_NORMAL);
//font2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 粗体显示
//font2.setFontHeightInPoints((short)12);
// 创建需要用户填写的数据页
// 设计表头
Sheet sheet1 = book.createSheet("sheet1");
Row row0 = sheet1.createRow(0);
// row0.createCell(0).setCellValue("<必填>订单类型");
Cell cell0 = row0.createCell(0);
RichTextString text0 = new XSSFRichTextString("<必填>发货省");
text0.applyFont(0, 7, font2); // 0, 1 表示应用字体的范围
cell0.setCellValue(text0); // 设置单元格的值
sheet1.setColumnWidth(0, 15* 256);
//row0.createCell(1).setCellValue("<必填>订单服务类型");
Cell cell1 = row0.createCell(1);
RichTextString text1 = new XSSFRichTextString("<必填>发货市");
text1.applyFont(0, 7, font2); // 0, 1 表示应用字体的范围
cell1.setCellValue(text1); // 设置单元格的值
sheet1.setColumnWidth(1, 19* 256);
//row0.createCell(2).setCellValue("<必填>选择店铺");
Cell cell2 = row0.createCell(2);
RichTextString text2 = new XSSFRichTextString("<必填>发货县");
text2.applyFont(0, 7, font2); // 0, 1 表示应用字体的范围
cell2.setCellValue(text2); // 设置单元格的值
sheet1.setColumnWidth(2, 15* 256);
row0.createCell(3).setCellValue("发货详细地址");
sheet1.setColumnWidth(3, 12* 256);
Cell cell4 = row0.createCell(4);
RichTextString text4 = new XSSFRichTextString("<必填>收货省");
text4.applyFont(0, 7, font2); // 0, 1 表示应用字体的范围
cell4.setCellValue(text4); // 设置单元格的值
sheet1.setColumnWidth(4, 15* 256);
Cell cell5 = row0.createCell(5);
RichTextString text5 = new XSSFRichTextString("<必填>收货市");
text5.applyFont(0, 7, font2); // 0, 1 表示应用字体的范围
cell5.setCellValue(text5); // 设置单元格的值
sheet1.setColumnWidth(5, 17* 256);
//row0.createCell(6).setCellValue("<必填>收货人手机");
Cell cell6 = row0.createCell(6);
RichTextString text6 = new XSSFRichTextString("<必填>收货县");
text6.applyFont(0, 7, font2); // 0, 1 表示应用字体的范围
cell6.setCellValue(text6); // 设置单元格的值
sheet1.setColumnWidth(6, 17* 256);
row0.createCell(7).setCellValue("收货详细地址");
sheet1.setColumnWidth(7, 12* 256);
row0.createCell(8).setCellValue("发货人姓名");
sheet1.setColumnWidth(8, 12* 256);
row0.createCell(9).setCellValue("发货人电话");
sheet1.setColumnWidth(9, 12* 256);
row0.createCell(10).setCellValue("收货人姓名");
sheet1.setColumnWidth(10, 12* 256);
row0.createCell(11).setCellValue("收货人电话");
sheet1.setColumnWidth(11, 12* 256);
row0.createCell(12).setCellValue("发货开始时间");
sheet1.setColumnWidth(12, 12* 256);
row0.createCell(13).setCellValue("收货截止时间");
sheet1.setColumnWidth(13, 12* 256);
Cell cell14 = row0.createCell(14);
RichTextString text14 = new XSSFRichTextString("<必填>货物大类");
text14.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell14.setCellValue(text14); // 设置单元格的值
sheet1.setColumnWidth(14, 17* 256);
Cell cell15 = row0.createCell(15);
RichTextString text15 = new XSSFRichTextString("<必填>货物小类");
text15.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell15.setCellValue(text15); // 设置单元格的值
sheet1.setColumnWidth(14, 17* 256);
Cell cell16 = row0.createCell(16);
RichTextString text16 = new XSSFRichTextString("<必填>货物名称");
text16.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell16.setCellValue(text16); // 设置单元格的值
sheet1.setColumnWidth(14, 17* 256);
Cell cell17 = row0.createCell(17);
RichTextString text17 = new XSSFRichTextString("<必填>发货量");
text17.applyFont(0, 7, font2); // 0, 1 表示应用字体的范围
cell17.setCellValue(text17); // 设置单元格的值
sheet1.setColumnWidth(17, 17* 256);
Cell cell18 = row0.createCell(18);
RichTextString text18 = new XSSFRichTextString("<必填>计量单位");
text18.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell18.setCellValue(text18); // 设置单元格的值
sheet1.setColumnWidth(18, 17* 256);
Cell cell19 = row0.createCell(19);
cell19.setCellValue("合理货损"); // 设置单元格的值
sheet1.setColumnWidth(19, 17* 256);
Cell cell20 = row0.createCell(20);
cell20.setCellValue("合理货损类型"); // 设置单元格的值
sheet1.setColumnWidth(20, 17* 256);
Cell cell21 = row0.createCell(21);
RichTextString text21 = new XSSFRichTextString("<必填>货物单价");
text21.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell21.setCellValue(text21); // 设置单元格的值
sheet1.setColumnWidth(21, 17* 256);
Cell cell22 = row0.createCell(22);
RichTextString text22 = new XSSFRichTextString("<必填>运费单价");
text22.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell22.setCellValue(text22); // 设置单元格的值
sheet1.setColumnWidth(21, 17* 256);
Cell cell23 = row0.createCell(23);
RichTextString text23 = new XSSFRichTextString("<必填>车辆类型");
text23.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell23.setCellValue(text23); // 设置单元格的值
sheet1.setColumnWidth(23, 17* 256);
Cell cell24 = row0.createCell(24);
RichTextString text24 = new XSSFRichTextString("<必填>车牌号码");
text24.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell24.setCellValue(text24); // 设置单元格的值
sheet1.setColumnWidth(24, 17* 256);
Cell cell25 = row0.createCell(25);
RichTextString text25 = new XSSFRichTextString("<必填>标准载重");
text25.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell25.setCellValue(text25); // 设置单元格的值
sheet1.setColumnWidth(25, 17* 256);
Cell cell26 = row0.createCell(26);
cell26.setCellValue("车长"); // 设置单元格的值
sheet1.setColumnWidth(26, 12* 256);
Cell cell27 = row0.createCell(27);
RichTextString text27 = new XSSFRichTextString("<必填>司机姓名");
text27.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell27.setCellValue(text27); // 设置单元格的值
sheet1.setColumnWidth(27, 17* 256);
Cell cell28 = row0.createCell(28);
RichTextString text28 = new XSSFRichTextString("<必填>司机电话");
text28.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell28.setCellValue(text28); // 设置单元格的值
sheet1.setColumnWidth(28, 17* 256);
Cell cell29 = row0.createCell(29);
RichTextString text29 = new XSSFRichTextString("<必填>司机身份证");
text29.applyFont(0, 9, font2); // 0, 1 表示应用字体的范围
cell29.setCellValue(text29); // 设置单元格的值
sheet1.setColumnWidth(29, 17* 256);
Cell cell30 = row0.createCell(30);
RichTextString text30 = new XSSFRichTextString("<必填>装车量");
text30.applyFont(0, 7, font2); // 0, 1 表示应用字体的范围
cell30.setCellValue(text30); // 设置单元格的值
sheet1.setColumnWidth(30, 17* 256);
Cell cell31 = row0.createCell(31);
RichTextString text31 = new XSSFRichTextString("<必填>卸车量");
text31.applyFont(0, 7, font2); // 0, 1 表示应用字体的范围
cell31.setCellValue(text31); // 设置单元格的值
sheet1.setColumnWidth(31, 17* 256);
Cell cell32 = row0.createCell(32);
RichTextString text32 = new XSSFRichTextString("<必填>装车时间");
text32.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell32.setCellValue(text32); // 设置单元格的值
sheet1.setColumnWidth(32, 17* 256);
Cell cell33 = row0.createCell(33);
RichTextString text33 = new XSSFRichTextString("<必填>卸车时间");
text33.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell33.setCellValue(text33); // 设置单元格的值
sheet1.setColumnWidth(33, 17* 256);
Cell cell34 = row0.createCell(34);
RichTextString text34 = new XSSFRichTextString("<必填>支付方式");
text34.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell34.setCellValue(text34); // 设置单元格的值
sheet1.setColumnWidth(34, 17* 256);
Cell cell35 = row0.createCell(35);
RichTextString text35 = new XSSFRichTextString("<必填>实付现金");
text35.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell35.setCellValue(text35); // 设置单元格的值
sheet1.setColumnWidth(35, 17* 256);
Cell cell36 = row0.createCell(36);
RichTextString text36 = new XSSFRichTextString("<必填>银行卡号");
text36.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell36.setCellValue(text36); // 设置单元格的值
sheet1.setColumnWidth(36, 17* 256);
Cell cell37 = row0.createCell(37);
RichTextString text37 = new XSSFRichTextString("<必填>开户名称");
text37.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell37.setCellValue(text37); // 设置单元格的值
sheet1.setColumnWidth(37, 17* 256);
Cell cell38 = row0.createCell(38);
RichTextString text38 = new XSSFRichTextString("<必填>开户手机号");
text38.applyFont(0, 8, font2); // 0, 1 表示应用字体的范围
cell38.setCellValue(text38); // 设置单元格的值
sheet1.setColumnWidth(38, 17* 256);
Cell cell39 = row0.createCell(39);
RichTextString text39 = new XSSFRichTextString("<必填>开户行");
text39.applyFont(0, 7, font2); // 0, 1 表示应用字体的范围
cell39.setCellValue(text39); // 设置单元格的值
sheet1.setColumnWidth(39, 17* 256);
Cell cell40 = row0.createCell(40);
cell40.setCellValue("备注"); // 设置单元格的值
sheet1.setColumnWidth(40, 17* 256);
//设置一下高度
row0.setHeightInPoints(20);
Sheet hideSheet = book.createSheet("area");
//这一行作用是将此sheet隐藏,功能未完成时注释此行,可以查看隐藏sheet中信息是否正确
book.setSheetHidden(book.getSheetIndex(hideSheet), true);
int rowId = 0;
// 设置第一行,存省的信息
Row provinceRow = hideSheet.createRow(rowId++);
provinceRow.createCell(0).setCellValue("省列表");
for(int i = 0; i < provinceArr.length; i ++){
Cell provinceCell = provinceRow.createCell(i + 1);
provinceCell.setCellValue(provinceArr[i]);
}
// 将具体的数据写入到每一行中,行开头为父级区域,后面是子区域。
Map> areaMap = UtilExcel.makeSiteMap();
System.out.println(JSON.toJSON(areaMap));
List area = UtilExcel.getAreaFatherNameArr();
String[] areaFatherNameArr = area.toArray(new String[]{});
for(int i = 0;i < areaFatherNameArr.length;i++){
String key = areaFatherNameArr[i];
String[] son = areaMap.get(key).toArray(new String[]{});
Row row = hideSheet.createRow(rowId++);
row.createCell(0).setCellValue(key);
for(int j = 0; j < son.length; j ++){
Cell cell = row.createCell(j + 1);
cell.setCellValue(son[j]);
}
// 添加名称管理器
String range = getRange(1, rowId, son.length);
Name name = book.createName();
//key不可重复
name.setNameName(key);
String formula = "area!" + range;
name.setRefersToFormula(formula);
}
XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet)sheet1);
// 省规则
DataValidationConstraint provConstraint = dvHelper.createExplicitListConstraint(provinceArr);
// 四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList provRangeAddressList = new CellRangeAddressList(1, 20000, 0, 0);
DataValidation provinceDataValidation = dvHelper.createValidation(provConstraint, provRangeAddressList);
//验证
provinceDataValidation.createErrorBox("error", "请使用下拉方式选择合适的省市区");
provinceDataValidation.setShowErrorBox(true);
provinceDataValidation.setSuppressDropDownArrow(true);
sheet1.addValidationData(provinceDataValidation);
//对前20行设置有效性
for(int i = 2;i < 20000;i++){
setDataValidation("A" , (XSSFSheet) sheet1,i,2);
setDataValidation("B" , (XSSFSheet) sheet1,i,3);
}
XSSFDataValidationHelper dvHelper1 = new XSSFDataValidationHelper((XSSFSheet)sheet1);
// 省规则
DataValidationConstraint provConstraint1 = dvHelper1.createExplicitListConstraint(provinceArr);
// 四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList provRangeAddressList1 = new CellRangeAddressList(1, 20000, 4, 4);
DataValidation provinceDataValidation1 = dvHelper1.createValidation(provConstraint1, provRangeAddressList1);
//验证
provinceDataValidation1.createErrorBox("error", "请使用下拉方式选择合适的省市区");
provinceDataValidation1.setShowErrorBox(true);
provinceDataValidation1.setSuppressDropDownArrow(true);
sheet1.addValidationData(provinceDataValidation1);
//对前20行设置有效性
for(int i = 2;i < 20000;i++){
setDataValidation("E" , (XSSFSheet) sheet1,i,6);
setDataValidation("F" , (XSSFSheet) sheet1,i,7);
}
//制作货物类型
Sheet hideSheet2 = book.createSheet("site2");
book.setSheetHidden(book.getSheetIndex(hideSheet2), true);
// 查询所有的订单类型名称
List goodsTypeList = makeGoodsType();
int rowId1 = 0;
// 设置第一行,存省的信息
Row proviRow1 = hideSheet2.createRow(rowId1++);
proviRow1.createCell(0).setCellValue("货物大类");
for(int j = 0; j < goodsTypeList.size(); j ++){
Cell proviCell = proviRow1.createCell(j + 1);
proviCell.setCellValue(goodsTypeList.get(j));
}
XSSFDataValidationHelper dvHelper2 = new XSSFDataValidationHelper((XSSFSheet)sheet1);
// 订单类型规则
DataValidationConstraint provConstraint2 = dvHelper2.createExplicitListConstraint(goodsTypeList.toArray(new String[]{}));
CellRangeAddressList provRangeAddressList2 = new CellRangeAddressList(1, 20000, 14, 14);
DataValidation provinceDataValidation2 = dvHelper2.createValidation(provConstraint2, provRangeAddressList2);
provinceDataValidation2.createErrorBox("error", "请选择正确的货物大类");
provinceDataValidation2.setShowErrorBox(true);
provinceDataValidation2.setSuppressDropDownArrow(true);
sheet1.addValidationData(provinceDataValidation2);
//制作计量单位类型
createUnitType( book, sheet1);
//货损类型
createCargoType(book, sheet1);
//车辆类型
createTruckType(book, sheet1);
//支付类型
createPaymentType(book, sheet1);
FileOutputStream os = null;
try {
os = new FileOutputStream("D:/waybill.xlsx");
book.write(os);
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(os);
}
}
private void createPaymentType(Workbook book, Sheet sheet1) {
//制作货物类型
Sheet hideSheet2 = book.createSheet("site6");
book.setSheetHidden(book.getSheetIndex(hideSheet2), true);
// 查询所有的订单类型名称
List PaymentTypeList = makePaymentType();
int rowId1 = 0;
// 设置第一行,存省的信息
Row proviRow1 = hideSheet2.createRow(rowId1++);
proviRow1.createCell(0).setCellValue("支付方式");
for(int j = 0; j < PaymentTypeList.size(); j ++){
Cell proviCell = proviRow1.createCell(j + 1);
proviCell.setCellValue(PaymentTypeList.get(j));
}
XSSFDataValidationHelper dvHelper2 = new XSSFDataValidationHelper((XSSFSheet)sheet1);
// 订单类型规则
DataValidationConstraint provConstraint2 = dvHelper2.createExplicitListConstraint(PaymentTypeList.toArray(new String[]{}));
CellRangeAddressList provRangeAddressList2 = new CellRangeAddressList(1, 20000, 34, 34);
DataValidation provinceDataValidation2 = dvHelper2.createValidation(provConstraint2, provRangeAddressList2);
provinceDataValidation2.createErrorBox("error", "请选择正确的支付方式");
provinceDataValidation2.setShowErrorBox(true);
provinceDataValidation2.setSuppressDropDownArrow(true);
sheet1.addValidationData(provinceDataValidation2);
}
private void createTruckType(Workbook book, Sheet sheet1) {
//制作货物类型
Sheet hideSheet2 = book.createSheet("site5");
book.setSheetHidden(book.getSheetIndex(hideSheet2), true);
// 查询所有的订单类型名称
List TruckTypeList = makeTruckType();
int rowId1 = 0;
// 设置第一行,存省的信息
Row proviRow1 = hideSheet2.createRow(rowId1++);
proviRow1.createCell(0).setCellValue("车辆类型");
for(int j = 0; j < TruckTypeList.size(); j ++){
Cell proviCell = proviRow1.createCell(j + 1);
proviCell.setCellValue(TruckTypeList.get(j));
}
XSSFDataValidationHelper dvHelper2 = new XSSFDataValidationHelper((XSSFSheet)sheet1);
// 订单类型规则
DataValidationConstraint provConstraint2 = dvHelper2.createExplicitListConstraint(TruckTypeList.toArray(new String[]{}));
CellRangeAddressList provRangeAddressList2 = new CellRangeAddressList(1, 20000, 23, 23);
DataValidation provinceDataValidation2 = dvHelper2.createValidation(provConstraint2, provRangeAddressList2);
provinceDataValidation2.createErrorBox("error", "请选择正确的车辆类型");
provinceDataValidation2.setShowErrorBox(true);
provinceDataValidation2.setSuppressDropDownArrow(true);
sheet1.addValidationData(provinceDataValidation2);
}
public void createUnitType(Workbook book,Sheet sheet1){
//制作货物类型
Sheet hideSheet2 = book.createSheet("site3");
book.setSheetHidden(book.getSheetIndex(hideSheet2), true);
// 查询所有的订单类型名称
List goodsTypeList = makeUnitType();
int rowId1 = 0;
// 设置第一行,存省的信息
Row proviRow1 = hideSheet2.createRow(rowId1++);
proviRow1.createCell(0).setCellValue("计量单位");
for(int j = 0; j < goodsTypeList.size(); j ++){
Cell proviCell = proviRow1.createCell(j + 1);
proviCell.setCellValue(goodsTypeList.get(j));
}
XSSFDataValidationHelper dvHelper2 = new XSSFDataValidationHelper((XSSFSheet)sheet1);
// 订单类型规则
DataValidationConstraint provConstraint2 = dvHelper2.createExplicitListConstraint(goodsTypeList.toArray(new String[]{}));
CellRangeAddressList provRangeAddressList2 = new CellRangeAddressList(1, 20000, 18, 18);
DataValidation provinceDataValidation2 = dvHelper2.createValidation(provConstraint2, provRangeAddressList2);
provinceDataValidation2.createErrorBox("error", "请选择正确的计量单位");
provinceDataValidation2.setShowErrorBox(true);
provinceDataValidation2.setSuppressDropDownArrow(true);
sheet1.addValidationData(provinceDataValidation2);
}
public void createCargoType(Workbook book,Sheet sheet1){
//制作货物类型
Sheet hideSheet2 = book.createSheet("site4");
book.setSheetHidden(book.getSheetIndex(hideSheet2), true);
// 查询所有的订单类型名称
List cargoTypeList = makeCargoType();
int rowId1 = 0;
// 设置第一行,存省的信息
Row proviRow1 = hideSheet2.createRow(rowId1++);
proviRow1.createCell(0).setCellValue("货损类型");
for(int j = 0; j < cargoTypeList.size(); j ++){
Cell proviCell = proviRow1.createCell(j + 1);
proviCell.setCellValue(cargoTypeList.get(j));
}
XSSFDataValidationHelper dvHelper2 = new XSSFDataValidationHelper((XSSFSheet)sheet1);
// 订单类型规则
DataValidationConstraint provConstraint2 = dvHelper2.createExplicitListConstraint(cargoTypeList.toArray(new String[]{}));
CellRangeAddressList provRangeAddressList2 = new CellRangeAddressList(1, 20000, 20, 20);
DataValidation provinceDataValidation2 = dvHelper2.createValidation(provConstraint2, provRangeAddressList2);
provinceDataValidation2.createErrorBox("error", "请选择正确的货损类型");
provinceDataValidation2.setShowErrorBox(true);
provinceDataValidation2.setSuppressDropDownArrow(true);
sheet1.addValidationData(provinceDataValidation2);
}
/**
* 设置有效性
* @param offset 主影响单元格所在列,即此单元格由哪个单元格影响联动
* @param sheet
* @param rowNum 行数
* @param colNum 列数
*/
public static void setDataValidation(String offset,XSSFSheet sheet, int rowNum,int colNum) {
XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet);
DataValidation data_validation_list;
data_validation_list = getDataValidationByFormula(
"INDIRECT($" + offset + (rowNum) + ")", rowNum, colNum,dvHelper);
sheet.addValidationData(data_validation_list);
}
/**
* 加载下拉列表内容
* @param formulaString
* @param naturalRowIndex
* @param naturalColumnIndex
* @param dvHelper
* @return
*/
private static DataValidation getDataValidationByFormula(
String formulaString, int naturalRowIndex, int naturalColumnIndex,XSSFDataValidationHelper dvHelper) {
// 加载下拉列表内容
// 举例:若formulaString = "INDIRECT($A$2)" 表示规则数据会从名称管理器中获取key与单元格 A2 值相同的数据,
//如果A2是江苏省,那么此处就是江苏省下的市信息。
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createFormulaListConstraint(formulaString);
// 设置数据有效性加载在哪个单元格上。
// 四个参数分别是:起始行、终止行、起始列、终止列
int firstRow = naturalRowIndex -1;
int lastRow = naturalRowIndex - 1;
int firstCol = naturalColumnIndex - 1;
int lastCol = naturalColumnIndex - 1;
CellRangeAddressList regions = new CellRangeAddressList(firstRow,
lastRow, firstCol, lastCol);
// 数据有效性对象
// 绑定
XSSFDataValidation data_validation_list = (XSSFDataValidation) dvHelper.createValidation(dvConstraint, regions);
data_validation_list.setEmptyCellAllowed(false);
if (data_validation_list instanceof XSSFDataValidation) {
data_validation_list.setSuppressDropDownArrow(true);
data_validation_list.setShowErrorBox(true);
} else {
data_validation_list.setSuppressDropDownArrow(false);
}
// 设置输入信息提示信息
// data_validation_list.createPromptBox("下拉选择提示", "请使用下拉方式选择合适的值!");
// 设置输入错误提示信息
data_validation_list.createErrorBox("error", "请使用下拉方式选择合适的省市区");
return data_validation_list;
}
/**
*
* @param offset 偏移量,如果给0,表示从A列开始,1,就是从B列
* @param rowId 第几行
* @param colCount 一共多少列
* @return 如果给入参 1,1,10. 表示从B1-K1。最终返回 $B$1:$K$1
*
* @author denggonghai 2016年8月31日 下午5:17:49
*/
public String getRange(int offset, int rowId, int colCount) {
char start = (char)('A' + offset);
if (colCount <= 25) {
char end = (char)(start + colCount - 1);
return "$" + start + "$" + rowId + ":$" + end + "$" + rowId;
} else {
char endPrefix = 'A';
char endSuffix = 'A';
if ((colCount - 25) / 26 == 0 || colCount == 51) {// 26-51之间,包括边界(仅两次字母表计算)
if ((colCount - 25) % 26 == 0) {// 边界值
endSuffix = (char)('A' + 25);
} else {
endSuffix = (char)('A' + (colCount - 25) % 26 - 1);
}
} else {// 51以上
if ((colCount - 25) % 26 == 0) {
endSuffix = (char)('A' + 25);
endPrefix = (char)(endPrefix + (colCount - 25) / 26 - 1);
} else {
endSuffix = (char)('A' + (colCount - 25) % 26 - 1);
endPrefix = (char)(endPrefix + (colCount - 25) / 26);
}
}
return "$" + start + "$" + rowId + ":$" + endPrefix + endSuffix + "$" + rowId;
}
}
/**
* 制作货物类型类型list
* @return list
*/
public List makeGoodsType(){
List list = new ArrayList();
try {
list.add("大宗货物");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
/**
* 制作计量单位list
* @return list
*/
public List makeUnitType(){
List list = new ArrayList();
try {
list.add("吨");
list.add("立方米");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
/**
* 制作车辆类型list
* @return list
*/
public List makeTruckType(){
List list = new ArrayList();
try {
list.add("仓栅式挂车");
list.add("自卸挂车");
list.add("集装箱挂车");
list.add("罐式挂车");
list.add("普通货车");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
/**
* 制作支付方式list
* @return list
*/
public List makePaymentType(){
List list = new ArrayList();
try {
list.add("现金");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
/**
* 制作货损类型list
* @return list
*/
public List makeCargoType(){
List list = new ArrayList();
try {
list.add("吨");
list.add("‰");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
private String provinceLists="[{\"id\": \"110000\",\"name\": \"北京\",\"child\": [{\t\"name\": \"北京市\",\t\"id\": \"110100\",\t\"child\": [{\"id\": \"110101\",\"child\": null,\"name\": \"东城区\"\t}, {\"child\": null,\"id\": \"110102\",\"name\": \"西城区\"\t}, {\"name\": \"崇文区\",\"id\": \"110103\",\"child\": null\t}, {\"name\": \"宣武区\",\"id\": \"110104\",\"child\": null\t}, {\"id\": \"110105\",\"name\": \"朝阳区\",\"child\": null\t}, {\"name\": \"丰台区\",\"id\": \"110106\",\"child\": null\t}, {\"name\": \"石景山区\",\"id\": \"110107\",\"child\": null\t}, {\"child\": null,\"id\": \"110108\",\"name\": \"海淀区\"\t}, {\"name\": \"门头沟区\",\"id\": \"110109\",\"child\": null\t}, {\"child\": null,\"name\": \"房山区\",\"id\": \"110111\"\t}, {\"child\": null,\"name\": \"通州区\",\"id\": \"110112\"\t}, {\"name\": \"顺义区\",\"id\": \"110113\",\"child\": null\t}, {\"id\": \"110114\",\"name\": \"昌平区\",\"child\": null\t}, {\"id\": \"110115\",\"name\": \"大兴区\",\"child\": null\t}, {\"id\": \"110116\",\"name\": \"怀柔区\",\"child\": null\t}, {\"id\": \"110117\",\"name\": \"平谷区\",\"child\": null\t}]}, {\t\"child\": [{\"id\": \"110228\",\"name\": \"密云县\",\"child\": null\t}, {\"id\": \"110229\",\"child\": null,\"name\": \"延庆县\"\t}],\t\"name\": \"北京市县\",\t\"id\": \"110200\"}] }, {\"id\": \"120000\",\"child\": [{\t\"name\": \"天津市\",\t\"child\": [{\"name\": \"和平区\",\"child\": null,\"id\": \"120101\"\t}, {\"name\": \"河东区\",\"id\": \"120102\",\"child\": null\t}, {\"name\": \"河西区\",\"id\": \"120103\",\"child\": null\t}, {\"id\": \"120104\",\"name\": \"南开区\",\"child\": null\t}, {\"id\": \"120105\",\"name\": \"河北区\",\"child\": null\t}, {\"id\": \"120106\",\"name\": \"红桥区\",\"child\": null\t}, {\"name\": \"塘沽区\",\"child\": null,\"id\": \"120107\"\t}, {\"child\": null,\"id\": \"120108\",\"name\": \"汉沽区\"\t}, {\"name\": \"大港区\",\"child\": null,\"id\": \"120109\"\t}, {\"child\": null,\"name\": \"东丽区\",\"id\": \"120110\"\t}, {\"child\": null,\"name\": \"西青区\",\"id\": \"120111\"\t}, {\"child\": null,\"id\": \"120112\",\"name\": \"津南区\"\t}, {\"child\": null,\"name\": \"北辰区\",\"id\": \"120113\"\t}, {\"child\": null,\"name\": \"武清区\",\"id\": \"120114\"\t}, {\"id\": \"120115\",\"name\": \"宝坻区\",\"child\": null\t}],\t\"id\": \"120100\"}, {\t\"id\": \"120200\",\t\"name\": \"天津市县\",\t\"child\": [{\"child\": null,\"name\": \"宁河县\",\"id\": \"120221\"\t}, {\"id\": \"120223\",\"name\": \"静海县\",\"child\": null\t}, {\"name\": \"蓟县\",\"id\": \"120225\",\"child\": null\t}]}],\"name\": \"天津\" }]";
/**
* 制作所有的省的list
*/
public static List makeProvNameList (){
List provNameList = new ArrayList();
try {
JSONArray jsonArray = new JSONArray().parseArray(provinceLists);
for(int i = 0;i getAreaFatherNameArr (){
List areaFatherNameArr = new ArrayList();
try {
JSONArray jsonArray = new JSONArray().parseArray(provinceLists);
for(int i = 0;i> makeSiteMap(){
Map> siteMap = new HashMap>();
try {
JSONArray jsonArray = new JSONArray().parseArray(provinceLists);
for(int i = 0;i list = new ArrayList();
for(int j = 0;j liste = new ArrayList();
for(int k = 0;k