View | Details | Raw Unified | Return to bug 51171
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/model/WorkbookRecordList.java (-1 / +17 lines)
Lines 22-30 Link Here
22
import java.util.List;
22
import java.util.List;
23
23
24
import org.apache.poi.hssf.record.Record;
24
import org.apache.poi.hssf.record.Record;
25
import org.apache.poi.hssf.record.StyleRecord;
25
26
26
public final class WorkbookRecordList implements Iterable<Record> {
27
public final class WorkbookRecordList implements Iterable<Record> {
27
    private List<Record> records = new ArrayList<Record>();
28
    private List<Record> records = new ArrayList<Record>();
29
    private List<StyleRecord> styleRecords = new ArrayList<StyleRecord>();
28
30
29
	private int  protpos	 = 0;   // holds the position of the protect record.
31
	private int  protpos	 = 0;   // holds the position of the protect record.
30
	private int  bspos	   = 0;   // holds the position of the last bound sheet.
32
	private int  bspos	   = 0;   // holds the position of the last bound sheet.
Lines 40-47 Link Here
40
42
41
	public void setRecords(List<Record> records) {
43
	public void setRecords(List<Record> records) {
42
		this.records = records;
44
		this.records = records;
45
        styleRecords.clear();
46
        for(Record r: records) {
47
            if(r instanceof StyleRecord) {
48
                styleRecords.add((StyleRecord)r);
49
            }
50
        }
43
	}
51
	}
44
52
53
    public List<StyleRecord> getStyleRecords() {
54
        return styleRecords;
55
    }
56
45
	public int size() {
57
	public int size() {
46
		return records.size();
58
		return records.size();
47
	}
59
	}
Lines 52-57 Link Here
52
64
53
	public void add(int pos, Record r) {
65
	public void add(int pos, Record r) {
54
		records.add(pos, r);
66
		records.add(pos, r);
67
        if(r instanceof StyleRecord) {
68
            styleRecords.add((StyleRecord)r);
69
        }
55
		if (getProtpos() >= pos) setProtpos( protpos + 1 );
70
		if (getProtpos() >= pos) setProtpos( protpos + 1 );
56
		if (getBspos() >= pos) setBspos( bspos + 1 );
71
		if (getBspos() >= pos) setBspos( bspos + 1 );
57
		if (getTabpos() >= pos) setTabpos( tabpos + 1 );
72
		if (getTabpos() >= pos) setTabpos( tabpos + 1 );
Lines 79-85 Link Here
79
94
80
	public void remove( int pos )
95
	public void remove( int pos )
81
	{
96
	{
82
		records.remove(pos);
97
		Record r = records.remove(pos);
98
        styleRecords.remove(r);
83
		if (getProtpos() >= pos) setProtpos( protpos - 1 );
99
		if (getProtpos() >= pos) setProtpos( protpos - 1 );
84
		if (getBspos() >= pos) setBspos( bspos - 1 );
100
		if (getBspos() >= pos) setBspos( bspos - 1 );
85
		if (getTabpos() >= pos) setTabpos( tabpos - 1 );
101
		if (getTabpos() >= pos) setTabpos( tabpos - 1 );
(-)src/java/org/apache/poi/hssf/model/InternalWorkbook.java (-9 / +1 lines)
Lines 867-881 Link Here
867
    public StyleRecord getStyleRecord(int xfIndex) {
867
    public StyleRecord getStyleRecord(int xfIndex) {
868
        // Style records always follow after
868
        // Style records always follow after
869
        //  the ExtendedFormat records
869
        //  the ExtendedFormat records
870
        for(int i=records.getXfpos(); i<records.size(); i++) {
870
        for(StyleRecord sr: records.getStyleRecords()) {
871
            Record r = records.get(i);
872
            if(r instanceof ExtendedFormatRecord) {
873
                continue;
874
            }
875
            if(!(r instanceof StyleRecord)) {
876
                continue;
877
            }
878
            StyleRecord sr = (StyleRecord)r;
879
            if(sr.getXFIndex() == xfIndex) {
871
            if(sr.getXFIndex() == xfIndex) {
880
                return sr;
872
                return sr;
881
            }
873
            }

Return to bug 51171