You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestSheetAdditional.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.hssf.model;
  16. import static org.junit.jupiter.api.Assertions.assertEquals;
  17. import static org.junit.jupiter.api.Assertions.assertThrows;
  18. import org.apache.poi.hssf.record.ColumnInfoRecord;
  19. import org.junit.jupiter.api.Test;
  20. final class TestSheetAdditional {
  21. @Test
  22. void testGetCellWidth() {
  23. InternalSheet sheet = InternalSheet.createSheet();
  24. ColumnInfoRecord nci = new ColumnInfoRecord();
  25. // Prepare test model
  26. nci.setFirstColumn(5);
  27. nci.setLastColumn(10);
  28. nci.setColumnWidth(100);
  29. sheet._columnInfos.insertColumn(nci);
  30. assertEquals(100,sheet.getColumnWidth(5));
  31. assertEquals(100,sheet.getColumnWidth(6));
  32. assertEquals(100,sheet.getColumnWidth(7));
  33. assertEquals(100,sheet.getColumnWidth(8));
  34. assertEquals(100,sheet.getColumnWidth(9));
  35. assertEquals(100,sheet.getColumnWidth(10));
  36. sheet.setColumnWidth(6,200);
  37. assertEquals(100,sheet.getColumnWidth(5));
  38. assertEquals(200,sheet.getColumnWidth(6));
  39. assertEquals(100,sheet.getColumnWidth(7));
  40. assertEquals(100,sheet.getColumnWidth(8));
  41. assertEquals(100,sheet.getColumnWidth(9));
  42. assertEquals(100,sheet.getColumnWidth(10));
  43. }
  44. @Test
  45. void testMaxColumnWidth() {
  46. InternalSheet sheet = InternalSheet.createSheet();
  47. // the limit
  48. sheet.setColumnWidth(0, 255*256);
  49. // over the limit
  50. IllegalArgumentException ex = assertThrows(
  51. IllegalArgumentException.class,
  52. () -> sheet.setColumnWidth(0, 256*256)
  53. );
  54. assertEquals("The maximum column width for an individual cell is 255 characters.", ex.getMessage());
  55. }
  56. }