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.

TestArrayRecord.java 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.record;
  16. import junit.framework.TestCase;
  17. import org.apache.poi.hssf.HSSFTestDataSamples;
  18. import org.apache.poi.hssf.usermodel.HSSFSheet;
  19. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  20. import org.apache.poi.hssf.util.CellRangeAddress8Bit;
  21. import org.apache.poi.ss.formula.Formula;
  22. import org.apache.poi.ss.formula.FormulaParser;
  23. import org.apache.poi.ss.formula.FormulaRenderer;
  24. import org.apache.poi.ss.formula.FormulaType;
  25. import org.apache.poi.ss.formula.ptg.Ptg;
  26. import org.apache.poi.util.HexDump;
  27. import org.apache.poi.util.HexRead;
  28. public final class TestArrayRecord extends TestCase {
  29. public void testRead() {
  30. String hex =
  31. "21 02 25 00 01 00 01 00 01 01 00 00 00 00 00 00 " +
  32. "17 00 65 00 00 01 00 02 C0 02 C0 65 00 00 01 00 " +
  33. "03 C0 03 C0 04 62 01 07 00";
  34. byte[] data = HexRead.readFromString(hex);
  35. RecordInputStream in = TestcaseRecordInputStream.create(data);
  36. ArrayRecord r1 = new ArrayRecord(in);
  37. CellRangeAddress8Bit range = r1.getRange();
  38. assertEquals(1, range.getFirstColumn());
  39. assertEquals(1, range.getLastColumn());
  40. assertEquals(1, range.getFirstRow());
  41. assertEquals(1, range.getLastRow());
  42. Ptg[] ptg = r1.getFormulaTokens();
  43. assertEquals("MAX(C1:C2-D1:D2)", FormulaRenderer.toFormulaString(null, ptg));
  44. //construct a new ArrayRecord with the same contents as r1
  45. Ptg[] fmlaPtg = FormulaParser.parse("MAX(C1:C2-D1:D2)", null, FormulaType.ARRAY, 0);
  46. ArrayRecord r2 = new ArrayRecord(Formula.create(fmlaPtg), new CellRangeAddress8Bit(1, 1, 1, 1));
  47. byte[] ser = r2.serialize();
  48. //serialize and check that the data is the same as in r1
  49. assertEquals(HexDump.toHex(data), HexDump.toHex(ser));
  50. }
  51. public void testBug57231() {
  52. HSSFWorkbook wb = HSSFTestDataSamples
  53. .openSampleWorkbook("57231_MixedGasReport.xls");
  54. HSSFSheet sheet = wb.getSheet("master");
  55. HSSFSheet newSheet = wb.cloneSheet(wb.getSheetIndex(sheet));
  56. int idx = wb.getSheetIndex(newSheet);
  57. wb.setSheetName(idx, "newName");
  58. // Write the output to a file
  59. HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
  60. assertNotNull(wbBack);
  61. assertNotNull(wbBack.getSheet("master"));
  62. assertNotNull(wbBack.getSheet("newName"));
  63. }
  64. }