mirror of https://github.com/apache/poi.git
Fix NullPointerException in Autosize introduced via #64981
Only happened when alignment is set Add a test reproducing the problem Also verify auto-size on SXSSF git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884653 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d20fa44305
commit
01dabc0d1b
|
@ -592,7 +592,7 @@ public class XSSFCellStyle implements CellStyle, Duplicatable {
|
|||
@Override
|
||||
public short getRotation() {
|
||||
CTCellAlignment align = _cellXf.getAlignment();
|
||||
return align == null ? 0 : align.getTextRotation().shortValue();
|
||||
return align == null || align.getTextRotation() == null ? 0 : align.getTextRotation().shortValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.xssf.usermodel;
|
||||
|
||||
import org.apache.poi.ss.usermodel.BaseTestSheetAutosizeColumn;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.SXSSFITestDataProvider;
|
||||
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class TestSXSSFSheetAutosizeColumn extends BaseTestSheetAutosizeColumn {
|
||||
|
||||
public TestSXSSFSheetAutosizeColumn(){
|
||||
super(SXSSFITestDataProvider.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void trackColumnsForAutoSizingIfSXSSF(Sheet sheet) {
|
||||
((SXSSFSheet)sheet).trackAllColumnsForAutoSizing();
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
|
@ -341,4 +342,22 @@ public abstract class BaseTestSheetAutosizeColumn {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testExcelExporter() {
|
||||
final Workbook wb = _testDataProvider.createWorkbook();
|
||||
final Sheet sheet = wb.createSheet("test");
|
||||
trackColumnsForAutoSizingIfSXSSF(sheet);
|
||||
final Row row = sheet.createRow(0);
|
||||
final Cell cell = row.createCell(0);
|
||||
|
||||
CellStyle csDateTime = wb.createCellStyle();
|
||||
csDateTime.setAlignment(HorizontalAlignment.LEFT);
|
||||
|
||||
cell.setCellValue(new Date(Long.parseLong("1439800763994")));
|
||||
cell.setCellStyle(csDateTime);
|
||||
|
||||
sheet.autoSizeColumn(0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue