jxl.WritableCellFormat 定义

发布于 2024-10-10 10:12:22 字数 459 浏览 1 评论 0原文

是否可以创建一个包含 Font、NumberFormat、BackgroundColor 和 Border 的 jxl.WritableCellFormat 属性?

这有效:

public static final NumberFormat numberformatter = new NumberFormat("#,###0.00");  
public static final WritableFont defaultfont = new WritableFont(WritableFont.TAHOMA, 10); 
public static final WritableCellFormat numberCellFormat = new WritableCellFormat(defaultfont, numberformatter); '

但我无法获得边框和颜色,认为创建工作表时多次需要相同类型的单元格。

Is it possible to create one jxl.WritableCellFormat attribute which contains Font, NumberFormat, BackgroundColor and Border?

This works:

public static final NumberFormat numberformatter = new NumberFormat("#,###0.00");  
public static final WritableFont defaultfont = new WritableFont(WritableFont.TAHOMA, 10); 
public static final WritableCellFormat numberCellFormat = new WritableCellFormat(defaultfont, numberformatter); '

but I can't get borders and colors, thought same kind of cell is needed many times when creating sheets.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

随心而道 2024-10-17 10:12:22

实例化单元格后,您可以通过 WritableCellFormat.setBorder()WritableCellFormat.setBackground() 方法设置边框和背景。

您可以在那里查看 API。

如果你必须经常这样做,你可以创建一个像这样的辅助函数:

public static makeCell(NumberFormat format, WritableFont font, Color backgrd, Border border){
    final WritableCellFormat result = new WritableCellFormat(defaultfont, numberformatter);
    result.setBorder(border);
    result.setBackground(backgrd);
    return result;
}

You can set the border and background via the WritableCellFormat.setBorder() and WritableCellFormat.setBackground() methods after having instanciated your cell.

You can see the API there.

If you have to do that a lot, you can make a helper function like this :

public static makeCell(NumberFormat format, WritableFont font, Color backgrd, Border border){
    final WritableCellFormat result = new WritableCellFormat(defaultfont, numberformatter);
    result.setBorder(border);
    result.setBackground(backgrd);
    return result;
}
战皆罪 2024-10-17 10:12:22

您可以通过 2 个步骤来完成此操作

  1. 创建 WritableFont

  2. 以 WritableFont、NumberFormats 作为参数创建 WritableCellFormat

附加代码片段

int fontSize = 8;  
WritableFont wfontStatus = new WritableFont(WritableFont.ARIAL, fontSize);
wfontStatus.setColour(Colour.BLACK);
wfontStatus.setBoldStyle(WritableFont.BOLD);

WritableCellFormat fCellstatus = new WritableCellFormat(wfontStatus, NumberFormats.TEXT); // You can use any NumberFormats I have used TEXT for my requirement
try {
    fCellstatus.setWrap(true);
    fCellstatus.setBorder(Border.ALL,BorderLineStyle.THIN);
    fCellstatus.setAlignment(Alignment.CENTRE);
    fCellstatus.setBackground(Colour.YELLOW);
} 
catch (WriteException e) {
    e.printStackTrace();
 }

You Can do this by 2 steps

  1. Create a WritableFont

  2. Create a WritableCellFormat with WritableFont,NumberFormats as a parameter

Attaching the code snippet

int fontSize = 8;  
WritableFont wfontStatus = new WritableFont(WritableFont.ARIAL, fontSize);
wfontStatus.setColour(Colour.BLACK);
wfontStatus.setBoldStyle(WritableFont.BOLD);

WritableCellFormat fCellstatus = new WritableCellFormat(wfontStatus, NumberFormats.TEXT); // You can use any NumberFormats I have used TEXT for my requirement
try {
    fCellstatus.setWrap(true);
    fCellstatus.setBorder(Border.ALL,BorderLineStyle.THIN);
    fCellstatus.setAlignment(Alignment.CENTRE);
    fCellstatus.setBackground(Colour.YELLOW);
} 
catch (WriteException e) {
    e.printStackTrace();
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文