use of org.apache.poi.hssf.record.TabIdRecord in project poi by apache.
the class InternalWorkbook method fixTabIdRecord.
/**
* make the tabid record look like the current situation.
*/
private void fixTabIdRecord() {
Record rec = records.get(records.getTabpos());
// we use the same check on Tabpos as done in other places
if (records.getTabpos() <= 0) {
return;
}
TabIdRecord tir = (TabIdRecord) rec;
short[] tia = new short[boundsheets.size()];
for (short k = 0; k < tia.length; k++) {
tia[k] = k;
}
tir.setTabIdArray(tia);
}
use of org.apache.poi.hssf.record.TabIdRecord in project poi by apache.
the class TestBugs method bug46664.
/**
* Newly created sheets need to get a
* proper TabID, otherwise print setup
* gets confused on them.
* Also ensure that print setup refs are
* by reference not value
*/
@Test
public void bug46664() throws Exception {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet sheet = wb1.createSheet("new_sheet");
HSSFRow row = sheet.createRow((short) 0);
row.createCell(0).setCellValue(new HSSFRichTextString("Column A"));
row.createCell(1).setCellValue(new HSSFRichTextString("Column B"));
row.createCell(2).setCellValue(new HSSFRichTextString("Column C"));
row.createCell(3).setCellValue(new HSSFRichTextString("Column D"));
row.createCell(4).setCellValue(new HSSFRichTextString("Column E"));
row.createCell(5).setCellValue(new HSSFRichTextString("Column F"));
//set print area from column a to column c (on first row)
wb1.setPrintArea(//sheet index
0, //start column
0, //end column
2, //start row
0, //end row
0);
HSSFWorkbook wb2 = writeOutAndReadBack(wb1);
wb1.close();
// Ensure the tab index
TabIdRecord tr = null;
for (Record r : wb2.getWorkbook().getRecords()) {
if (r instanceof TabIdRecord) {
tr = (TabIdRecord) r;
}
}
assertNotNull(tr);
assertEquals(1, tr._tabids.length);
assertEquals(0, tr._tabids[0]);
// Ensure the print setup
assertEquals("new_sheet!$A$1:$C$1", wb2.getPrintArea(0));
HSSFName printArea = wb2.getName("Print_Area");
assertNotNull(printArea);
assertEquals("new_sheet!$A$1:$C$1", printArea.getRefersToFormula());
// Needs reference not value
NameRecord nr = wb2.getWorkbook().getNameRecord(wb2.getNameIndex("Print_Area"));
assertEquals("Print_Area", nr.getNameText());
assertEquals(1, nr.getNameDefinition().length);
assertEquals("new_sheet!$A$1:$C$1", ((Area3DPtg) nr.getNameDefinition()[0]).toFormulaString(HSSFEvaluationWorkbook.create(wb2)));
assertEquals('R', nr.getNameDefinition()[0].getRVAType());
wb2.close();
}
Aggregations