Esempio n. 1
0
	/**
	 * Returns all the charts for the given sheet.
	 *
	 * NOTE: You won't be able to do very much with
	 *  these charts yet, as this is very limited support
	 */
	public static HSSFChart[] GetSheetCharts(HSSFSheet sheet) {
		List<HSSFChart> charts = new List<HSSFChart>();
		HSSFChart lastChart = null;
		HSSFSeries lastSeries = null;
		// Find records of interest
		List<RecordBase> records = sheet.GetSheet().GetRecords();
		foreach(RecordBase r in records) {

			if(r is ChartRecord) {
				lastSeries = null;
				
				lastChart = new HSSFChart(sheet,(ChartRecord)r);
				charts.Add(lastChart);
			} else if(r is LegendRecord) {
				lastChart.legendRecord = (LegendRecord)r;
			} else if(r is SeriesRecord) {
				HSSFSeries series = lastChart.new HSSFSeries( (SeriesRecord)r );
				lastChart.series.Add(series);
				lastSeries = series;
			} else if(r is ChartTitleFormatRecord) {
				lastChart.chartTitleFormat =
					(ChartTitleFormatRecord)r;
			} else if(r is SeriesTextRecord) {
				// Applies to a series, unless we've seen
				//  a legend already
				SeriesTextRecord str = (SeriesTextRecord)r;
				if(lastChart.legendRecord == null &&
						lastChart.series.Size() > 0) {
					HSSFSeries series = (HSSFSeries)
						lastChart.series.Get(lastChart.series.Size()-1);
					series.seriesTitleText = str;
				} else {
					lastChart.chartTitleText = str;
				}
			} else if (r is LinkedDataRecord) {
				LinkedDataRecord linkedDataRecord = (LinkedDataRecord) r;
				if (lastSeries != null) {
					lastSeries.InsertData(linkedDataRecord);
				}
			} else if(r is ValueRangeRecord){
				lastChart.valueRanges.Add((ValueRangeRecord)r);
			} else if (r is Record) {
				if (lastChart != null)
				{
					Record record = (Record) r;
					for (HSSFChartType type : HSSFChartType.Values()) {
						if (type == HSSFChartType.Unknown)
						{
							continue;
						}
						if (record.GetSid() == type.GetSid()) {
							lastChart.type = type ;
							break;
						}
					}
				}
			}
		}

		return (HSSFChart[])
			charts.ToArray( new HSSFChart[charts.Size()] );
	}