简体   繁体   English

当我在Apache POI库中使用Calibri字体时,在可运行jar中的列宽度未正确显示

[英]Column width not coming properly in runnable jar when I use Calibri font in apache poi library

I have built a java application using apache poi. 我已经使用apache poi构建了一个Java应用程序。 It is a simple swing gui app and it generates excel using apache poi library. 这是一个简单的swing gui应用程序,它使用apache poi库生成excel。 After generating sheet I have set autofit column, which is working perfectly fine when I am running the application with RAD . 生成工作表后,我设置了autofit列, 当我使用RAD运行应用程序时 ,该列工作得很好 Now I have generated runnable jar (which is my requirement) and it generates excel but all columns after second column are hiding behind one another . 现在,我已经生成了可运行的jar (这是我的要求),并且它生成了excel, 但是第二列之后的所有列都相互隐藏

I removed autosize column and columns didnt hide behind each other. 我删除了自动调整大小列,并且各列之间没有隐藏。 But I want my columns to be autosized according to text. 但是我希望根据文本自动调整列的大小。 Please tell me what is the correct way to use autosize. 请告诉我使用自动调整大小的正确方法是什么。 And why its working in RAD and not in runnable jar. 以及为什么它在RAD中而不是在可运行的jar中工作。

I get this is font issue. 我得到这是字体问题。 I removed the line where I am setting font name and it worked good. 我删除了我设置字体名称的行,它很好用。 Now my question is how can I use Calibri font. 现在我的问题是如何使用Calibri字体。 Please help. 请帮忙。

Here is my code for writing excel: 这是我编写excel的代码:

public class Excel {
    HSSFWorkbook wb;
    HSSFFont head, defFont;

    public Excel() {
        wb = new HSSFWorkbook);
        //create header font to use Calibri and bold text
        //create default font to use Calibri and normal text
    }

    public void sheetGen() {
        HSSFSheet sheet = wb.creatSheet("sheet1");

        //create style
        //create each row and column
        for (int i = 1; i < 9; i++) {
            if (i != 2)
                sheet.autoSizeColumn(i);  //this is not working in runnable jar
        }
        //write workbook
    }
}

On some platforms, Calibri is a third party font; 在某些平台上, Calibri是第三方字体。 for example, it is included with Microsoft Office on Mac OS X. Instead, use the desired logical fonts from among the five font families defined by the Java platform. 例如,它包含在Mac OS X上的Microsoft Office中。相反,请使用Java平台定义的五个字体系列中所需的逻辑字体。 For example, 例如,

Header: new Font(Font.SansSerif, Font.BOLD | Font.ITALIC, 14) 标题: new Font(Font.SansSerif, Font.BOLD | Font.ITALIC, 14)

Default: new Font(Font.Serif, Font.PLAIN, 12) 默认值: new Font(Font.Serif, Font.PLAIN, 12)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM