use of org.apache.poi.hssf.model.InternalWorkbook in project poi by apache.
the class TestHSSFWorkbook method clonePictures.
@Test
public void clonePictures() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithImages.xls");
InternalWorkbook iwb = wb.getWorkbook();
iwb.findDrawingGroup();
for (int pictureIndex = 1; pictureIndex <= 4; pictureIndex++) {
EscherBSERecord bse = iwb.getBSERecord(pictureIndex);
assertEquals(1, bse.getRef());
}
wb.cloneSheet(0);
for (int pictureIndex = 1; pictureIndex <= 4; pictureIndex++) {
EscherBSERecord bse = iwb.getBSERecord(pictureIndex);
assertEquals(2, bse.getRef());
}
wb.cloneSheet(0);
for (int pictureIndex = 1; pictureIndex <= 4; pictureIndex++) {
EscherBSERecord bse = iwb.getBSERecord(pictureIndex);
assertEquals(3, bse.getRef());
}
wb.close();
}
use of org.apache.poi.hssf.model.InternalWorkbook in project poi by apache.
the class BiffDrawingToXml method writeToFile.
public static void writeToFile(OutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook(xlsWorkbook);
InternalWorkbook internalWorkbook = workbook.getInternalWorkbook();
DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid);
StringBuilder builder = new StringBuilder();
builder.append("<workbook>\n");
String tab = "\t";
if (!excludeWorkbookRecords && r != null) {
r.decode();
List<EscherRecord> escherRecords = r.getEscherRecords();
for (EscherRecord record : escherRecords) {
builder.append(record.toXml(tab));
}
}
List<Integer> sheets = getSheetsIndexes(params, workbook);
for (Integer i : sheets) {
HSSFPatriarch p = workbook.getSheetAt(i).getDrawingPatriarch();
if (p != null) {
builder.append(tab).append("<sheet").append(i).append(">\n");
builder.append(p.getBoundAggregate().toXml(tab + "\t"));
builder.append(tab).append("</sheet").append(i).append(">\n");
}
}
builder.append("</workbook>\n");
fos.write(builder.toString().getBytes(StringUtil.UTF8));
fos.close();
workbook.close();
}
use of org.apache.poi.hssf.model.InternalWorkbook in project poi by apache.
the class TestFeatRecord method testReadFeatRecord.
public void testReadFeatRecord() throws Exception {
HSSFWorkbook hssf = HSSFTestDataSamples.openSampleWorkbook("46136-NoWarnings.xls");
InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
FeatRecord fr = null;
FeatHdrRecord fhr = null;
assertEquals(1, hssf.getNumberOfSheets());
// First check it isn't on the Workbook
int countFR = 0;
int countFRH = 0;
for (Record r : wb.getRecords()) {
if (r instanceof FeatRecord) {
fr = (FeatRecord) r;
countFR++;
} else if (r.getSid() == FeatRecord.sid) {
fail("FeatRecord SID found but not created correctly!");
}
if (r instanceof FeatHdrRecord) {
countFRH++;
} else if (r.getSid() == FeatHdrRecord.sid) {
fail("FeatHdrRecord SID found but not created correctly!");
}
}
assertEquals(0, countFR);
assertEquals(0, countFRH);
// Now find it on our 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) {
fr = (FeatRecord) r;
countFR++;
} else if (r.getSid() == FeatRecord.sid) {
countFR++;
}
if (r instanceof FeatHdrRecord) {
fhr = (FeatHdrRecord) r;
countFRH++;
} else if (r.getSid() == FeatHdrRecord.sid) {
countFRH++;
}
}
}
assertEquals(1, countFR);
assertEquals(1, countFRH);
assertNotNull(fr);
assertNotNull(fhr);
// Now check the contents are as expected
assertEquals(FeatHdrRecord.SHAREDFEATURES_ISFFEC2, fr.getIsf_sharedFeatureType());
// Applies to one cell only
assertEquals(1, fr.getCellRefs().length);
assertEquals(0, fr.getCellRefs()[0].getFirstRow());
assertEquals(0, fr.getCellRefs()[0].getLastRow());
assertEquals(0, fr.getCellRefs()[0].getFirstColumn());
assertEquals(0, fr.getCellRefs()[0].getLastColumn());
// More checking of shared features stuff
assertEquals(4, fr.getCbFeatData());
assertEquals(4, fr.getSharedFeature().getDataSize());
assertEquals(FeatFormulaErr2.class, fr.getSharedFeature().getClass());
FeatFormulaErr2 fferr2 = (FeatFormulaErr2) fr.getSharedFeature();
assertEquals(0x04, fferr2._getRawErrorCheckValue());
assertFalse(fferr2.getCheckCalculationErrors());
assertFalse(fferr2.getCheckDateTimeFormats());
assertFalse(fferr2.getCheckEmptyCellRef());
assertFalse(fferr2.getCheckInconsistentFormulas());
assertFalse(fferr2.getCheckInconsistentRanges());
assertTrue(fferr2.getCheckNumbersAsText());
assertFalse(fferr2.getCheckUnprotectedFormulas());
assertFalse(fferr2.getPerformDataValidation());
}
use of org.apache.poi.hssf.model.InternalWorkbook in project poi by apache.
the class HSSFSheet method setAutoFilter.
@Override
public HSSFAutoFilter setAutoFilter(CellRangeAddress range) {
InternalWorkbook workbook = _workbook.getWorkbook();
int sheetIndex = _workbook.getSheetIndex(this);
NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, sheetIndex + 1);
if (name == null) {
name = workbook.createBuiltInName(NameRecord.BUILTIN_FILTER_DB, sheetIndex + 1);
}
int firstRow = range.getFirstRow();
// if row was not given when constructing the range...
if (firstRow == -1) {
firstRow = 0;
}
// The built-in name must consist of a single Area3d Ptg.
Area3DPtg ptg = new Area3DPtg(firstRow, range.getLastRow(), range.getFirstColumn(), range.getLastColumn(), false, false, false, false, sheetIndex);
name.setNameDefinition(new Ptg[] { ptg });
AutoFilterInfoRecord r = new AutoFilterInfoRecord();
// the number of columns that have AutoFilter enabled.
int numcols = 1 + range.getLastColumn() - range.getFirstColumn();
r.setNumEntries((short) numcols);
int idx = _sheet.findFirstRecordLocBySid(DimensionsRecord.sid);
_sheet.getRecords().add(idx, r);
//create a combobox control for each column
HSSFPatriarch p = createDrawingPatriarch();
final int firstColumn = range.getFirstColumn();
final int lastColumn = range.getLastColumn();
for (int col = firstColumn; col <= lastColumn; col++) {
p.createComboBox(new HSSFClientAnchor(0, 0, 0, 0, (short) col, firstRow, (short) (col + 1), firstRow + 1));
}
return new HSSFAutoFilter(this);
}
use of org.apache.poi.hssf.model.InternalWorkbook in project poi by apache.
the class TestEventWorkbookBuilder method testContents.
public void testContents() {
assertEquals(2, listener.getSSTRecord().getNumStrings());
assertEquals(3, listener.getBoundSheetRecords().length);
assertEquals(1, listener.getExternSheetRecords().length);
assertEquals(3, listener.getStubWorkbook().getNumSheets());
InternalWorkbook ref = listener.getStubWorkbook();
assertEquals("Sh3", ref.findSheetFirstNameFromExternSheet(0));
assertEquals("Sheet1", ref.findSheetFirstNameFromExternSheet(1));
assertEquals("S2", ref.findSheetFirstNameFromExternSheet(2));
}
Aggregations