「java合并表头」java合并单元格后如何设置边框

博主:adminadmin 2023-03-21 17:03:08 459

本篇文章给大家谈谈java合并表头,以及java合并单元格后如何设置边框对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

急急急!!java导出一个固定格式的excel里面有合并行和并列,并且有附表,小弟是新手,求demo

可以合并的哦。你这个表格比较复杂,做起来不是一下就弄完的啊,就提供一个思路吧。如下:

(这个需要apache 的 poi hssf jar包,先下下来)

实例代码如下哦:

HSSFWorkbook wb = new HSSFWorkbook();//创建excel文件

HSSFSheet sheet = wb.createSheet(“sheetName”) ;//创建sheet

sheet.addMergedRegion(new CellRangeAddress(4, 5, 0, 0));//合并单元格

不明白的再@我哦。

java如何如何实现两张excel表的合并?

你这个是将第二excel的数据追加到第一个excel里吧。

1、你在构建第一个excel的时候,把第二excel数据读出来与源数据同时写入。

2、你可以将两个excel的数据都读出来 放到对象列表中。再将list里的对象写到excel中。

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 word 导出怎么合并表头 Word poi

给你个例子

iText-2.1.5.jar、iTextAsian.jar、iText-rtf-2.1.4.jar

public String CreateWord() {

try {

Document document = new Document(PageSize.A4);

RtfWriter2.getInstance(document, new FileOutputStream("c:\\"));

document.open();

for (int i = 0; i datalist.size(); i++) {

Lawmanager lawmanager = (Lawmanager) datalist.get(i);

Paragraph title = new Paragraph("行 政 执 法 人 员 登 记 表");

title.setAlignment(Element.ALIGN_CENTER);

title.setFont(new RtfFont("仿 宋__GB2312", 18, Font.BOLD, Color.BLACK));

document.add(title);

Table table = new Table(7);

table.setWidth(100);

table.setBorderWidth(1);

table.setBorderColor(Color.BLACK);

table.setPadding(0);

table.setSpacing(0);

table.setAlignment("CENTER");

table.setWidths(new float[]{16.0f,16.0f,15.0f,15.0f,16.0f,22.0f,0.0f});

table.setAutoFillEmptyCells(true);

RtfFont font = new RtfFont("仿 宋__GB2312", 12, Font.COURIER, Color.BLACK);

Cell cell = new Cell(new Phrase("姓 名", font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

table.addCell(cell);

cell = new Cell(new Phrase(lawmanager.getLawname(), font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

cell.setColspan(2);

table.addCell(cell);

cell = new Cell(new Phrase("性 别", font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

table.addCell(cell);

cell = new Cell(new Phrase(lawmanager.getLawsex(), font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

table.addCell(cell);

try {

Image lawPic = Image.getInstance(publicTools.getPath() + "/" + lawmanager.getLawpic());

lawPic.scaleAbsolute(105, 135);

cell = new Cell(lawPic);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

cell.setRowspan(4);

table.addCell(cell);

} catch (IOException e) {

publicTools.OutputLog(e.toString(), "ERROR", 0);

Image lawPic = Image.getInstance(publicTools.getPath("upfile/pic") + "pic.jpg");

lawPic.scaleAbsolute(105, 135);

cell = new Cell(lawPic);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

cell.setRowspan(4);

table.addCell(cell);

}

cell = new Cell("\n\n");

cell.setBorderColor(new Color(255, 255, 255));

cell.setBackgroundColor(new Color(255, 255, 255));

table.addCell(cell);

cell = new Cell(new Phrase("出生年月日", font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

table.addCell(cell);

cell = new Cell(new Phrase(lawmanager.getLawbirthdate(), font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

cell.setColspan(2);

table.addCell(cell);

cell = new Cell(new Phrase("民 族", font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

table.addCell(cell);

cell = new Cell(new Phrase(lawmanager.getVolkdictionaryname(), font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

table.addCell(cell);

cell = new Cell("\n\n");

cell.setBorderColor(new Color(255, 255, 255));

cell.setBackgroundColor(new Color(255, 255, 255));

table.addCell(cell);

cell = new Cell(new Phrase("工作单位", font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

table.addCell(cell);

cell = new Cell(new Phrase(" " + lawmanager.getDeptname(), font));

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

cell.setColspan(4);

table.addCell(cell);

cell = new Cell("\n\n");

cell.setBorderColor(new Color(255, 255, 255));

cell.setBackgroundColor(new Color(255, 255, 255));

table.addCell(cell);

cell = new Cell(new Phrase("职 务", font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

table.addCell(cell);

cell = new Cell(new Phrase(lawmanager.getPostdictionaryname(), font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

table.addCell(cell);

cell = new Cell(new Phrase("参加工作时间", font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

table.addCell(cell);

cell = new Cell(new Phrase(lawmanager.getLawworkdate(), font));

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

cell.setColspan(2);

table.addCell(cell);

cell = new Cell("\n\n");

cell.setBorderColor(new Color(255, 255, 255));

cell.setBackgroundColor(new Color(255, 255, 255));

table.addCell(cell);

document.add(table);

Phrase phrase = new Phrase("\n注:如未取得行政执法证件、行政执法资格的,在表中“行政执法证件编号”、“行政执法资格编号”栏中显示“0”。", new RtfFont("黑 体", 10, Font.TIMES_ROMAN, Color.red));

document.add(phrase);

if(i datalist.size() - 1){

document.newPage();

}

}

document.close();

publicTools.insertLog("5", "下载Word文件", userSession);

} catch (FileNotFoundException e) {

publicTools.OutputLog(e.toString(), "ERROR", 0);

e.printStackTrace();

} catch (DocumentException e) {

publicTools.OutputLog(e.toString(), "ERROR", 0);

e.printStackTrace();

} catch (MalformedURLException e) {

publicTools.OutputLog(e.toString(), "ERROR", 0);

e.printStackTrace();

} catch (IOException e) {

publicTools.OutputLog(e.toString(), "ERROR", 0);

e.printStackTrace();

}

return "upfile/download/" + fileName;

}

关于java合并表头和java合并单元格后如何设置边框的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。