use of org.apache.poi.hssf.usermodel.HSSFSheet in project poi by apache.
the class TestDrawingShapes method testCorrectOrderInOptRecord.
@Test
public void testCorrectOrderInOptRecord() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
EscherOptRecord opt = HSSFTestHelper.getOptRecord(textbox);
String opt1Str = opt.toXml();
textbox.setFillColor(textbox.getFillColor());
EscherContainerRecord container = HSSFTestHelper.getEscherContainer(textbox);
EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);
assertEquals(opt1Str, optRecord.toXml());
textbox.setLineStyle(textbox.getLineStyle());
assertEquals(opt1Str, optRecord.toXml());
textbox.setLineWidth(textbox.getLineWidth());
assertEquals(opt1Str, optRecord.toXml());
textbox.setLineStyleColor(textbox.getLineStyleColor());
assertEquals(opt1Str, optRecord.toXml());
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFSheet in project poi by apache.
the class TestPageSettingsBlock method testPrintSetup_bug46548.
public void testPrintSetup_bug46548() {
// PageSettingBlock in this file contains PLS (sid=x004D) record
// followed by ContinueRecord (sid=x003C)
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex46548-23133.xls");
HSSFSheet sheet = wb.getSheetAt(0);
HSSFPrintSetup ps = sheet.getPrintSetup();
try {
ps.getCopies();
} catch (NullPointerException e) {
e.printStackTrace();
throw new AssertionFailedError("Identified bug 46548: PageSettingBlock missing PrintSetupRecord record");
}
}
use of org.apache.poi.hssf.usermodel.HSSFSheet in project poi by apache.
the class TestCFRecordsAggregate method testCantMixTypes.
public void testCantMixTypes() {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
CellRangeAddress[] cellRanges = { new CellRangeAddress(0, 1, 0, 0), new CellRangeAddress(0, 1, 2, 2) };
CFRuleBase[] rules = { CFRuleRecord.create(sheet, "7"), CFRule12Record.create(sheet, ComparisonOperator.BETWEEN, "2", "5") };
try {
new CFRecordsAggregate(cellRanges, rules);
fail("Shouldn't be able to mix between types");
} catch (IllegalArgumentException e) {
// expected here
}
rules = new CFRuleBase[] { CFRuleRecord.create(sheet, "7") };
CFRecordsAggregate agg = new CFRecordsAggregate(cellRanges, rules);
assertTrue(agg.getHeader().getNeedRecalculation());
try {
agg.addRule(CFRule12Record.create(sheet, "7"));
fail("Shouldn't be able to mix between types");
} catch (IllegalArgumentException e) {
// expected here
}
}
use of org.apache.poi.hssf.usermodel.HSSFSheet in project poi by apache.
the class TestCFRecordsAggregate method testCFRecordsAggregate.
public void testCFRecordsAggregate() {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
List<Record> recs = new ArrayList<Record>();
CFHeaderBase header = new CFHeaderRecord();
CFRuleBase rule1 = CFRuleRecord.create(sheet, "7");
CFRuleBase rule2 = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5");
CFRuleBase rule3 = CFRuleRecord.create(sheet, ComparisonOperator.GE, "100", null);
header.setNumberOfConditionalFormats(3);
CellRangeAddress[] cellRanges = { new CellRangeAddress(0, 1, 0, 0), new CellRangeAddress(0, 1, 2, 2) };
header.setCellRanges(cellRanges);
recs.add(header);
recs.add(rule1);
recs.add(rule2);
recs.add(rule3);
CFRecordsAggregate record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
// Serialize
byte[] serializedRecord = new byte[record.getRecordSize()];
record.serialize(0, serializedRecord);
InputStream in = new ByteArrayInputStream(serializedRecord);
//Parse
recs = RecordFactory.createRecords(in);
// Verify
assertNotNull(recs);
assertEquals(4, recs.size());
header = (CFHeaderRecord) recs.get(0);
rule1 = (CFRuleRecord) recs.get(1);
assertNotNull(rule1);
rule2 = (CFRuleRecord) recs.get(2);
assertNotNull(rule2);
rule3 = (CFRuleRecord) recs.get(3);
assertNotNull(rule3);
cellRanges = header.getCellRanges();
assertEquals(2, cellRanges.length);
assertEquals(3, header.getNumberOfConditionalFormats());
assertFalse(header.getNeedRecalculation());
record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
record = record.cloneCFAggregate();
assertNotNull(record.getHeader());
assertEquals(3, record.getNumberOfRules());
header = record.getHeader();
rule1 = record.getRule(0);
assertNotNull(rule1);
rule2 = record.getRule(1);
assertNotNull(rule2);
rule3 = record.getRule(2);
assertNotNull(rule3);
cellRanges = header.getCellRanges();
assertEquals(2, cellRanges.length);
assertEquals(3, header.getNumberOfConditionalFormats());
assertFalse(header.getNeedRecalculation());
}
use of org.apache.poi.hssf.usermodel.HSSFSheet in project poi by apache.
the class TestFeatRecord method testWithoutFeatRecord.
public void testWithoutFeatRecord() throws Exception {
HSSFWorkbook hssf = HSSFTestDataSamples.openSampleWorkbook("46136-WithWarnings.xls");
InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
assertEquals(1, hssf.getNumberOfSheets());
int countFR = 0;
int countFRH = 0;
// Check on the workbook, but shouldn't be there!
for (Record r : wb.getRecords()) {
if (r instanceof FeatRecord) {
countFR++;
} else if (r.getSid() == FeatRecord.sid) {
countFR++;
}
if (r instanceof FeatHdrRecord) {
countFRH++;
} else if (r.getSid() == FeatHdrRecord.sid) {
countFRH++;
}
}
assertEquals(0, countFR);
assertEquals(0, countFRH);
// Now check on the sheet
HSSFSheet s = hssf.getSheetAt(0);
InternalSheet sheet = HSSFTestHelper.getSheetForTest(s);
for (RecordBase rb : sheet.getRecords()) {
if (rb instanceof Record) {
Record r = (Record) rb;
if (r instanceof FeatRecord) {
countFR++;
} else if (r.getSid() == FeatRecord.sid) {
countFR++;
}
if (r instanceof FeatHdrRecord) {
countFRH++;
} else if (r.getSid() == FeatHdrRecord.sid) {
countFRH++;
}
}
}
assertEquals(0, countFR);
assertEquals(0, countFRH);
}
Aggregations