diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2015-08-29 21:45:08 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2015-08-29 21:45:08 +0000 |
commit | 72433ac40591b0425116eb5214d7c92cbc1e2bc1 (patch) | |
tree | 3e734a860ea68fda15d0ed38de18de44f9878bfe /src/testcases/org/apache | |
parent | a9f220d1541455abee041321fb26ba6b71388019 (diff) | |
download | poi-72433ac40591b0425116eb5214d7c92cbc1e2bc1.tar.gz poi-72433ac40591b0425116eb5214d7c92cbc1e2bc1.zip |
forbidden apis fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1700076 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r-- | src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java | 7 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java | 128 |
2 files changed, 72 insertions, 63 deletions
diff --git a/src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java b/src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java index 5e64f75da5..d0935af6ca 100644 --- a/src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java +++ b/src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java @@ -26,12 +26,17 @@ import org.junit.runners.Suite; */ @RunWith(Suite.class) @Suite.SuiteClasses({ + TestAreaReference.class, TestCellRangeAddress.class, TestCellReference.class, + TestDateFormatConverter.class, TestExpandedDouble.class, TestNumberComparer.class, TestNumberToTextConverter.class, - TestRegion.class + TestRegion.class, + TestSheetBuilder.class, + TestSheetUtil.class, + TestWorkbookUtil.class }) public class AllSSUtilTests { } diff --git a/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java b/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java index 95042e50f3..418070f16a 100644 --- a/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java +++ b/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java @@ -42,78 +42,82 @@ public final class TestDateFormatConverter extends TestCase { private void outputLocaleDataFormats( Date date, boolean dates, boolean times, int style, String styleName ) throws Exception { Workbook workbook = new HSSFWorkbook(); - String sheetName; - if( dates ) { - if( times ) { - sheetName = "DateTimes"; + try { + String sheetName; + if( dates ) { + if( times ) { + sheetName = "DateTimes"; + } else { + sheetName = "Dates"; + } } else { - sheetName = "Dates"; + sheetName = "Times"; } - } else { - sheetName = "Times"; - } - Sheet sheet = workbook.createSheet(sheetName); - Row header = sheet.createRow(0); - header.createCell(0).setCellValue("locale"); - header.createCell(1).setCellValue("DisplayName"); - header.createCell(2).setCellValue("Excel " + styleName); - header.createCell(3).setCellValue("java.text.DateFormat"); - header.createCell(4).setCellValue("Equals"); - header.createCell(5).setCellValue("Java pattern"); - header.createCell(6).setCellValue("Excel pattern"); - - int rowNum = 1; - for( Locale locale : DateFormat.getAvailableLocales() ) { - try { - Row row = sheet.createRow(rowNum++); - - row.createCell(0).setCellValue(locale.toString()); - row.createCell(1).setCellValue(locale.getDisplayName()); + Sheet sheet = workbook.createSheet(sheetName); + Row header = sheet.createRow(0); + header.createCell(0).setCellValue("locale"); + header.createCell(1).setCellValue("DisplayName"); + header.createCell(2).setCellValue("Excel " + styleName); + header.createCell(3).setCellValue("java.text.DateFormat"); + header.createCell(4).setCellValue("Equals"); + header.createCell(5).setCellValue("Java pattern"); + header.createCell(6).setCellValue("Excel pattern"); - DateFormat dateFormat; - if( dates ) { - if( times ) { - dateFormat = DateFormat.getDateTimeInstance(style, style, locale); + int rowNum = 1; + for( Locale locale : DateFormat.getAvailableLocales() ) { + try { + Row row = sheet.createRow(rowNum++); + + row.createCell(0).setCellValue(locale.toString()); + row.createCell(1).setCellValue(locale.getDisplayName()); + + DateFormat dateFormat; + if( dates ) { + if( times ) { + dateFormat = DateFormat.getDateTimeInstance(style, style, locale); + } else { + dateFormat = DateFormat.getDateInstance(style, locale); + } } else { - dateFormat = DateFormat.getDateInstance(style, locale); + dateFormat = DateFormat.getTimeInstance(style, locale); } - } else { - dateFormat = DateFormat.getTimeInstance(style, locale); + + Cell cell = row.createCell(2); + + cell.setCellValue(date); + CellStyle cellStyle = row.getSheet().getWorkbook().createCellStyle(); + + String javaDateFormatPattern = ((SimpleDateFormat)dateFormat).toPattern(); + String excelFormatPattern = DateFormatConverter.convert(locale, javaDateFormatPattern); + + DataFormat poiFormat = row.getSheet().getWorkbook().createDataFormat(); + cellStyle.setDataFormat(poiFormat.getFormat(excelFormatPattern)); + row.createCell(3).setCellValue(dateFormat.format(date)); + + cell.setCellStyle(cellStyle); + + // the formula returns TRUE is the formatted date in column C equals to the string in column D + row.createCell(4).setCellFormula("TEXT(C"+rowNum+",G"+rowNum+")=D" + rowNum); + row.createCell(5).setCellValue(javaDateFormatPattern); + row.createCell(6).setCellValue(excelFormatPattern); + } catch (Exception e) { + throw new RuntimeException("Failed for locale: " + locale + ", having locales: " + + Arrays.toString(DateFormat.getAvailableLocales()), e); } + } - Cell cell = row.createCell(2); - - cell.setCellValue(date); - CellStyle cellStyle = row.getSheet().getWorkbook().createCellStyle(); - - String javaDateFormatPattern = ((SimpleDateFormat)dateFormat).toPattern(); - String excelFormatPattern = DateFormatConverter.convert(locale, javaDateFormatPattern); - - DataFormat poiFormat = row.getSheet().getWorkbook().createDataFormat(); - cellStyle.setDataFormat(poiFormat.getFormat(excelFormatPattern)); - row.createCell(3).setCellValue(dateFormat.format(date)); - - cell.setCellStyle(cellStyle); - - // the formula returns TRUE is the formatted date in column C equals to the string in column D - row.createCell(4).setCellFormula("TEXT(C"+rowNum+",G"+rowNum+")=D" + rowNum); - row.createCell(5).setCellValue(javaDateFormatPattern); - row.createCell(6).setCellValue(excelFormatPattern); - } catch (Exception e) { - throw new RuntimeException("Failed for locale: " + locale + ", having locales: " + - Arrays.toString(DateFormat.getAvailableLocales()), e); + File outputFile = TempFile.createTempFile("Locale" + sheetName + styleName, ".xlsx"); + FileOutputStream outputStream = new FileOutputStream(outputFile); + try { + workbook.write(outputStream); + } finally { + outputStream.close(); } - } - - File outputFile = TempFile.createTempFile("Locale" + sheetName + styleName, ".xlsx"); - FileOutputStream outputStream = new FileOutputStream(outputFile); - try { - workbook.write(outputStream); + + System.out.println("Open " + outputFile.getAbsolutePath()+" in Excel"); } finally { - outputStream.close(); + workbook.close(); } - - System.out.println("Open " + outputFile.getAbsolutePath()+" in Excel"); } public void testJavaDateFormatsInExcel() throws Exception { |