use of org.apache.poi.hssf.record.chart.LinkedDataRecord in project poi by apache.
the class HSSFChart method createValuesLinkedDataRecord.
private LinkedDataRecord createValuesLinkedDataRecord() {
LinkedDataRecord r = new LinkedDataRecord();
r.setLinkType(LinkedDataRecord.LINK_TYPE_VALUES);
r.setReferenceType(LinkedDataRecord.REFERENCE_TYPE_WORKSHEET);
r.setCustomNumberFormat(false);
r.setIndexNumberFmtRecord((short) 0);
Area3DPtg p = new Area3DPtg(0, 31, 0, 0, false, false, false, false, 0);
r.setFormulaOfLink(new Ptg[] { p });
return r;
}
use of org.apache.poi.hssf.record.chart.LinkedDataRecord in project poi by apache.
the class HSSFChart method createTitleLinkedDataRecord.
private LinkedDataRecord createTitleLinkedDataRecord() {
LinkedDataRecord r = new LinkedDataRecord();
r.setLinkType(LinkedDataRecord.LINK_TYPE_TITLE_OR_TEXT);
r.setReferenceType(LinkedDataRecord.REFERENCE_TYPE_DIRECT);
r.setCustomNumberFormat(false);
r.setIndexNumberFmtRecord((short) 0);
r.setFormulaOfLink(null);
return r;
}
use of org.apache.poi.hssf.record.chart.LinkedDataRecord in project poi by apache.
the class HSSFChart method createLinkedDataRecord.
private LinkedDataRecord createLinkedDataRecord() {
LinkedDataRecord r = new LinkedDataRecord();
r.setLinkType(LinkedDataRecord.LINK_TYPE_TITLE_OR_TEXT);
r.setReferenceType(LinkedDataRecord.REFERENCE_TYPE_DIRECT);
r.setCustomNumberFormat(false);
r.setIndexNumberFmtRecord((short) 0);
r.setFormulaOfLink(null);
return r;
}
use of org.apache.poi.hssf.record.chart.LinkedDataRecord in project poi by apache.
the class HSSFChart method createCategoriesLinkedDataRecord.
private LinkedDataRecord createCategoriesLinkedDataRecord() {
LinkedDataRecord r = new LinkedDataRecord();
r.setLinkType(LinkedDataRecord.LINK_TYPE_CATEGORIES);
r.setReferenceType(LinkedDataRecord.REFERENCE_TYPE_WORKSHEET);
r.setCustomNumberFormat(false);
r.setIndexNumberFmtRecord((short) 0);
Area3DPtg p = new Area3DPtg(0, 31, 1, 1, false, false, false, false, 0);
r.setFormulaOfLink(new Ptg[] { p });
return r;
}
use of org.apache.poi.hssf.record.chart.LinkedDataRecord in project poi by apache.
the class HSSFChart method createSeries.
public HSSFSeries createSeries() throws Exception {
ArrayList<RecordBase> seriesTemplate = new ArrayList<RecordBase>();
boolean seriesTemplateFilled = false;
int idx = 0;
int deep = 0;
int chartRecordIdx = -1;
int chartDeep = -1;
int lastSeriesDeep = -1;
int endSeriesRecordIdx = -1;
int seriesIdx = 0;
final List<RecordBase> records = sheet.getSheet().getRecords();
/* store first series as template and find last series index */
for (final RecordBase record : records) {
idx++;
if (record instanceof BeginRecord) {
deep++;
} else if (record instanceof EndRecord) {
deep--;
if (lastSeriesDeep == deep) {
lastSeriesDeep = -1;
endSeriesRecordIdx = idx;
if (!seriesTemplateFilled) {
seriesTemplate.add(record);
seriesTemplateFilled = true;
}
}
if (chartDeep == deep) {
break;
}
}
if (record instanceof ChartRecord) {
if (record == chartRecord) {
chartRecordIdx = idx;
chartDeep = deep;
}
} else if (record instanceof SeriesRecord) {
if (chartRecordIdx != -1) {
seriesIdx++;
lastSeriesDeep = deep;
}
}
if (lastSeriesDeep != -1 && !seriesTemplateFilled) {
seriesTemplate.add(record);
}
}
/* check if a series was found */
if (endSeriesRecordIdx == -1) {
return null;
}
/* next index in the records list where the new series can be inserted */
idx = endSeriesRecordIdx + 1;
HSSFSeries newSeries = null;
/* duplicate record of the template series */
ArrayList<RecordBase> clonedRecords = new ArrayList<RecordBase>();
for (final RecordBase record : seriesTemplate) {
Record newRecord = null;
if (record instanceof BeginRecord) {
newRecord = new BeginRecord();
} else if (record instanceof EndRecord) {
newRecord = new EndRecord();
} else if (record instanceof SeriesRecord) {
SeriesRecord seriesRecord = (SeriesRecord) ((SeriesRecord) record).clone();
newSeries = new HSSFSeries(seriesRecord);
newRecord = seriesRecord;
} else if (record instanceof LinkedDataRecord) {
LinkedDataRecord linkedDataRecord = ((LinkedDataRecord) record).clone();
if (newSeries != null) {
newSeries.insertData(linkedDataRecord);
}
newRecord = linkedDataRecord;
} else if (record instanceof DataFormatRecord) {
DataFormatRecord dataFormatRecord = ((DataFormatRecord) record).clone();
dataFormatRecord.setSeriesIndex((short) seriesIdx);
dataFormatRecord.setSeriesNumber((short) seriesIdx);
newRecord = dataFormatRecord;
} else if (record instanceof SeriesTextRecord) {
SeriesTextRecord seriesTextRecord = (SeriesTextRecord) ((SeriesTextRecord) record).clone();
if (newSeries != null) {
newSeries.setSeriesTitleText(seriesTextRecord);
}
newRecord = seriesTextRecord;
} else if (record instanceof Record) {
newRecord = (Record) ((Record) record).clone();
}
if (newRecord != null) {
clonedRecords.add(newRecord);
}
}
/* check if a user model series object was created */
if (newSeries == null) {
return null;
}
/* transfer series to record list */
for (final RecordBase record : clonedRecords) {
records.add(idx++, record);
}
return newSeries;
}
Aggregations