Search in sources :

Example 1 with ProtectRecord

use of org.apache.poi.hssf.record.ProtectRecord in project poi by apache.

the class WorksheetProtectionBlock method protectSheet.

/**
	 * protect a spreadsheet with a password (not encrypted, just sets protect
	 * flags and the password.
	 *
	 * @param password to set. Pass <code>null</code> to remove all protection
	 * @param shouldProtectObjects are protected
	 * @param shouldProtectScenarios are protected
	 */
public void protectSheet(String password, boolean shouldProtectObjects, boolean shouldProtectScenarios) {
    if (password == null) {
        _passwordRecord = null;
        _protectRecord = null;
        _objectProtectRecord = null;
        _scenarioProtectRecord = null;
        return;
    }
    ProtectRecord prec = getProtect();
    PasswordRecord pass = getPassword();
    prec.setProtect(true);
    pass.setPassword((short) CryptoFunctions.createXorVerifier1(password));
    if (_objectProtectRecord == null && shouldProtectObjects) {
        ObjectProtectRecord rec = createObjectProtect();
        rec.setProtect(true);
        _objectProtectRecord = rec;
    }
    if (_scenarioProtectRecord == null && shouldProtectScenarios) {
        ScenarioProtectRecord srec = createScenarioProtect();
        srec.setProtect(true);
        _scenarioProtectRecord = srec;
    }
}
Also used : ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) ObjectProtectRecord(org.apache.poi.hssf.record.ObjectProtectRecord) ScenarioProtectRecord(org.apache.poi.hssf.record.ScenarioProtectRecord) ScenarioProtectRecord(org.apache.poi.hssf.record.ScenarioProtectRecord) PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) ObjectProtectRecord(org.apache.poi.hssf.record.ObjectProtectRecord)

Example 2 with ProtectRecord

use of org.apache.poi.hssf.record.ProtectRecord in project poi by apache.

the class HSSFChart method createBarChart.

/**
	 * 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 parentSheet) {
    List<Record> records = new ArrayList<Record>();
    records.add(createMSDrawingObjectRecord());
    records.add(createOBJRecord());
    records.add(createBOFRecord());
    records.add(new HeaderRecord(""));
    records.add(new FooterRecord(""));
    records.add(createHCenterRecord());
    records.add(createVCenterRecord());
    records.add(createPrintSetupRecord());
    // unknown 33
    records.add(createFontBasisRecord1());
    records.add(createFontBasisRecord2());
    records.add(new ProtectRecord(false));
    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());
    // eek, undocumented text type
    records.add(createDefaultTextRecord((short) 3));
    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(EOFRecord.instance);
    parentSheet.insertChartRecords(records);
    workbook.insertChartRecord();
}
Also used : ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) FooterRecord(org.apache.poi.hssf.record.FooterRecord) HeaderRecord(org.apache.poi.hssf.record.HeaderRecord) ArrayList(java.util.ArrayList) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) VCenterRecord(org.apache.poi.hssf.record.VCenterRecord) AxisUsedRecord(org.apache.poi.hssf.record.chart.AxisUsedRecord) LinkedDataRecord(org.apache.poi.hssf.record.chart.LinkedDataRecord) FooterRecord(org.apache.poi.hssf.record.FooterRecord) SCLRecord(org.apache.poi.hssf.record.SCLRecord) ChartRecord(org.apache.poi.hssf.record.chart.ChartRecord) ValueRangeRecord(org.apache.poi.hssf.record.chart.ValueRangeRecord) LegendRecord(org.apache.poi.hssf.record.chart.LegendRecord) SeriesTextRecord(org.apache.poi.hssf.record.chart.SeriesTextRecord) AxisParentRecord(org.apache.poi.hssf.record.chart.AxisParentRecord) DefaultDataLabelTextPropertiesRecord(org.apache.poi.hssf.record.chart.DefaultDataLabelTextPropertiesRecord) PrintSetupRecord(org.apache.poi.hssf.record.PrintSetupRecord) Record(org.apache.poi.hssf.record.Record) SeriesToChartGroupRecord(org.apache.poi.hssf.record.chart.SeriesToChartGroupRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) AreaFormatRecord(org.apache.poi.hssf.record.chart.AreaFormatRecord) BeginRecord(org.apache.poi.hssf.record.chart.BeginRecord) HCenterRecord(org.apache.poi.hssf.record.HCenterRecord) EndRecord(org.apache.poi.hssf.record.chart.EndRecord) PlotGrowthRecord(org.apache.poi.hssf.record.chart.PlotGrowthRecord) UnitsRecord(org.apache.poi.hssf.record.chart.UnitsRecord) HeaderRecord(org.apache.poi.hssf.record.HeaderRecord) SeriesRecord(org.apache.poi.hssf.record.chart.SeriesRecord) BarRecord(org.apache.poi.hssf.record.chart.BarRecord) ChartFormatRecord(org.apache.poi.hssf.record.chart.ChartFormatRecord) AxisLineFormatRecord(org.apache.poi.hssf.record.chart.AxisLineFormatRecord) CategorySeriesAxisRecord(org.apache.poi.hssf.record.chart.CategorySeriesAxisRecord) ChartTitleFormatRecord(org.apache.poi.hssf.record.chart.ChartTitleFormatRecord) FrameRecord(org.apache.poi.hssf.record.chart.FrameRecord) PlotAreaRecord(org.apache.poi.hssf.record.chart.PlotAreaRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) DataFormatRecord(org.apache.poi.hssf.record.chart.DataFormatRecord) ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) TextRecord(org.apache.poi.hssf.record.chart.TextRecord) FontBasisRecord(org.apache.poi.hssf.record.chart.FontBasisRecord) AxisOptionsRecord(org.apache.poi.hssf.record.chart.AxisOptionsRecord) SeriesIndexRecord(org.apache.poi.hssf.record.chart.SeriesIndexRecord) SheetPropertiesRecord(org.apache.poi.hssf.record.chart.SheetPropertiesRecord) TickRecord(org.apache.poi.hssf.record.chart.TickRecord) AxisRecord(org.apache.poi.hssf.record.chart.AxisRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) FontIndexRecord(org.apache.poi.hssf.record.chart.FontIndexRecord) LineFormatRecord(org.apache.poi.hssf.record.chart.LineFormatRecord)

Aggregations

ProtectRecord (org.apache.poi.hssf.record.ProtectRecord)2 ArrayList (java.util.ArrayList)1 BOFRecord (org.apache.poi.hssf.record.BOFRecord)1 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)1 EOFRecord (org.apache.poi.hssf.record.EOFRecord)1 FooterRecord (org.apache.poi.hssf.record.FooterRecord)1 HCenterRecord (org.apache.poi.hssf.record.HCenterRecord)1 HeaderRecord (org.apache.poi.hssf.record.HeaderRecord)1 ObjectProtectRecord (org.apache.poi.hssf.record.ObjectProtectRecord)1 PasswordRecord (org.apache.poi.hssf.record.PasswordRecord)1 PrintSetupRecord (org.apache.poi.hssf.record.PrintSetupRecord)1 Record (org.apache.poi.hssf.record.Record)1 SCLRecord (org.apache.poi.hssf.record.SCLRecord)1 ScenarioProtectRecord (org.apache.poi.hssf.record.ScenarioProtectRecord)1 UnknownRecord (org.apache.poi.hssf.record.UnknownRecord)1 VCenterRecord (org.apache.poi.hssf.record.VCenterRecord)1 AreaFormatRecord (org.apache.poi.hssf.record.chart.AreaFormatRecord)1 AxisLineFormatRecord (org.apache.poi.hssf.record.chart.AxisLineFormatRecord)1 AxisOptionsRecord (org.apache.poi.hssf.record.chart.AxisOptionsRecord)1 AxisParentRecord (org.apache.poi.hssf.record.chart.AxisParentRecord)1