]> source.dussan.org Git - poi.git/commitdiff
[github-264] extend test
authorPJ Fanning <fanningpj@apache.org>
Fri, 15 Oct 2021 07:49:31 +0000 (07:49 +0000)
committerPJ Fanning <fanningpj@apache.org>
Fri, 15 Oct 2021 07:49:31 +0000 (07:49 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894276 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java

index 1ab3c4136b8eaf199add6f32224cd78dd6e9b955..503119594ff354914a32e90a51a977fb8a95cbf0 100644 (file)
@@ -1254,32 +1254,38 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
         String nameA = "link-external-workbook-a.xlsx";
 
         try (
-                XSSFWorkbook a = new XSSFWorkbook();
-                XSSFWorkbook b = new XSSFWorkbook()
+                UnsynchronizedByteArrayOutputStream bosA = new UnsynchronizedByteArrayOutputStream();
+                UnsynchronizedByteArrayOutputStream bosB = new UnsynchronizedByteArrayOutputStream();
+                XSSFWorkbook workbookA = new XSSFWorkbook();
+                XSSFWorkbook workbookB = new XSSFWorkbook()
         ) {
-            XSSFRow row1 = a.createSheet().createRow(0);
+            XSSFRow row1 = workbookA.createSheet().createRow(0);
             row1.createCell(0).setCellValue(10);
             row1.createCell(1).setCellValue(20);
 
-            XSSFRow row2 = b.createSheet().createRow(0);
+            XSSFRow row2 = workbookB.createSheet().createRow(0);
             XSSFCell cell = row2.createCell(0);
 
-            b.linkExternalWorkbook(nameA, a);
+            workbookB.linkExternalWorkbook(nameA, workbookA);
             String formula = String.format(LocaleUtil.getUserLocale(), "SUM('[%s]Sheet0'!A1:B1)", nameA);
             cell.setCellFormula(formula);
-            XSSFFormulaEvaluator evaluator = b.getCreationHelper().createFormulaEvaluator();
+            XSSFFormulaEvaluator evaluator = workbookB.getCreationHelper().createFormulaEvaluator();
             evaluator.evaluateFormulaCell(cell);
-            double cellValue = cell.getNumericCellValue();
-            assertEquals(cellValue,30.0);
-            /*
-            try (FileOutputStream out = new FileOutputStream(getSampleFile(nameA))) {
-                a.write(out);
+            assertEquals(30.0, cell.getNumericCellValue());
+
+            workbookA.write(bosA);
+            workbookB.write(bosB);
+
+            try(
+                    XSSFWorkbook workbook1 = new XSSFWorkbook(bosA.toInputStream());
+                    XSSFWorkbook workbook2 = new XSSFWorkbook(bosB.toInputStream())
+            ) {
+                workbook2.linkExternalWorkbook(nameA, workbook1);
+                XSSFFormulaEvaluator evaluator2 = workbook2.getCreationHelper().createFormulaEvaluator();
+                XSSFCell cell2 = workbook2.getSheetAt(0).getRow(0).getCell(0);
+                evaluator2.evaluateFormulaCell(cell2);
+                assertEquals(30.0, cell2.getNumericCellValue());
             }
-            String nameB = "link-external-workbook-b.xlsx";
-            try (FileOutputStream out = new FileOutputStream(getSampleFile(nameB))) {
-                b.write(out);
-            }
-            */
         }
     }