2003-07-09 16:18:56 -04:00
|
|
|
/* ====================================================================
|
2006-12-22 14:18:16 -05:00
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
2004-04-09 09:05:39 -04:00
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
2003-07-09 16:18:56 -04:00
|
|
|
|
|
|
|
package org.apache.poi.hssf.usermodel;
|
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
import junit.framework.TestCase;
|
|
|
|
|
|
|
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
2003-07-09 16:18:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests row shifting capabilities.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Shawn Laubach (slaubach at apache dot com)
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public final class TestHSSFHeaderFooter extends TestCase {
|
2003-07-09 16:18:56 -04:00
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
/**
|
|
|
|
* Tests that get header retreives the proper values.
|
|
|
|
*
|
|
|
|
* @author Shawn Laubach (slaubach at apache dot org)
|
|
|
|
*/
|
|
|
|
public void testRetrieveCorrectHeader() {
|
|
|
|
// Read initial file in
|
|
|
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("EmbeddedChartHeaderTest.xls");
|
|
|
|
HSSFSheet s = wb.getSheetAt( 0 );
|
|
|
|
HSSFHeader head = s.getHeader();
|
|
|
|
|
|
|
|
assertEquals("Top Left", head.getLeft());
|
|
|
|
assertEquals("Top Center", head.getCenter());
|
|
|
|
assertEquals("Top Right", head.getRight());
|
|
|
|
}
|
2008-08-14 17:25:16 -04:00
|
|
|
|
|
|
|
public void testSpecialChars() {
|
|
|
|
assertEquals("&U", HSSFHeader.startUnderline());
|
|
|
|
assertEquals("&U", HSSFHeader.endUnderline());
|
|
|
|
assertEquals("&P", HSSFHeader.page());
|
|
|
|
|
|
|
|
assertEquals("&22", HSSFFooter.fontSize((short)22));
|
|
|
|
assertEquals("&\"Arial,bold\"", HSSFFooter.font("Arial", "bold"));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testStripFields() {
|
|
|
|
String simple = "I am a test header";
|
|
|
|
String withPage = "I am a&P test header";
|
|
|
|
String withLots = "I&A am&N a&P test&T header&U";
|
|
|
|
String withFont = "I&22 am a&\"Arial,bold\" test header";
|
2008-08-14 17:41:01 -04:00
|
|
|
String withOtherAnds = "I am a&P test header&&";
|
|
|
|
String withOtherAnds2 = "I am a&P test header&a&b";
|
2008-08-14 17:25:16 -04:00
|
|
|
|
|
|
|
assertEquals(simple, HSSFHeader.stripFields(simple));
|
|
|
|
assertEquals(simple, HSSFHeader.stripFields(withPage));
|
|
|
|
assertEquals(simple, HSSFHeader.stripFields(withLots));
|
|
|
|
assertEquals(simple, HSSFHeader.stripFields(withFont));
|
2008-08-14 17:41:01 -04:00
|
|
|
assertEquals(simple + "&&", HSSFHeader.stripFields(withOtherAnds));
|
|
|
|
assertEquals(simple + "&a&b", HSSFHeader.stripFields(withOtherAnds2));
|
2008-08-14 17:25:16 -04:00
|
|
|
|
|
|
|
// Now test the default strip flag
|
|
|
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("EmbeddedChartHeaderTest.xls");
|
|
|
|
HSSFSheet s = wb.getSheetAt( 0 );
|
|
|
|
HSSFHeader head = s.getHeader();
|
|
|
|
|
|
|
|
assertEquals("Top Left", head.getLeft());
|
|
|
|
assertEquals("Top Center", head.getCenter());
|
|
|
|
assertEquals("Top Right", head.getRight());
|
|
|
|
|
|
|
|
head.setLeft("Top &P&F&D Left");
|
|
|
|
assertEquals("Top &P&F&D Left", head.getLeft());
|
|
|
|
assertFalse(head.areFieldsStripped());
|
|
|
|
|
|
|
|
head.setAreFieldsStripped(true);
|
|
|
|
assertEquals("Top Left", head.getLeft());
|
|
|
|
assertTrue(head.areFieldsStripped());
|
2008-08-14 17:41:01 -04:00
|
|
|
|
|
|
|
// Now even more complex
|
2008-08-30 10:47:33 -04:00
|
|
|
head.setCenter("HEADER TEXT &P&N&D&T&Z&F&F&A&G&X END");
|
|
|
|
assertEquals("HEADER TEXT END", head.getCenter());
|
2008-08-14 17:25:16 -04:00
|
|
|
}
|
2003-07-09 16:18:56 -04:00
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
/**
|
|
|
|
* Tests that get header retreives the proper values.
|
|
|
|
*
|
|
|
|
* @author Shawn Laubach (slaubach at apache dot org)
|
|
|
|
*/
|
|
|
|
public void testRetrieveCorrectFooter() {
|
|
|
|
// Read initial file in
|
|
|
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("EmbeddedChartHeaderTest.xls");
|
|
|
|
HSSFSheet s = wb.getSheetAt( 0 );
|
|
|
|
HSSFFooter foot = s.getFooter();
|
2005-04-28 09:35:38 -04:00
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
assertEquals("Bottom Left", foot.getLeft());
|
|
|
|
assertEquals("Bottom Center", foot.getCenter());
|
|
|
|
assertEquals("Bottom Right", foot.getRight());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-04-28 09:35:38 -04:00
|
|
|
* Testcase for Bug 17039 HSSFHeader doesnot support DBCS
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void testHeaderHas16bitCharacter() {
|
|
|
|
HSSFWorkbook b = new HSSFWorkbook();
|
|
|
|
HSSFSheet s = b.createSheet("Test");
|
|
|
|
HSSFHeader h = s.getHeader();
|
|
|
|
h.setLeft("\u0391");
|
|
|
|
h.setCenter("\u0392");
|
|
|
|
h.setRight("\u0393");
|
|
|
|
|
|
|
|
HSSFWorkbook b2 = HSSFTestDataSamples.writeOutAndReadBack(b);
|
|
|
|
HSSFHeader h2 = b2.getSheet("Test").getHeader();
|
|
|
|
|
|
|
|
assertEquals(h2.getLeft(),"\u0391");
|
|
|
|
assertEquals(h2.getCenter(),"\u0392");
|
|
|
|
assertEquals(h2.getRight(),"\u0393");
|
2005-04-28 09:35:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Testcase for Bug 17039 HSSFFooter doesnot support DBCS
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void testFooterHas16bitCharacter() {
|
|
|
|
HSSFWorkbook b = new HSSFWorkbook();
|
|
|
|
HSSFSheet s = b.createSheet("Test");
|
|
|
|
HSSFFooter f = s.getFooter();
|
|
|
|
f.setLeft("\u0391");
|
|
|
|
f.setCenter("\u0392");
|
|
|
|
f.setRight("\u0393");
|
|
|
|
|
|
|
|
HSSFWorkbook b2 = HSSFTestDataSamples.writeOutAndReadBack(b);
|
|
|
|
HSSFFooter f2 = b2.getSheet("Test").getFooter();
|
|
|
|
|
|
|
|
assertEquals(f2.getLeft(),"\u0391");
|
|
|
|
assertEquals(f2.getCenter(),"\u0392");
|
|
|
|
assertEquals(f2.getRight(),"\u0393");
|
2005-04-28 09:35:38 -04:00
|
|
|
}
|
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
public void testReadDBCSHeaderFooter() {
|
|
|
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DBCSHeader.xls");
|
|
|
|
HSSFSheet s = wb.getSheetAt(0);
|
|
|
|
HSSFHeader h = s.getHeader();
|
|
|
|
assertEquals("Header Left " ,h.getLeft(),"\u090f\u0915");
|
|
|
|
assertEquals("Header Center " ,h.getCenter(),"\u0939\u094b\u0917\u093e");
|
|
|
|
assertEquals("Header Right " ,h.getRight(),"\u091c\u093e");
|
2005-04-28 09:35:38 -04:00
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
HSSFFooter f = s.getFooter();
|
|
|
|
assertEquals("Footer Left " ,f.getLeft(),"\u091c\u093e");
|
|
|
|
assertEquals("Footer Center " ,f.getCenter(),"\u091c\u093e");
|
|
|
|
assertEquals("Footer Right " ,f.getRight(),"\u091c\u093e");
|
2005-04-28 09:35:38 -04:00
|
|
|
}
|
2003-07-09 16:18:56 -04:00
|
|
|
}
|
|
|
|
|