選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

TestXSSFUnicodeSurrogates.java 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xssf.usermodel;
  16. import static org.junit.jupiter.api.Assertions.assertEquals;
  17. import org.apache.poi.ss.usermodel.Cell;
  18. import org.apache.poi.ss.usermodel.Row;
  19. import org.apache.poi.ss.usermodel.Sheet;
  20. import org.apache.poi.util.TempFile;
  21. import org.junit.jupiter.api.Test;
  22. import java.io.File;
  23. import java.io.FileInputStream;
  24. import java.io.FileOutputStream;
  25. import java.io.IOException;
  26. class TestXSSFUnicodeSurrogates {
  27. // "𝝊𝝋𝝌𝝍𝝎𝝏𝝐𝝑𝝒𝝓𝝔𝝕𝝖𝝗𝝘𝝙𝝚𝝛𝝜𝝝𝝞𝝟𝝠𝝡𝝢𝝣𝝤𝝥𝝦𝝧𝝨𝝩𝝪𝝫𝝬𝝭𝝮𝝯𝝰𝝱𝝲𝝳𝝴𝝵𝝶𝝷𝝸𝝹𝝺";
  28. private static final String unicodeText =
  29. "\uD835\uDF4A\uD835\uDF4B\uD835\uDF4C\uD835\uDF4D\uD835\uDF4E\uD835\uDF4F\uD835\uDF50\uD835" +
  30. "\uDF51\uD835\uDF52\uD835\uDF53\uD835\uDF54\uD835\uDF55\uD835\uDF56\uD835\uDF57\uD835\uDF58" +
  31. "\uD835\uDF59\uD835\uDF5A\uD835\uDF5B\uD835\uDF5C\uD835\uDF5D\uD835\uDF5E\uD835\uDF5F\uD835" +
  32. "\uDF60\uD835\uDF61\uD835\uDF62\uD835\uDF63\uD835\uDF64\uD835\uDF65\uD835\uDF66\uD835\uDF67" +
  33. "\uD835\uDF68\uD835\uDF69\uD835\uDF6A\uD835\uDF6B\uD835\uDF6C\uD835\uDF6D\uD835\uDF6E\uD835" +
  34. "\uDF6F\uD835\uDF70\uD835\uDF71\uD835\uDF72\uD835\uDF73\uD835\uDF74\uD835\uDF75\uD835\uDF76" +
  35. "\uD835\uDF77\uD835\uDF78\uD835\uDF79\uD835\uDF7A";
  36. @Test
  37. void testWriteUnicodeSurrogates() throws IOException {
  38. String sheetName = "Sheet1";
  39. File tf = TempFile.createTempFile("poi-xmlbeans-test", ".xlsx");
  40. try (XSSFWorkbook wb = new XSSFWorkbook()) {
  41. Sheet sheet = wb.createSheet(sheetName);
  42. Row row = sheet.createRow(0);
  43. Cell cell = row.createCell(0);
  44. cell.setCellValue(unicodeText);
  45. try (FileOutputStream os = new FileOutputStream(tf)) {
  46. wb.write(os);
  47. }
  48. try (FileInputStream fis = new FileInputStream(tf);
  49. XSSFWorkbook wb2 = new XSSFWorkbook(fis)) {
  50. Sheet sheet2 = wb2.getSheet(sheetName);
  51. Cell cell2 = sheet2.getRow(0).getCell(0);
  52. assertEquals(unicodeText, cell2.getStringCellValue());
  53. }
  54. } finally {
  55. tf.delete();
  56. }
  57. }
  58. }