html表格边框为void,将表格边框设置为THICK(Setting Table borders to THICK)

将表格边框设置为THICK(Setting Table borders to THICK)

我想创建一个厚边框的表格。 我一直在寻找一段时间,但似乎THICK风格不起作用。 如果我选择其他样式,例如DOUBLE,那么很好,但例如,如果我选择THIN_THICK_SMALL_GAP,它会创建两条细线。 我使用的代码是:

CTTblPr tblpro = table.getCTTbl().getTblPr();

CTTblBorders borders = tblpro.addNewTblBorders();

borders.addNewBottom().setVal(STBorder.THICK);

borders.addNewLeft().setVal(STBorder.THICK);

borders.addNewRight().setVal(STBorder.THICK);

borders.addNewTop().setVal(STBorder.THICK);

borders.addNewInsideH().setVal(STBorder.THICK);

borders.addNewInsideV().setVal(STBorder.THICK);

另一方面,如果我使用:

table.setInsideHBorder(XWPFTable.XWPFBorderType.THICK, 4, 0, "000000");

table.setInsideVBorder(XWPFTable.XWPFBorderType.THICK, 4, 0, "000000");

然后它可以工作,但我错过了表格的外边框。

任何人都可以帮助我吗? 谢谢!

I would like to create a table with thick borders. I've been searching for a while but it seems that the style THICK does not work. If I select other styles such as DOUBLE it's fine but for instance, if I select THIN_THICK_SMALL_GAP it creates two thin lines. The code I'm using is:

CTTblPr tblpro = table.getCTTbl().getTblPr();

CTTblBorders borders = tblpro.addNewTblBorders();

borders.addNewBottom().setVal(STBorder.THICK);

borders.addNewLeft().setVal(STBorder.THICK);

borders.addNewRight().setVal(STBorder.THICK);

borders.addNewTop().setVal(STBorder.THICK);

borders.addNewInsideH().setVal(STBorder.THICK);

borders.addNewInsideV().setVal(STBorder.THICK);

On the other hand, if I use:

table.setInsideHBorder(XWPFTable.XWPFBorderType.THICK, 4, 0, "000000");

table.setInsideVBorder(XWPFTable.XWPFBorderType.THICK, 4, 0, "000000");

Then it works, but I'm missing the outer border of the table.

Can anyone help me with this please? Thank you!

原文:https://stackoverflow.com/questions/50465457

更新时间:2020-01-10 16:26

最满意答案

不清楚为什么XWPFTable没有这个,但是如果我们看一下XWPFTable.java setInsideHBorder是如何工作的,那么我们可以实现这个相对容易。

提示: Word本身从不使用边框类型STBorder.THICK 。 相反,它使用STBorder.SINGLE因为厚度由大小决定。 这意味着没有大小的边框类型STBorder.THICK也不可见。 和大小为24 * 1 / STBorder.THICK = STBorder.SINGLE不会比STBorder.SINGLE厚STBorder.SINGLE具有相同的大小。

例:

import java.io.FileOutputStream;

import org.apache.poi.xwpf.usermodel.*;

import org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;

import java.util.EnumMap;

import java.math.BigInteger;

public class CreateWordTableBorders {

private static EnumMap xwpfBorderTypeMap;

static {

// populate enum map

xwpfBorderTypeMap = new EnumMap(XWPFBorderType.class);

xwpfBorderTypeMap.put(XWPFBorderType.NIL, STBorder.Enum.forInt(STBorder.INT_NIL));

xwpfBorderTypeMap.put(XWPFBorderType.NONE, STBorder.Enum.forInt(STBorder.INT_NONE));

xwpfBorderTypeMap.put(XWPFBorderType.SINGLE, STBorder.Enum.forInt(STBorder.INT_SINGLE));

xwpfBorderTypeMap.put(XWPFBorderType.THICK, STBorder.Enum.forInt(STBorder.INT_THICK));

xwpfBorderTypeMap.put(XWPFBorderType.DOUBLE, STBorder.Enum.forInt(STBorder.INT_DOUBLE));

xwpfBorderTypeMap.put(XWPFBorderType.DOTTED, STBorder.Enum.forInt(STBorder.INT_DOTTED));

xwpfBorderTypeMap.put(XWPFBorderType.DASHED, STBorder.Enum.forInt(STBorder.INT_DASHED));

xwpfBorderTypeMap.put(XWPFBorderType.DOT_DASH, STBorder.Enum.forInt(STBorder.INT_DOT_DASH));

}

private enum BorderPosition {

TOP, BOTTOM, LEFT, RIGHT

}

private static void setTableBorder(BorderPosition position, XWPFTable table, XWPFBorderType type,

int size, int space, String rgbColor) {

CTTblPr tblPr = (table.getCTTbl().getTblPr() != null) ? table.getCTTbl().getTblPr() : table.getCTTbl().addNewTblPr();

CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();

CTBorder b = null;

switch (position) {

case TOP:

b = ctb.isSetTop() ? ctb.getTop() : ctb.addNewTop();

break;

case BOTTOM:

b = ctb.isSetBottom() ? ctb.getBottom() : ctb.addNewBottom();

break;

case LEFT:

b = ctb.isSetLeft() ? ctb.getLeft() : ctb.addNewLeft();

break;

case RIGHT:

b = ctb.isSetRight() ? ctb.getRight() : ctb.addNewRight();

break;

}

b.setVal(xwpfBorderTypeMap.get(type));

b.setSz(BigInteger.valueOf(size));

b.setSpace(BigInteger.valueOf(space));

b.setColor(rgbColor);

}

public static void main(String[] args) throws Exception {

XWPFDocument document = new XWPFDocument();

XWPFParagraph paragraph = document.createParagraph();

XWPFTable table = document.createTable(3, 3);

//create CTTblGrid for this table with widths of the 3 columns.

//necessary for Libreoffice/Openoffice to accept the column widths.

//values are in unit twentieths of a point (1/1440 of an inch)

//first column = 1 inches width

table.getCTTbl().addNewTblGrid().addNewGridCol().setW(BigInteger.valueOf(1*1440));

//other columns (2 in this case) also each 1 inches width

for (int col = 1 ; col < 3; col++) {

table.getCTTbl().getTblGrid().addNewGridCol().setW(BigInteger.valueOf(1*1440));

}

for (int col = 0; col < 3; col++) {

table.getRow(0).getCell(col).setText("Column " + (col+1));

}

setTableBorder(BorderPosition.TOP, table, XWPFBorderType.SINGLE, 24/*unit 1/8 pt*/, 0, "0000FF");

setTableBorder(BorderPosition.BOTTOM, table, XWPFBorderType.SINGLE, 24/*unit 1/8 pt*/, 0, "0000FF");

setTableBorder(BorderPosition.LEFT, table, XWPFBorderType.SINGLE, 24/*unit 1/8 pt*/, 0, "0000FF");

setTableBorder(BorderPosition.RIGHT, table, XWPFBorderType.SINGLE, 24/*unit 1/8 pt*/, 0, "0000FF");

table.setInsideHBorder(XWPFTable.XWPFBorderType.DASHED, 8/*unit 1/8 pt*/, 0, "000000");

table.setInsideVBorder(XWPFTable.XWPFBorderType.DASHED, 8/*unit 1/8 pt*/, 0, "000000");

paragraph = document.createParagraph();

document.write(new FileOutputStream("CreateWordTableBorders.docx"));

document.close();

}

}

Not clear why XWPFTable does not have this already but if we look at XWPFTable.java how the setInsideHBorder works, then we can implementing this relatively easy.

Hint : Word itself never uses border type STBorder.THICK. Instead it uses STBorder.SINGLE because the thickness is determined by the size. That means that border type STBorder.THICK without size is also not visible. And STBorder.THICK with size 24 * 1/8 pt = 3 pt is not thicker than STBorder.SINGLE with the same size.

Example:

import java.io.FileOutputStream;

import org.apache.poi.xwpf.usermodel.*;

import org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;

import java.util.EnumMap;

import java.math.BigInteger;

public class CreateWordTableBorders {

private static EnumMap xwpfBorderTypeMap;

static {

// populate enum map

xwpfBorderTypeMap = new EnumMap(XWPFBorderType.class);

xwpfBorderTypeMap.put(XWPFBorderType.NIL, STBorder.Enum.forInt(STBorder.INT_NIL));

xwpfBorderTypeMap.put(XWPFBorderType.NONE, STBorder.Enum.forInt(STBorder.INT_NONE));

xwpfBorderTypeMap.put(XWPFBorderType.SINGLE, STBorder.Enum.forInt(STBorder.INT_SINGLE));

xwpfBorderTypeMap.put(XWPFBorderType.THICK, STBorder.Enum.forInt(STBorder.INT_THICK));

xwpfBorderTypeMap.put(XWPFBorderType.DOUBLE, STBorder.Enum.forInt(STBorder.INT_DOUBLE));

xwpfBorderTypeMap.put(XWPFBorderType.DOTTED, STBorder.Enum.forInt(STBorder.INT_DOTTED));

xwpfBorderTypeMap.put(XWPFBorderType.DASHED, STBorder.Enum.forInt(STBorder.INT_DASHED));

xwpfBorderTypeMap.put(XWPFBorderType.DOT_DASH, STBorder.Enum.forInt(STBorder.INT_DOT_DASH));

}

private enum BorderPosition {

TOP, BOTTOM, LEFT, RIGHT

}

private static void setTableBorder(BorderPosition position, XWPFTable table, XWPFBorderType type,

int size, int space, String rgbColor) {

CTTblPr tblPr = (table.getCTTbl().getTblPr() != null) ? table.getCTTbl().getTblPr() : table.getCTTbl().addNewTblPr();

CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();

CTBorder b = null;

switch (position) {

case TOP:

b = ctb.isSetTop() ? ctb.getTop() : ctb.addNewTop();

break;

case BOTTOM:

b = ctb.isSetBottom() ? ctb.getBottom() : ctb.addNewBottom();

break;

case LEFT:

b = ctb.isSetLeft() ? ctb.getLeft() : ctb.addNewLeft();

break;

case RIGHT:

b = ctb.isSetRight() ? ctb.getRight() : ctb.addNewRight();

break;

}

b.setVal(xwpfBorderTypeMap.get(type));

b.setSz(BigInteger.valueOf(size));

b.setSpace(BigInteger.valueOf(space));

b.setColor(rgbColor);

}

public static void main(String[] args) throws Exception {

XWPFDocument document = new XWPFDocument();

XWPFParagraph paragraph = document.createParagraph();

XWPFTable table = document.createTable(3, 3);

//create CTTblGrid for this table with widths of the 3 columns.

//necessary for Libreoffice/Openoffice to accept the column widths.

//values are in unit twentieths of a point (1/1440 of an inch)

//first column = 1 inches width

table.getCTTbl().addNewTblGrid().addNewGridCol().setW(BigInteger.valueOf(1*1440));

//other columns (2 in this case) also each 1 inches width

for (int col = 1 ; col < 3; col++) {

table.getCTTbl().getTblGrid().addNewGridCol().setW(BigInteger.valueOf(1*1440));

}

for (int col = 0; col < 3; col++) {

table.getRow(0).getCell(col).setText("Column " + (col+1));

}

setTableBorder(BorderPosition.TOP, table, XWPFBorderType.SINGLE, 24/*unit 1/8 pt*/, 0, "0000FF");

setTableBorder(BorderPosition.BOTTOM, table, XWPFBorderType.SINGLE, 24/*unit 1/8 pt*/, 0, "0000FF");

setTableBorder(BorderPosition.LEFT, table, XWPFBorderType.SINGLE, 24/*unit 1/8 pt*/, 0, "0000FF");

setTableBorder(BorderPosition.RIGHT, table, XWPFBorderType.SINGLE, 24/*unit 1/8 pt*/, 0, "0000FF");

table.setInsideHBorder(XWPFTable.XWPFBorderType.DASHED, 8/*unit 1/8 pt*/, 0, "000000");

table.setInsideVBorder(XWPFTable.XWPFBorderType.DASHED, 8/*unit 1/8 pt*/, 0, "000000");

paragraph = document.createParagraph();

document.write(new FileOutputStream("CreateWordTableBorders.docx"));

document.close();

}

}

相关问答

快速而肮脏的方式将以下行添加到弹出式面板定义中: style: '-webkit-border-radius: 0; border-radius: 0;'

如果你想要更干净的东西 - 使用SachinG方法 - 创建你自己的CSS类,将它添加到每个面板,但关键的CSS差异仍然是border-radius 。 The quick and dirty way add the following line into your popup panel definition: style: '-webki

...

如果要在图像中创建类似双线的内容,可以在文本周围创建一个额外的容器:

Text

然后你可以设置这样的样式: .outer {

border-bottom: 1px solid #000;

padding-bottom: 2px;

}

.inner {

border-bottom: 4px solid #000;

}

If you want to creat

...

这是一种hacky方式,您可以修复一个干净的矩形顶部边框: HTML

CSS #test_div:before {

position:absolute;

width:100%;

padding:1px;

top:0;

content: '';

left:-1px;

background:#000;

height:1px; }

#test_div {

bord

...

通过将BorderStyle属性设置为None来隐藏边框。 请注意,您可能还需要在相邻的单元格上更改此设置,以便它们没有边框属性设置,以便沿边缘放置边框。 You hide borders by setting the BorderStyle property to None. Note that you may also need to change this on the cells that are adjacent so that they don't have a border prop

...

style.css CSS规则正在制作边框 th,td {

border: 1px solid;

padding: 8px;

}

This CSS rule in your style.css is making the border th,td {

border: 1px solid;

padding: 8px;

}

不清楚为什么XWPFTable没有这个,但是如果我们看一下XWPFTable.java setInsideHBorder是如何工作的,那么我们可以实现这个相对容易。 提示: Word本身从不使用边框类型STBorder.THICK 。 相反,它使用STBorder.SINGLE因为厚度由大小决定。 这意味着没有大小的边框类型STBorder.THICK也不可见。 和大小为24 * 1 / STBorder.THICK = STBorder.SINGLE不会比STBorder.SINGLE厚STBo

...

考虑使用WindowChrome与GlassFrameThickness = GlassFrameCompleteThickness 。 这不是一个理想的解决方案 - 您必须小心地为窗口标题腾出空间,以及最大化,最小化和关闭按钮。 这就是说,它确实消除了你正在处理的边界问题。 有关如何在使用WindowChrome时管理内容布局的示例,请参阅此答案。 这是一个完整的XAML,它也应该有所帮助:

...

尝试像这样切换你的CSS:

/* The canvas with thick border has the id 'c' */

canvas { border: 2px solid #5408FA; }

#c { border: 8px solid #8525AA; }

First of all: Shame on me! I'll document what was going on, and what mistake I did. I violated th

...

我想到了。 对于未来的观众: objTable.Cell(1, 1).Borders[PPT.PpBorderType.ppBorderLeft].Weight = 0.5f;

objTable.Cell(1, 1).Borders[PPT.PpBorderType.ppBorderRight].Weight = 0.5f;

objTable.Cell(1, 1).Borders[PPT.PpBorderType.ppBorderTop].Weight = 0.5f;

objTable.Cell(

...

这里有另一种选择(如果你想避免table标记)。 .icon-block {

display: flex;

}

.icon-block span {

margin: 0 auto;

text-align: center;

}

div>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值