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

(-)src/java/org/apache/poi/hssf/model/Sheet.java (-45 lines)
Lines 566-617 Link Here
566
        return numMergedRegions;
566
        return numMergedRegions;
567
    }
567
    }
568
568
569
    /**
570
     * This is basically a kludge to deal with the now obsolete Label records.  If
571
     * you have to read in a sheet that contains Label records, be aware that the rest
572
     * of the API doesn't deal with them, the low level structure only provides read-only
573
     * semi-immutable structures (the sets are there for interface conformance with NO
574
     * impelmentation).  In short, you need to call this function passing it a reference
575
     * to the Workbook object.  All labels will be converted to LabelSST records and their
576
     * contained strings will be written to the Shared String tabel (SSTRecord) within
577
     * the Workbook.
578
     *
579
     * @param wb sheet's matching low level Workbook structure containing the SSTRecord.
580
     * @see org.apache.poi.hssf.record.LabelRecord
581
     * @see org.apache.poi.hssf.record.LabelSSTRecord
582
     * @see org.apache.poi.hssf.record.SSTRecord
583
     */
584
569
585
    public void convertLabelRecords(Workbook wb)
586
    {
587
        if (log.check( POILogger.DEBUG ))
588
            log.log(POILogger.DEBUG, "convertLabelRecords called");
589
        if (containsLabels)
590
        {
591
            for (int k = 0; k < records.size(); k++)
592
            {
593
                Record rec = ( Record ) records.get(k);
594
595
                if (rec.getSid() == LabelRecord.sid)
596
                {
597
                    LabelRecord oldrec = ( LabelRecord ) rec;
598
599
                    records.remove(k);
600
                    LabelSSTRecord newrec   = new LabelSSTRecord();
601
                    int            stringid =
602
                        wb.addSSTString(oldrec.getValue());
603
604
                    newrec.setRow(oldrec.getRow());
605
                    newrec.setColumn(oldrec.getColumn());
606
                    newrec.setXFIndex(oldrec.getXFIndex());
607
                    newrec.setSSTIndex(stringid);
608
                          records.add(k, newrec);
609
                }
610
            }
611
        }
612
        if (log.check( POILogger.DEBUG ))
613
            log.log(POILogger.DEBUG, "convertLabelRecords exit");
614
    }
615
570
616
    /**
571
    /**
617
     * Returns the number of low level binary records in this sheet.  This adjusts things for the so called
572
     * Returns the number of low level binary records in this sheet.  This adjusts things for the so called
(-)src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (-3 / +39 lines)
Lines 167-180 Link Here
167
        setPropertiesFromWorkbook(workbook);
167
        setPropertiesFromWorkbook(workbook);
168
        int recOffset = workbook.getNumRecords();
168
        int recOffset = workbook.getNumRecords();
169
        int sheetNum = 0;
169
        int sheetNum = 0;
170
170
		convertLabelRecords(records);
171
        while (recOffset < records.size())
171
        while (recOffset < records.size())
172
        {
172
        {
173
            Sheet sheet = Sheet.createSheet(records, sheetNum++, recOffset );
173
            Sheet sheet = Sheet.createSheet(records, sheetNum++, recOffset );
174
174
175
            recOffset = sheet.getEofLoc()+1;
175
            recOffset = sheet.getEofLoc()+1;
176
            sheet.convertLabelRecords(
177
                    workbook);   // convert all LabelRecord records to LabelSSTRecord
178
            HSSFSheet hsheet = new HSSFSheet(workbook, sheet);
176
            HSSFSheet hsheet = new HSSFSheet(workbook, sheet);
179
177
180
            sheets.add(hsheet);
178
            sheets.add(hsheet);
Lines 1068-1073 Link Here
1068
        workbook.getRecords().add(loc, r);
1066
        workbook.getRecords().add(loc, r);
1069
    }
1067
    }
1070
1068
1069
	/**
1070
	 * This is basically a kludge to deal with the now obsolete Label records.  If
1071
	 * you have to read in a sheet that contains Label records, be aware that the rest
1072
	 * of the API doesn't deal with them, the low level structure only provides read-only
1073
	 * semi-immutable structures (the sets are there for interface conformance with NO
1074
	 * impelmentation).  In short, you need to call this function passing it a reference
1075
	 * to the Workbook object.  All labels will be converted to LabelSST records and their
1076
	 * contained strings will be written to the Shared String tabel (SSTRecord) within
1077
	 * the Workbook.
1078
	 *
1079
	 * @param wb sheet's matching low level Workbook structure containing the SSTRecord.
1080
	 * @see org.apache.poi.hssf.record.LabelRecord
1081
	 * @see org.apache.poi.hssf.record.LabelSSTRecord
1082
	 * @see org.apache.poi.hssf.record.SSTRecord
1083
	 */
1084
	public void convertLabelRecords(List records)
1085
	{
1086
		if (log.check(POILogger.DEBUG))
1087
			log.log(POILogger.DEBUG, "convertLabelRecords called");
1088
		for (int k = 0; k < records.size(); k++)
1089
		{
1090
			Record rec = (Record) records.get(k);
1091
			if (rec.getSid() == LabelRecord.sid)
1092
			{
1093
				LabelRecord oldrec = (LabelRecord) rec;
1094
				records.remove(k);
1095
				LabelSSTRecord newrec = new LabelSSTRecord();
1096
				int stringid = addSSTString(oldrec.getValue());
1097
				newrec.setRow(oldrec.getRow());
1098
				newrec.setColumn(oldrec.getColumn());
1099
				newrec.setXFIndex(oldrec.getXFIndex());
1100
				newrec.setSSTIndex(stringid);
1101
				records.add(k, newrec);
1102
			}
1103
		}
1104
		if (log.check(POILogger.DEBUG))
1105
			log.log(POILogger.DEBUG, "convertLabelRecords exit");
1106
	}
1071
1107
1072
1108
1073
}
1109
}

Return to bug 19053