📄 hssfchart.java
字号:
/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache POI" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache POI", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package org.apache.poi.hssf.usermodel;import org.apache.poi.hssf.record.*;import org.apache.poi.hssf.record.formula.Area3DPtg;import java.util.ArrayList;import java.util.List;import java.util.Stack;/** * Has methods for construction of a chart object. * * @author Glen Stampoultzis (glens at apache.org) */public class HSSFChart{ /** * Creates a bar chart. API needs some work. :) * <p> * NOTE: Does not yet work... checking it in just so others * can take a look. */ public void createBarChart( HSSFWorkbook workbook, HSSFSheet sheet ) { List records = new ArrayList(); records.add( createMSDrawingObjectRecord() ); records.add( createOBJRecord() ); records.add( createBOFRecord() ); records.add( createHeaderRecord() ); records.add( createFooterRecord() ); records.add( createHCenterRecord() ); records.add( createVCenterRecord() ); records.add( createPrintSetupRecord() ); // unknown 33 records.add( createFontBasisRecord1() ); records.add( createFontBasisRecord2() ); records.add( createProtectRecord() ); records.add( createUnitsRecord() ); records.add( createChartRecord( 0, 0, 30434904, 19031616 ) ); records.add( createBeginRecord() ); records.add( createSCLRecord( (short) 1, (short) 1 ) ); records.add( createPlotGrowthRecord( 65536, 65536 ) ); records.add( createFrameRecord1() ); records.add( createBeginRecord() ); records.add( createLineFormatRecord(true) ); records.add( createAreaFormatRecord1() ); records.add( createEndRecord() ); records.add( createSeriesRecord() ); records.add( createBeginRecord() ); records.add( createTitleLinkedDataRecord() ); records.add( createValuesLinkedDataRecord() ); records.add( createCategoriesLinkedDataRecord() ); records.add( createDataFormatRecord() ); // records.add(createBeginRecord()); // unknown // records.add(createEndRecord()); records.add( createSeriesToChartGroupRecord() ); records.add( createEndRecord() ); records.add( createSheetPropsRecord() ); records.add( createDefaultTextRecord( DefaultDataLabelTextPropertiesRecord.CATEGORY_DATA_TYPE_ALL_TEXT_CHARACTERISTIC ) ); records.add( createAllTextRecord() ); records.add( createBeginRecord() ); // unknown records.add( createFontIndexRecord( 5 ) ); records.add( createDirectLinkRecord() ); records.add( createEndRecord() ); records.add( createDefaultTextRecord( (short) 3 ) ); // eek, undocumented text type records.add( createUnknownTextRecord() ); records.add( createBeginRecord() ); records.add( createFontIndexRecord( (short) 6 ) ); records.add( createDirectLinkRecord() ); records.add( createEndRecord() ); records.add( createAxisUsedRecord( (short) 1 ) ); createAxisRecords( records ); records.add( createEndRecord() ); records.add( createDimensionsRecord() ); records.add( createSeriesIndexRecord(2) ); records.add( createSeriesIndexRecord(1) ); records.add( createSeriesIndexRecord(3) ); records.add( createEOFRecord() ); sheet.insertChartRecords( records ); workbook.insertChartRecord(); } private EOFRecord createEOFRecord() { return new EOFRecord(); } private SeriesIndexRecord createSeriesIndexRecord( int index ) { SeriesIndexRecord r = new SeriesIndexRecord(); r.setIndex((short)index); return r; } private DimensionsRecord createDimensionsRecord() { DimensionsRecord r = new DimensionsRecord(); r.setFirstRow(0); r.setLastRow(31); r.setFirstCol((short)0); r.setLastCol((short)1); return r; } private HCenterRecord createHCenterRecord() { HCenterRecord r = new HCenterRecord(); r.setHCenter(false); return r; } private VCenterRecord createVCenterRecord() { VCenterRecord r = new VCenterRecord(); r.setVCenter(false); return r; } private PrintSetupRecord createPrintSetupRecord() { PrintSetupRecord r = new PrintSetupRecord(); r.setPaperSize((short)0); r.setScale((short)18); r.setPageStart((short)1); r.setFitWidth((short)1); r.setFitHeight((short)1); r.setLeftToRight(false); r.setLandscape(false); r.setValidSettings(true); r.setNoColor(false); r.setDraft(false); r.setNotes(false); r.setNoOrientation(false); r.setUsePage(false); r.setHResolution((short)0); r.setVResolution((short)0); r.setHeaderMargin(0.5); r.setFooterMargin(0.5); r.setCopies((short)15); // what the ?? return r; } private FontBasisRecord createFontBasisRecord1() { FontBasisRecord r = new FontBasisRecord(); r.setXBasis((short)9120); r.setYBasis((short)5640); r.setHeightBasis((short)200); r.setScale((short)0); r.setIndexToFontTable((short)5); return r; } private FontBasisRecord createFontBasisRecord2() { FontBasisRecord r = createFontBasisRecord1(); r.setIndexToFontTable((short)6); return r; } private ProtectRecord createProtectRecord() { ProtectRecord r = new ProtectRecord(); r.setProtect(false); return r; } private FooterRecord createFooterRecord() { FooterRecord r = new FooterRecord(); r.setFooter(null); return r; } private HeaderRecord createHeaderRecord() { HeaderRecord r = new HeaderRecord(); r.setHeader(null); return r; } private BOFRecord createBOFRecord() { BOFRecord r = new BOFRecord(); r.setVersion((short)600); r.setType((short)20); r.setBuild((short)0x1CFE); r.setBuildYear((short)1997); r.setHistoryBitMask(0x40C9); r.setRequiredVersion(106); return r; } private UnknownRecord createOBJRecord() { byte[] data = { (byte) 0x15, (byte) 0x00, (byte) 0x12, (byte) 0x00, (byte) 0x05, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x11, (byte) 0x60, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xB8, (byte) 0x03, (byte) 0x87, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, }; return new UnknownRecord( (short) 0x005D, (short) 0x001a, data ); } private UnknownRecord createMSDrawingObjectRecord() { // Since we haven't created this object yet we'll just put in the raw // form for the moment. byte[] data = { (byte)0x0F, (byte)0x00, (byte)0x02, (byte)0xF0, (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x00, (byte)0x08, (byte)0xF0, (byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x0F, (byte)0x00, (byte)0x03, (byte)0xF0, (byte)0xA8, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0F, (byte)0x00, (byte)0x04, (byte)0xF0, (byte)0x28, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x09, (byte)0xF0, (byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02, (byte)0x00, (byte)0x0A, (byte)0xF0, (byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x05, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0F, (byte)0x00, (byte)0x04, (byte)0xF0, (byte)0x70, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x92, (byte)0x0C, (byte)0x0A, (byte)0xF0, (byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0A, (byte)0x00, (byte)0x00, (byte)0x93, (byte)0x00, (byte)0x0B, (byte)0xF0, (byte)0x36, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x7F, (byte)0x00, (byte)0x04, (byte)0x01, (byte)0x04, (byte)0x01, (byte)0xBF, (byte)0x00, (byte)0x08, (byte)0x00, (byte)0x08, (byte)0x00, (byte)0x81, (byte)0x01, (byte)0x4E, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x83, (byte)0x01, (byte)0x4D, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0xBF, (byte)0x01, (byte)0x10, (byte)0x00, (byte)0x11, (byte)0x00, (byte)0xC0, (byte)0x01, (byte)0x4D, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0xFF, (byte)0x01, (byte)0x08, (byte)0x00, (byte)0x08, (byte)0x00, (byte)0x3F, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x02, (byte)0x00, (byte)0xBF, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0xF0, (byte)0x12, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0xC0, (byte)0x02, (byte)0x0A, (byte)0x00, (byte)0xF4, (byte)0x00, (byte)0x0E, (byte)0x00, (byte)0x66, (byte)0x01, (byte)0x20, (byte)0x00, (byte)0xE9, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x11, (byte)0xF0, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }; return new UnknownRecord((short)0x00EC, (short)0x00C8, data); } private void createAxisRecords( List records ) { records.add( createAxisParentRecord() ); records.add( createBeginRecord() ); records.add( createAxisRecord( AxisRecord.AXIS_TYPE_CATEGORY_OR_X_AXIS ) ); records.add( createBeginRecord() ); records.add( createCategorySeriesAxisRecord() ); records.add( createAxisOptionsRecord() ); records.add( createTickRecord1() ); records.add( createEndRecord() ); records.add( createAxisRecord( AxisRecord.AXIS_TYPE_VALUE_AXIS ) ); records.add( createBeginRecord() ); records.add( createValueRangeRecord() ); records.add( createTickRecord2() ); records.add( createAxisLineFormatRecord( AxisLineFormatRecord.AXIS_TYPE_MAJOR_GRID_LINE ) ); records.add( createLineFormatRecord(false) ); records.add( createEndRecord() ); records.add( createPlotAreaRecord() ); records.add( createFrameRecord2() ); records.add( createBeginRecord() ); records.add( createLineFormatRecord2() ); records.add( createAreaFormatRecord2() ); records.add( createEndRecord() ); records.add( createChartFormatRecord() ); records.add( createBeginRecord() ); records.add( createBarRecord() ); // unknown 1022 records.add( createLegendRecord() ); records.add( createBeginRecord() ); // unknown 104f records.add( createTextRecord() ); records.add( createBeginRecord() ); // unknown 104f records.add( createLinkedDataRecord() ); records.add( createEndRecord() ); records.add( createEndRecord() ); records.add( createEndRecord() ); records.add( createEndRecord() ); } 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( new LinkedDataFormulaField() ); return r; } private TextRecord createTextRecord() { TextRecord r = new TextRecord(); r.setHorizontalAlignment(TextRecord.HORIZONTAL_ALIGNMENT_CENTER); r.setVerticalAlignment(TextRecord.VERTICAL_ALIGNMENT_CENTER); r.setDisplayMode((short)1); r.setRgbColor(0x00000000); r.setX(-37); r.setY(-60); r.setWidth(0); r.setHeight(0); r.setAutoColor(true); r.setShowKey(false); r.setShowValue(false); r.setVertical(false); r.setAutoGeneratedText(true); r.setGenerated(true); r.setAutoLabelDeleted(false); r.setAutoBackground(true); r.setRotation((short)0); r.setShowCategoryLabelAsPercentage(false); r.setShowValueAsPercentage(false); r.setShowBubbleSizes(false); r.setShowLabel(false); r.setIndexOfColorValue((short)77); r.setDataLabelPlacement((short)0); r.setTextRotation((short)0); return r; } private LegendRecord createLegendRecord() { LegendRecord r = new LegendRecord(); r.setXAxisUpperLeft(3542); r.setYAxisUpperLeft(1566); r.setXSize(437); r.setYSize(213); r.setType(LegendRecord.TYPE_RIGHT); r.setSpacing(LegendRecord.SPACING_MEDIUM); r.setAutoPosition(true); r.setAutoSeries(true); r.setAutoXPositioning(true); r.setAutoYPositioning(true); r.setVertical(true); r.setDataTable(false); return r; } private BarRecord createBarRecord() { BarRecord r = new BarRecord(); r.setBarSpace((short)0); r.setCategorySpace((short)150); r.setHorizontal(false); r.setStacked(false); r.setDisplayAsPercentage(false); r.setShadow(false); return r; } private ChartFormatRecord createChartFormatRecord() { ChartFormatRecord r = new ChartFormatRecord(); r.setXPosition(0); r.setYPosition(0); r.setWidth(0); r.setHeight(0); r.setVaryDisplayPattern(false); return r;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -