ASF Bugzilla – Attachment 33069 Details for
Bug 55752
Using RegionUtil will result merged cell turn black when clicked in
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Save workbook to poi.test.xssf.output.dir
bug55752.patch (text/plain), 9.03 KB, created by
Javen O'Neal
on 2015-09-06 10:59:09 UTC
(
hide
)
Description:
Save workbook to poi.test.xssf.output.dir
Filename:
MIME Type:
Creator:
Javen O'Neal
Created:
2015-09-06 10:59:09 UTC
Size:
9.03 KB
patch
obsolete
>Index: src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java (revision 1698089) >+++ src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java (working copy) >@@ -18,10 +18,7 @@ > package org.apache.poi.xssf.usermodel; > > import java.io.ByteArrayOutputStream; >-import java.io.File; >-import java.io.FileOutputStream; > import java.io.IOException; >-import java.io.OutputStream; > import java.nio.charset.Charset; > import java.util.Calendar; > import java.util.Date; >@@ -220,64 +217,54 @@ > > @Test > public void testBug55752() throws IOException { >- Workbook wb = new XSSFWorkbook(); >- try { >- Sheet sheet = wb.createSheet("test"); >- >- for (int i = 0; i < 4; i++) { >- Row row = sheet.createRow(i); >- for (int j = 0; j < 2; j++) { >- Cell cell = row.createCell(j); >- cell.setCellStyle(wb.createCellStyle()); >- } >+ final Workbook wb = new XSSFWorkbook(); >+ Sheet sheet = wb.createSheet("test"); >+ >+ for (int i = 0; i < 4; i++) { >+ Row row = sheet.createRow(i); >+ for (int j = 0; j < 2; j++) { >+ Cell cell = row.createCell(j); >+ cell.setCellStyle(wb.createCellStyle()); > } >- >- // set content >- Row row1 = sheet.getRow(0); >- row1.getCell(0).setCellValue("AAA"); >- Row row2 = sheet.getRow(1); >- row2.getCell(0).setCellValue("BBB"); >- Row row3 = sheet.getRow(2); >- row3.getCell(0).setCellValue("CCC"); >- Row row4 = sheet.getRow(3); >- row4.getCell(0).setCellValue("DDD"); >- >- // merge cells >- CellRangeAddress range1 = new CellRangeAddress(0, 0, 0, 1); >- sheet.addMergedRegion(range1); >- CellRangeAddress range2 = new CellRangeAddress(1, 1, 0, 1); >- sheet.addMergedRegion(range2); >- CellRangeAddress range3 = new CellRangeAddress(2, 2, 0, 1); >- sheet.addMergedRegion(range3); >- assertEquals(0, range3.getFirstColumn()); >- assertEquals(1, range3.getLastColumn()); >- assertEquals(2, range3.getLastRow()); >- CellRangeAddress range4 = new CellRangeAddress(3, 3, 0, 1); >- sheet.addMergedRegion(range4); >- >- // set border >- RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, range1, sheet, wb); >- >- row2.getCell(0).getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); >- row2.getCell(1).getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); >+ } > >- Cell cell0 = CellUtil.getCell(row3, 0); >- CellUtil.setCellStyleProperty(cell0, wb, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN); >- Cell cell1 = CellUtil.getCell(row3, 1); >- CellUtil.setCellStyleProperty(cell1, wb, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN); >+ // set content >+ Row row1 = sheet.getRow(0); >+ row1.getCell(0).setCellValue("AAA"); >+ Row row2 = sheet.getRow(1); >+ row2.getCell(0).setCellValue("BBB"); >+ Row row3 = sheet.getRow(2); >+ row3.getCell(0).setCellValue("CCC"); >+ Row row4 = sheet.getRow(3); >+ row4.getCell(0).setCellValue("DDD"); > >- RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, range4, sheet, wb); >- >- // write to file >- OutputStream stream = new FileOutputStream(new File("C:/temp/55752.xlsx")); >- try { >- wb.write(stream); >- } finally { >- stream.close(); >- } >- } finally { >- wb.close(); >- } >+ // merge cells >+ CellRangeAddress range1 = new CellRangeAddress(0, 0, 0, 1); >+ sheet.addMergedRegion(range1); >+ CellRangeAddress range2 = new CellRangeAddress(1, 1, 0, 1); >+ sheet.addMergedRegion(range2); >+ CellRangeAddress range3 = new CellRangeAddress(2, 2, 0, 1); >+ sheet.addMergedRegion(range3); >+ assertEquals(0, range3.getFirstColumn()); >+ assertEquals(1, range3.getLastColumn()); >+ assertEquals(2, range3.getLastRow()); >+ CellRangeAddress range4 = new CellRangeAddress(3, 3, 0, 1); >+ sheet.addMergedRegion(range4); >+ >+ // set border >+ RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, range1, sheet, wb); >+ >+ row2.getCell(0).getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); >+ row2.getCell(1).getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); >+ >+ Cell cell0 = CellUtil.getCell(row3, 0); >+ CellUtil.setCellStyleProperty(cell0, wb, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN); >+ Cell cell1 = CellUtil.getCell(row3, 1); >+ CellUtil.setCellStyleProperty(cell1, wb, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN); >+ >+ RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, range4, sheet, wb); >+ >+ XSSFTestDataSamples.writeOutToFile(wb, "bug55752"); > } > > @Test >Index: src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java (revision 1698089) >+++ src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java (working copy) >@@ -56,10 +56,13 @@ > public static XSSFWorkbook openSampleWorkbook(String sampleName) { > InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName); > try { >- return new XSSFWorkbook(is); >+ final XSSFWorkbook wb = new XSSFWorkbook(is); >+ is.close(); >+ return wb; > } catch (IOException e) { > throw new RuntimeException(e); > } >+ > } > public static <R extends Workbook> R writeOutAndReadBack(R wb) { > Workbook result; >@@ -84,6 +87,51 @@ > } > > /** >+ * Writes the Workbook into a file using the system property {@value #TEST_OUTPUT_DIR}/testName.xlsx >+ * @param wb workbook to write >+ * @param testName file name to be used to save the workbook. The old file with the same name will be overridden. >+ */ >+ public static <R extends Workbook> void writeOutToFile(R wb, String testName) throws IOException { >+ final String test_output_dir = System.getProperty(TEST_OUTPUT_DIR); >+ if (test_output_dir != null) { >+ File file = new File(test_output_dir, testName + ".xlsx"); >+ writeOutToFile(wb, file); >+ } >+ else { >+ throw new RuntimeException("System property " + TEST_OUTPUT_DIR + " must be set"); >+ } >+ } >+ >+ >+ /** >+ * Writes the Workbook into the specified file >+ * @param wb workbook to write >+ * @param file location to save the workbook. An old file with the same name will be overridden. >+ */ >+ public static <R extends Workbook> void writeOutToFile(R wb, File file) throws IOException { >+ if (file.exists()) { >+ file.delete(); >+ } >+ FileOutputStream out = new FileOutputStream(file); >+ try { >+ wb.write(out); >+ } finally { >+ out.close(); >+ } >+ } >+ >+ /** >+ * Reads the Workbook from the specified file >+ * @param file location to read the workbook. >+ * @return workbook read in from file >+ */ >+ public static XSSFWorkbook readInFromFile(File file) throws IOException { >+ final InputStream is = new FileInputStream(file); >+ XSSFWorkbook result = new XSSFWorkbook(is); >+ return result; >+ } >+ >+ /** > * Writes the Workbook either into a file or into a byte array, depending on presence of > * the system property {@value #TEST_OUTPUT_DIR}, and reads it in a new instance of the Workbook back. > * @param wb workbook to write >@@ -92,24 +140,12 @@ > */ > public static <R extends Workbook> R writeOutAndReadBack(R wb, String testName) { > XSSFWorkbook result = null; >- if (System.getProperty(TEST_OUTPUT_DIR) != null) { >+ final String test_output_dir = System.getProperty(TEST_OUTPUT_DIR); >+ if (test_output_dir != null) { > try { >- File file = new File(System.getProperty(TEST_OUTPUT_DIR), testName + ".xlsx"); >- if (file.exists()) { >- file.delete(); >- } >- FileOutputStream out = new FileOutputStream(file); >- try { >- wb.write(out); >- } finally { >- out.close(); >- } >- FileInputStream in = new FileInputStream(file); >- try { >- result = new XSSFWorkbook(in); >- } finally { >- in.close(); >- } >+ File file = new File(test_output_dir, testName + ".xlsx"); >+ writeOutToFile(wb, file); >+ result = readInFromFile(file); > } catch (IOException e) { > throw new RuntimeException(e); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 55752
:
31022
| 33069