java 导入EXCEL表格 单元格合并的情况怎么处理,数据放在哪里?

 我来答
马珊笛704
2013-12-19 · TA获得超过481个赞
知道小有建树答主
回答量:634
采纳率:100%
帮助的人:267万
展开全部
//下面一段代码是来上传文件的 fie是你倒入的文件
InputStream is = new FileInputStream(file); String root = ServletActionContext.getServletContext().getRealPath("WEB-INF/files/"); File newFile = new File(root+"/verify"); //判断文件夹是否存在 if(!newFile.exists()){ newFile.mkdir(); } File destFile = new File(newFile+"/"+this.getFileFileName()); try{ FileOutputStream os = new FileOutputStream(destFile); byte[] buffer = new byte[1024]; int length=0; while((length = is.read(buffer)) > 0 ){ os.write(buffer,0,length); } is.close(); os.close(); }catch(Exception e){ e.printStackTrace(); }
文件可以存放在临时文件里面,然后,创建完临时文件后,进行check ,然后插入数据库,上面的是一小段代码,由于保密,就不给你全部发了。
HSSFRow row = sheet.createRow(0); //产生第一个单元格 HSSFCell cell = row.createCell(0); //合并单元格 //第一行 sheet.addMergedRegion(new CellRangeAddress(0,0,0,15)); //第二行 sheet.addMergedRegion(new CellRangeAddress(1,1,0,1)); sheet.addMergedRegion(new CellRangeAddress(1,1,2,9)); sheet.addMergedRegion(new CellRangeAddress(1,1,10,11)); sheet.addMergedRegion(new CellRangeAddress(1,1,12,15)); //第三行 sheet.addMergedRegion(new CellRangeAddress(2,2,0,15)); //第四行 sheet.addMergedRegion(new CellRangeAddress(3,3,0,1)); sheet.addMergedRegion(new CellRangeAddress(3,3,2,9)); sheet.addMergedRegion(new CellRangeAddress(3,3,10,11)); sheet.addMergedRegion(new CellRangeAddress(3,3,12,15)); //第五行 sheet.addMergedRegion(new CellRangeAddress(4,4,0,1)); sheet.addMergedRegion(new CellRangeAddress(4,4,2,5)); sheet.addMergedRegion(new CellRangeAddress(4,4,6,7)); sheet.addMergedRegion(new CellRangeAddress(4,4,8,9)); sheet.addMergedRegion(new CellRangeAddress(4,4,10,11)); sheet.addMergedRegion(new CellRangeAddress(4,4,12,14)); sheet.addMergedRegion(new CellRangeAddress(4,4,15,15)); //第六行 sheet.addMergedRegion(new CellRangeAddress(5,5,0,1)); sheet.addMergedRegion(new CellRangeAddress(5,5,2,5)); sheet.addMergedRegion(new CellRangeAddress(5,5,6,7)); sheet.addMergedRegion(new CellRangeAddress(5,5,8,9)); sheet.addMergedRegion(new CellRangeAddress(5,5,10,11)); sheet.addMergedRegion(new CellRangeAddress(5,5,12,14)); sheet.addMergedRegion(new CellRangeAddress(5,5,15,15)); //第七行 sheet.addMergedRegion(new CellRangeAddress(6,7,0,0)); sheet.addMergedRegion(new CellRangeAddress(6,7,1,1)); sheet.addMergedRegion(new CellRangeAddress(6,7,2,2)); sheet.addMergedRegion(new CellRangeAddress(6,7,3,3)); sheet.addMergedRegion(new CellRangeAddress(6,7,4,4)); sheet.addMergedRegion(new CellRangeAddress(6,7,5,5)); sheet.addMergedRegion(new CellRangeAddress(6,7,6,6)); sheet.addMergedRegion(new CellRangeAddress(6,7,7,7)); sheet.addMergedRegion(new CellRangeAddress(6,7,8,8)); sheet.addMergedRegion(new CellRangeAddress(6,7,9,9)); sheet.addMergedRegion(new CellRangeAddress(6,7,10,10)); sheet.addMergedRegion(new CellRangeAddress(6,6,11,12)); sheet.addMergedRegion(new CellRangeAddress(7,7,11,11)); sheet.addMergedRegion(new CellRangeAddress(7,7,12,12)); sheet.addMergedRegion(new CellRangeAddress(6,7,13,13)); sheet.addMergedRegion(new CellRangeAddress(6,7,14,14)); sheet.addMergedRegion(new CellRangeAddress(6,7,15,15)); //标题 //字符类型 cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue("业主注册"); //第二行 row = sheet.createRow(1); cell = row.createCell(0); cell.setCellValue("项目名称"); cell = row.createCell(2); cell.setCellValue(expupList.get(0).get("ENGINEERING_PROJECT_NAME").toString()); cell = row.createCell(10); cell.setCellValue("列支范围"); cell = row.createCell(12); cell.setCellValue(expupList.get(0).get("SERVICING_CONFINE").toString()); //第三行 row = sheet.createRow(2); cell = row.createCell(0); cell.setCellValue("施工内容"); cell = row.createCell(2); cell.setCellValue("施工内容值"); //第四行 row = sheet.createRow(3); cell = row.createCell(0); cell.setCellValue("施工单位"); cell = row.createCell(2); cell.setCellValue(expupList.get(0).get("CONSTRUCTION_ORG_NAME").toString()); cell = row.createCell(10); cell.setCellValue("工程验收方式"); cell = row.createCell(12); cell.setCellValue("工程验收方式值"); //第五行 row = sheet.createRow(4); cell = row.createCell(0); cell.setCellValue("预算金额"); cell = row.createCell(2); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(expupList.get(0).get("SERVICING_APPLICATION_MONEY").toString()); cell = row.createCell(6); cell.setCellValue("涉及建筑面积(㎡)"); cell = row.createCell(8); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(expupList.get(0).get("SERVICING_CONSTRUCTION_AREA").toString()); cell = row.createCell(10); cell.setCellValue("施工期间"); cell = row.createCell(12); cell.setCellValue("施工期间值"); //第六行 row = sheet.createRow(5); cell = row.createCell(0); cell.setCellValue("分摊金额"); cell = row.createCell(2); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(expupList.get(0).get("SERVICING_APPLICATION_MONEY").toString()); cell = row.createCell(6); cell.setCellValue("涉及户数(户)"); cell = row.createCell(8); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(expupList.get(0).get("SERVICING_OWNERS_NUMBER").toString()); cell = row.createCell(10); cell.setCellValue("现场鉴证人员"); cell = row.createCell(12); cell.setCellValue("现场鉴证人员值"); //第7行 row = sheet.createRow(6); cell = row.createCell(0); cell.setCellValue("序号"); cell = row.createCell(1); cell.setCellValue("业主姓名"); cell = row.createCell(2); cell.setCellValue("幢"); cell = row.createCell(3); cell.setCellValue("单元"); cell = row.createCell(4); cell.setCellValue("楼层"); cell = row.createCell(5); cell.setCellValue("户号"); cell = row.createCell(6); cell.setCellValue("有无电梯"); cell = row.createCell(7); cell.setCellValue("建筑面积"); cell = row.createCell(8); cell.setCellValue("缴存金额"); cell = row.createCell(9); cell.setCellValue("分摊比例"); cell = row.createCell(10); cell.setCellValue("分摊金额"); cell = row.createCell(11); cell.setCellValue("是否同意使用维修基金"); cell = row.createCell(13); cell.setCellValue("业主签字"); cell = row.createCell(14); cell.setCellValue("联系电话"); cell = row.createCell(15); cell.setCellValue("备注"); row = sheet.createRow(7); cell = row.createCell(11); cell.setCellValue("同意"); cell = row.createCell(12); cell.setCellValue("不同意");
合并单元格
追问
也就说,我需要自己判断单元格是不是合并了,而且需要在程序里把合并的单元格表示出来,然后填入数据,再存入数据库是吧?
追答
我们是这么做的啊,一般的项目导入的格式必须是一定的。暂时死我还没有发现更强大 的框架
埃及来的法老
2013-12-19 · 超过26用户采纳过TA的回答
知道答主
回答量:82
采纳率:0%
帮助的人:71.1万
展开全部
HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(1);
HSSFRow rowm = sheet.getRow(83);//取第84行,读出C84备注,合并单元数据,再写入备注
rowm.setHeight((short)1000);
//合并单元数据
sheet.addMergedRegion(new Region((short)83 , (short) 2, (short)83, (short)16));
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式