「java表单合并」Java合并两个单链表
今天给各位分享java表单合并的知识,其中也会对Java合并两个单链表进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
java tablemodel怎么样实现表格合并
Jtable没有提供现成的合并单元格的方法,但是使用其所提供的方法仍然能做到这一点,只是复杂了一些。为了合并单元格,我们可以使用Jtable的三个方法:getCellRect(),columnAtPoint(),and rowAtPoint()。第一个方法返回一个单元格的边界(Rectangle类),第二、三个方法分别返回屏幕指定位置的列和行。
然后根据你是需要合并行还是合并列,分别处理。如果是合并行的话,那么列的信息就不用变了,我们只需要处理getCellRect和rowAtPoint()。 如果是合并列的话,我们那个row的信息就不变了,只需要处理column和getCellRect的信息就好了。下面是一个合并列的例子:
public Rectangle getCellRect(int row, int column, boolean includeSpacing){
// 该方法是Jtable构建时所必须的
if (map==null) return super.getCellRect(row,column, includeSpacing);
// 指定单元格的可视单元格列值
int sk=map.visibleCell(row,column);
Rectangle r1=super.getCellRect(row,sk,includeSpacing);
// 如果指定单元格列宽不为1,累计出跨列单元格的宽度
if (map.span(row,sk)!=1)
for (int i=1; imap.span(row,sk); i++){
r1.width+=getColumnModel().getColumn(sk+i).getWidth();
}
return r1;
}
public int columnAtPoint(Point p) {
int x=super.columnAtPoint(p);
// 当指定位置不在Table内时,返回-1
if (x0) return x;
int y=super.rowAtPoint(p);
//获取指定位置可视单元格的列值
return map.visibleCell(y,x);
}
java如何如何实现两张excel表的合并?
你这个是将第二excel的数据追加到第一个excel里吧。
1、你在构建第一个excel的时候,把第二excel数据读出来与源数据同时写入。
2、你可以将两个excel的数据都读出来 放到对象列表中。再将list里的对象写到excel中。
java poi合并单元表格(求帮助啊)
/**
*
* @param context
* @param dictionary
* @param rows 数据行
* @param fileName 文件名
* @param fields 列名
* @param fieldsName 字段名
*/
private void outExcelFile(HttpContext context,
IContextDictionary dictionary, DataRowCollections rows,
String fileName, ListString fields, ListString fieldsName) {
int cellSize = fields.size();
if(cellSize == 0){
LogManager.debug("没有指定列头信息,无法导出Excel文件!");
return;
}
//============创建样式 start
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
//列头字体样式
HSSFFont headerFont = workbook.createFont();
headerFont.setFontName("宋体");
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//列头样式
HSSFCellStyle headerStyle = workbook.createCellStyle();
headerStyle.setFont(headerFont);
headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
headerStyle.setLocked(true);
headerStyle.setWrapText(true);
//标题样式
HSSFFont titleFont = workbook.createFont();
titleFont.setFontName("宋体");
titleFont.setFontHeightInPoints((short) 15);
titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle titleStyle = workbook.createCellStyle();
titleStyle.setFont(titleFont);
titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
titleStyle.setLocked(true);
titleStyle.setWrapText(true);
//普通单元格字体样式
HSSFFont cellFont = workbook.createFont();
cellFont.setFontName("宋体");
cellFont.setFontHeightInPoints((short)12);
//普通单元格样式
HSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFont(cellFont);
cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);// 左右居中
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
cellStyle.setLocked(true);
cellStyle.setWrapText(true);
//============创建样式 end
//设置序号列、列宽和标题行 start
HSSFRow titleRow = sheet.createRow(0);
titleRow.setHeightInPoints(50);
HSSFCell titleCell = titleRow.createCell(0);
titleCell.setCellValue(new HSSFRichTextString(fileName));
titleCell.setCellStyle(titleStyle);
//sheet.addMergedRegion(new Region(0,(short)0,0,(short)cellSize));//合并单元格--方法过时
//CellRangeAddress 起始行 结束行 起始列 结束列
sheet.addMergedRegion(new CellRangeAddress(0,0,(short)0,(short)cellSize));//合并单元格
//显示总的数据个数 start
HSSFRow countRow = sheet.createRow(1);
countRow.setHeightInPoints(40);
HSSFCell countCell = countRow.createCell(0);
countCell.setCellValue(new HSSFRichTextString("共计专项检查("+rows.size()+")项"));
countCell.setCellStyle(headerStyle);
sheet.addMergedRegion(new CellRangeAddress(1,1,(short)0,(short)cellSize));//合并单元格
//显示总的数据个数 end
HSSFRow headerRow = sheet.createRow(2);
headerRow.setHeightInPoints(35);
HSSFCell headerCell = null;
//序号
int startIndex = 0 ;
headerCell = headerRow.createCell(0);
sheet.setColumnWidth(0, 2000);
headerCell.setCellValue(new HSSFRichTextString("序号"));
headerCell.setCellStyle(headerStyle);
startIndex ++ ;
//列头
for(int i = 0; i cellSize; i ++){
sheet.setColumnWidth(startIndex + i, 7000);
headerCell = headerRow.createCell(startIndex + i);
headerCell.setCellValue(new HSSFRichTextString(fields.get(i)));
headerCell.setCellStyle(headerStyle);
}
//设置序号列、列宽和标题行 end
//文件正文 start
int rowNum = 1;
int rowIndex = 0;
HSSFRow row = null;
ListInteger[] cellRangeLst = new ArrayListInteger[](0);
Integer [] arr = null;
int l = 0;
String orgName = "";
for(int j = 2; jrows.size()+2; j++){//循环行
DataRow dataRow = rows.get(rowIndex); //对应数据库字段
HSSFCell cell = null;
row = sheet.createRow(j + 1);
row.setHeightInPoints(55);
//序号
cell = row.createCell(0);
cell.setCellValue(rowNum++);
cell.setCellStyle(cellStyle);
if(StringHelper.isNullOrEmpty(orgName)){
arr = new Integer[2];
arr[0] = j + 1;
l =j + 1;
orgName = dataRow.getString("ORGNAME");
}else{
if(!orgName.equals(dataRow.getString("ORGNAME"))){
arr[1] = j;
cellRangeLst.add(arr);
sheet.addMergedRegion(new CellRangeAddress(l,j,1,1));
arr = new Integer[2];
l = j+1;
orgName = dataRow.getString("ORGNAME");
}
if(rowIndex == rows.size() - 1){
arr[1] = j+1;
cellRangeLst.add(arr);
sheet.addMergedRegion(new CellRangeAddress(l,j+1,1,1));
}
}
for(int k = 0; k cellSize; k++){
cell = row.createCell(k + startIndex);
String column = fieldsName.get(k); //对应数据库字段
String value = "";
if("APSJ".equals(column)){
value = getAPSJValue(dataRow.getString(column));
}else{
value = dataRow.getString(column);
}
cell.setCellValue(new HSSFRichTextString(value));
cell.setCellStyle(cellStyle);
}
rowIndex ++;
}
//文件正文 end
//for(Integer[] te : cellRangeLst){
// sheet.addMergedRegion(new CellRangeAddress(te[0],te[1],1,1));//合并处室单元格
//}
//下载
HttpServletResponse response = context.getResponse();
response.setContentType("application/x-download;charset=UTF-8");
String title = "export";
try {
title = java.net.URLEncoder.encode(fileName, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
response.addHeader("Content-Disposition", "attachment;filename=" + title + ".xls");
try {
OutputStream out = response.getOutputStream();
workbook.write(out);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//参考一下吧
java表单合并的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于Java合并两个单链表、java表单合并的信息别忘了在本站进行查找喔。
发布于:2022-12-01,除非注明,否则均为
原创文章,转载请注明出处。