]> source.dussan.org Git - poi.git/commitdiff
right to left xlsx test
authorPJ Fanning <fanningpj@apache.org>
Tue, 20 Jul 2021 12:43:52 +0000 (12:43 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 20 Jul 2021 12:43:52 +0000 (12:43 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891682 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
test-data/spreadsheet/right-to-left.xlsx [new file with mode: 0644]

index ef17baa8e72c3416c33154d6e3fd6bc44f6dc286..58beb8896b40d8e3e8982f662129ace058e456f4 100644 (file)
@@ -31,11 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.*;
 import java.nio.charset.StandardCharsets;
 import java.util.Date;
 import java.util.Iterator;
@@ -58,16 +54,10 @@ import org.apache.poi.openxml4j.opc.internal.FileHelper;
 import org.apache.poi.openxml4j.opc.internal.MemoryPackagePart;
 import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
 import org.apache.poi.ss.tests.usermodel.BaseTestXWorkbook;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.RichTextString;
-import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.apache.poi.ss.util.AreaReference;
+import org.apache.poi.ss.util.CellAddress;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LocaleUtil;
@@ -83,7 +73,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCalcMode;
 
-public final class  TestXSSFWorkbook extends BaseTestXWorkbook {
+public final class TestXSSFWorkbook extends BaseTestXWorkbook {
 
     public TestXSSFWorkbook() {
         super(XSSFITestDataProvider.instance);
@@ -1136,4 +1126,33 @@ public final class  TestXSSFWorkbook extends BaseTestXWorkbook {
         wbBack.close();
         wbBack2.close();
     }
+
+    @Test
+    void testRightToLeft() throws IOException {
+        try(XSSFWorkbook workbook = openSampleWorkbook("right-to-left.xlsx")){
+            Sheet sheet = workbook.getSheet("عربى");
+
+            Cell A1 = sheet.getRow(0).getCell(0);
+            Cell A2 = sheet.getRow(1).getCell(0);
+            Cell A3 = sheet.getRow(2).getCell(0);
+            Cell A4 = sheet.getRow(3).getCell(0);
+
+            expectFormattedContent(A1, "نص");
+            expectFormattedContent(A2, "123"); //this should really be ۱۲۳
+            expectFormattedContent(A3, "text with comment");
+            expectFormattedContent(A4, " עִבְרִית and اَلْعَرَبِيَّةُ");
+
+            Comment a3Comment = sheet.getCellComment(new CellAddress("A3"));
+            assertTrue(a3Comment.getString().getString().contains("تعليق الاختبا"));
+        }
+    }
+
+    private static void expectFormattedContent(Cell cell, String value) {
+        assertEquals(value, new DataFormatter().formatCellValue(cell),
+                "Cell " + ref(cell) + " has wrong formatted content.");
+    }
+
+    private static String ref(Cell cell) {
+        return new CellReference(cell).formatAsString();
+    }
 }
diff --git a/test-data/spreadsheet/right-to-left.xlsx b/test-data/spreadsheet/right-to-left.xlsx
new file mode 100644 (file)
index 0000000..48e3353
Binary files /dev/null and b/test-data/spreadsheet/right-to-left.xlsx differ