将表格边框设置为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;

}

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

  1. html中隐藏单元格上边框,HTML table 标签边框问题(隐藏表格边框、单元格边框等)...

    一.表格的常用属性 基本属性有:width(宽度).height(高度).border(边框值).cellspacing(表格的内宽,即表格与tr之间的间隔). cellpadding(表格内元素的间 ...

  2. HTML table 标签边框问题(隐藏表格边框、单元格边框等)

    一.表格的常用属性 基本属性有:width(宽度).height(高度).border(边框值).cellspacing(表格的内宽,即表格与tr之间的间隔). cellpadding(表格内元素的间 ...

  3. html table 边框线隐藏,HTML table 标签边框问题(隐藏表格边框、单元格边框等)...

    一.表格的常用属性 基本属性有:width(宽度).height(高度).border(边框值).cellspacing(表格的内宽,即表格与tr之间的间隔). cellpadding(表格内元素的间 ...

  4. 如何给table表格的tr行加border边框(解决篇)

    文章目录 一.如何给table表格的tr行加border边框 二.样式 bug - 截图示下 三.解决办法: 四.关于属性 `border-collapse`的取值.解析 一.如何给table表格的t ...

  5. php设置表格边框颜色,HTML表格标记教程(38):表头的边框色属性BORDERCOLOR

    HTML表格标记教程(38):表头的边框色属性BORDERCOLOR 互联网   发布时间:2008-10-17 18:57:02   作者:佚名   我要评论 为了美化表格,可以为表头设定不同的边框 ...

  6. 【HTML+CSS网页设计与布局 从入门到精通】第15章-表格格式:边距/居中/边框/折叠

    目录 初始表格 边距.居中.边框 单元格边距cellspacing 边距折叠(两个叠加不会变粗)border-collapse:collapse; 单元格边距border-spacing 初始表格 & ...

  7. Excel表格复制到Foxmail不显示边框

    在复制粘贴Excel表格内容到Foxmail 时,边框粗线经常出现某一边不显示问题: 在Excel 表格显示完好: 复制表格粘贴到Foxmail 邮件时,出现了局部边框不显示问题. 解决方法: 将表格 ...

  8. 计算机考试中如何设置表格外边框,Excel表格中怎么为单元格区域设置边框

    在Excel表格工作表中,我们可以为选中的单元格区域设置各种类型的边框.Excel表格中为单元格区域设置边框的方法其实很简单,下面由学习啦小编告诉你! Excel表格中为单元格区域设置边框的方法 01 ...

  9. php表格所有边框实线,css表格怎么添加边框样式?css表格边框样式总结(附完整实例)...

    本篇文章主要讲述的就是关于css表格添加边框样式,这里还有关于css表格边框样式的总结,还有css表格边框的完整实例.接下来就让我们一起来看这篇文章吧 首先我们先看看如何利用css来给表格添加边框: ...

最新文章

  1. 万亿级企业MySQL海量存储分库分表设计实践
  2. vscode使用教程python-VS Code 配置 Python 开发环境
  3. kotlin学习笔记——内联函数
  4. 我的世界java什么村民卖地图_《我的世界》推出虚拟货币、商店 玩家可在店中卖地图...
  5. Java实现 第三方的验证码发送问题--博客园老牛大讲堂
  6. mysql5.5连不上主机_mysql5.5主从同步排错
  7. web前端简历的详解
  8. 3090显卡 爆显存调试
  9. java——Random种子
  10. java实验四 综合应用实验
  11. yolov5的detect.py代码详解
  12. vue h5手机网站支付宝支付 - 前端
  13. 电子产品安规测试及检测设备
  14. 1w存银行一年多少利息_500万、1000万存银行一年有多少钱利息?能靠利息生活吗?...
  15. 软件系统需求分析策划方案
  16. BABvsBABAB
  17. PAT 十一章 模拟 17-24 自用
  18. Win11微信消息任务栏右下角不闪烁解决办法
  19. 画出微型计算机结构图,微型计算机试卷(1997年)
  20. linux selinux_安全Linux:第1部分。SELinux –其开发,架构和操作原理的历史

热门文章

  1. linux查看文件位置
  2. ThinkPHP5生成支付二维码
  3. 蓝牙广播包中自定义厂家数据的设置及获取
  4. 【招行】信用卡推荐用户列表 数据岗
  5. 使用 Spring 构建 REST 服务
  6. java获取和设置系统变量(环境变量)
  7. 请输入标题 请输入文本内容
  8. 赛效:怎么将PPT转为PDF
  9. ubuntu18.04连接蓝牙耳机
  10. mysql 参数名 下划线,MySQL表名称中的下划线会引起问题吗?