Apache POI autoSizeColumn不正确地调整大小 [英] Apache POI autoSizeColumn Resizes Incorrectly
问题描述
没有空白单元格被写(我相信),调整大小是最后一个
以下是相关的代码:这是一个没有错误处理的boiled down版本等。
public static synchronized String storeResults(ArrayList< String> resultList,String file){
if(resultList == null || resultList.size == 0){
return file;
}
FileOutputStream stream = new FileOutputStream(file);
//创建工作簿和结果表
XSSFWorkbook book = new XSSFWorkbook();
工作表结果= book.createSheet(结果);
//将结果写入工作簿
for(int x = 0; x< resultList.size(); x ++){
String [] items = resultList.get x)的.split(PRIM_DELIM);
行行= results.createRow(x); (int i = 0; i< items.length; i ++){
row.createCell(i).setCellValue(items [i]);
}
}
//自动调整所有列
(x = 0; x< results.getRow(0).getPhysicalNumberOfCells(); x ++ ){
results.autoSizeColumn(x);
}
//写书并关闭流
book.write(stream);
stream.flush();
stream.close();
返回文件;
}
我知道这里有几个问题,但大部分是仅仅是在填写数据之前确定大小的情况。而且少数不是更复杂/没有答案。
编辑:我尝试使用几种不同的字体,它没有工作。这不是太令人惊讶,因为无论什么字体的所有列应该完全崩溃或没有应该是。
另外,因为字体问题出现,我在Windows 7上运行程序。
解决方案:这是一个字体问题。我找到的唯一字体是Serif。
只是为了从我的评论中做出回答。这些行无法正确调整大小,因为Java不知道您尝试使用的字体这个链接应该有帮助,如果你想要安装新的字体到Java,所以你可以使用一些爱好者。它还具有Java知道的默认字体列表。
很高兴这有助于您解决问题!
I'm using Apache POI in java to create an excel file. I fill in the data then try to autosize each column, however the sizes are always wrong (and I think consistent). The first two rows are always(?) completely collapsed. When I autosize the columns in excel, it works perfectly.
No blank cells are being written (I believe) and the resizing is the last thing I do.
Here's the relevant code: This is a boiled down version without error handling, etc.
public static synchronized String storeResults(ArrayList<String> resultList, String file) {
if (resultList == null || resultList.size() == 0) {
return file;
}
FileOutputStream stream = new FileOutputStream(file);
//Create workbook and result sheet
XSSFWorkbook book = new XSSFWorkbook();
Sheet results = book.createSheet("Results");
//Write results to workbook
for (int x = 0; x < resultList.size(); x++) {
String[] items = resultList.get(x).split(PRIM_DELIM);
Row row = results.createRow(x);
for (int i = 0; i < items.length; i++) {
row.createCell(i).setCellValue(items[i]);
}
}
//Auto size all the columns
for (x = 0; x < results.getRow(0).getPhysicalNumberOfCells(); x++) {
results.autoSizeColumn(x);
}
//Write the book and close the stream
book.write(stream);
stream.flush();
stream.close();
return file;
}
I know there are a few questions out there similar, but most of them are simply a case of sizing before filling in the data. And the few that aren't are more complicated/unanswered.
EDIT: I tried using a couple different fonts and it didn't work. Which isn't too surprising, as no matter what the font either all the columns should be completely collapsed or none should be.
Also, because the font issue came up, I'm running the program on Windows 7.
SOLVED: It was a font issue. The only font that I found that worked was Serif.
Just to make an answer out of my comment. The rows couldn't size properly because Java was unaware of the font you were trying to use this link should help if you want to install new fonts into Java so you could use something fancier. It also has the list of default fonts that Java knows.
Glad this helped and you got your issue solved!
这篇关于Apache POI autoSizeColumn不正确地调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!