Logo Search packages:      
Sourcecode: jexcelapi version File versions  Download package

void jxl::write::biff::WritableWorkbookImpl::write (  )  throws IOException [inline, virtual]

Writes out this sheet to the output file. First it writes out the standard workbook information required by excel, before calling the write method on each sheet individually

Exceptions:
IOException 

Implements jxl::write::WritableWorkbook.

Definition at line 631 of file WritableWorkbookImpl.java.

References addInFunctionNames, addNameArea(), buttonPropertySet, jxl::write::biff::WritableSheetImpl::checkMergedBorders(), containsMacros, countryRecord, drawingGroup, externSheet, fonts, formatRecords, jxl::Range::getBottomRight(), jxl::Cell::getColumn(), jxl::biff::CountryCode::getCountryCode(), jxl::WorkbookSettings::getExcel9File(), jxl::WorkbookSettings::getExcelDisplayLanguage(), jxl::WorkbookSettings::getExcelRegionalSettings(), jxl::WorkbookSettings::getHideobj(), jxl::Sheet::getName(), getNumberOfSheets(), jxl::biff::FormattingRecords::getPalette(), jxl::write::biff::File::getPos(), jxl::SheetSettings::getPrintArea(), jxl::SheetSettings::getPrintTitlesCol(), jxl::SheetSettings::getPrintTitlesRow(), jxl::WorkbookSettings::getRationalizationDisabled(), jxl::WorkbookSettings::getRefreshAll(), jxl::Cell::getRow(), jxl::Sheet::getSettings(), jxl::write::biff::WritableSheetImpl::getSettings(), getSheet(), jxl::WorkbookSettings::getTemplate(), jxl::Range::getTopLeft(), jxl::WorkbookSettings::getWindowProtected(), jxl::WorkbookSettings::getWriteAccess(), jxl::SheetSettings::isHidden(), jxl::SheetSettings::isSelected(), logger, names, outputFile, rationalize(), jxl::write::biff::BoundsheetRecord::setChartOnly(), jxl::write::biff::File::setData(), jxl::write::biff::BoundsheetRecord::setHidden(), jxl::SheetSettings::setSelected(), settings, sharedStrings, sheets, supbooks, jxl::biff::CountryCode::UK, jxl::biff::CountryCode::UNKNOWN, jxl::biff::CountryCode::USA, jxl::common::Logger::warn(), wbProtected, jxl::write::biff::WritableSheetImpl::write(), jxl::write::biff::SharedStrings::write(), jxl::biff::drawing::DrawingGroup::write(), jxl::biff::FormattingRecords::write(), jxl::biff::Fonts::write(), jxl::write::biff::File::write(), and xctRecords.

  {
    // Perform some preliminary sheet check before we start writing out
    // the workbook
    WritableSheetImpl wsi = null;
    for (int i = 0; i < getNumberOfSheets(); i++)
    {
      wsi = (WritableSheetImpl) getSheet(i);

      // Check the merged records.  This has to be done before the
      // globals are written out because some more XF formats might be created
      wsi.checkMergedBorders();

      // Check to see if there are any predefined names
      Range range = wsi.getSettings().getPrintArea();
      if (range != null)
      {
        addNameArea(BuiltInName.PRINT_AREA,
                    wsi,
                    range.getTopLeft().getColumn(),
                    range.getTopLeft().getRow(),
                    range.getBottomRight().getColumn(),
                    range.getBottomRight().getRow(),
                    false);
      }
      
      // Check to see if print titles by row were set
      Range rangeR = wsi.getSettings().getPrintTitlesRow();
      Range rangeC = wsi.getSettings().getPrintTitlesCol();      
      if (rangeR != null && rangeC != null)
      {
        addNameArea(BuiltInName.PRINT_TITLES, 
                    wsi,
                    rangeR.getTopLeft().getColumn(),
                    rangeR.getTopLeft().getRow(),
                    rangeR.getBottomRight().getColumn(),
                    rangeR.getBottomRight().getRow(),
                    rangeC.getTopLeft().getColumn(),
                    rangeC.getTopLeft().getRow(),
                    rangeC.getBottomRight().getColumn(),
                    rangeC.getBottomRight().getRow(),
                    false);  
      }
      // Check to see if print titles by row were set
      else if (rangeR != null)
      {
        addNameArea(BuiltInName.PRINT_TITLES, 
                    wsi,
                    rangeR.getTopLeft().getColumn(),
                    rangeR.getTopLeft().getRow(),
                    rangeR.getBottomRight().getColumn(),
                    rangeR.getBottomRight().getRow(),
                    false);
      }
      // Check to see if print titles by column were set 
      else if (rangeC != null)
      {
        addNameArea(BuiltInName.PRINT_TITLES, 
                    wsi,
                    rangeC.getTopLeft().getColumn(),
                    rangeC.getTopLeft().getRow(),
                    rangeC.getBottomRight().getColumn(),
                    rangeC.getBottomRight().getRow(), 
                    false);
      }
    }
    
    // Rationalize all the XF and number formats
    if (!settings.getRationalizationDisabled())
    {
      rationalize();
    }

    // Write the workbook globals
    BOFRecord bof = new BOFRecord(BOFRecord.workbookGlobals);
    outputFile.write(bof);

    // Must immediatly follow the BOF record
    if (settings.getTemplate())
    {
      // Only write record if we are a template
      TemplateRecord trec= new TemplateRecord();
      outputFile.write(trec);
    }


    InterfaceHeaderRecord ihr = new InterfaceHeaderRecord();
    outputFile.write(ihr);

    MMSRecord mms = new MMSRecord(0,0);
    outputFile.write(mms);

    InterfaceEndRecord ier = new InterfaceEndRecord();
    outputFile.write(ier);

    WriteAccessRecord wr = new WriteAccessRecord(settings.getWriteAccess());
    outputFile.write(wr);

    CodepageRecord cp = new CodepageRecord();
    outputFile.write(cp);

    DSFRecord dsf = new DSFRecord();
    outputFile.write(dsf);

    if (settings.getExcel9File())
    {
      // Only write record if we are a template
      // We are not excel 2000, should we still set the flag
      Excel9FileRecord e9rec= new Excel9FileRecord();
      outputFile.write(e9rec);
    }

    TabIdRecord tabid = new TabIdRecord(getNumberOfSheets());
    outputFile.write(tabid);

    if (containsMacros)
    {
      ObjProjRecord objproj = new ObjProjRecord();
      outputFile.write(objproj);
    }

    if (buttonPropertySet != null)
    {
      outputFile.write(buttonPropertySet);
    }

    FunctionGroupCountRecord fgcr = new FunctionGroupCountRecord();
    outputFile.write(fgcr);

    // do not support password protected workbooks
    WindowProtectRecord wpr = new WindowProtectRecord
      (settings.getWindowProtected());
    outputFile.write(wpr);

    ProtectRecord pr = new ProtectRecord(wbProtected);
    outputFile.write(pr);

    PasswordRecord pw = new PasswordRecord(null);
    outputFile.write(pw);

    Prot4RevRecord p4r = new Prot4RevRecord(false);
    outputFile.write(p4r);

    Prot4RevPassRecord p4rp = new Prot4RevPassRecord();
    outputFile.write(p4rp);

    // If no sheet is identified as being selected, then select
    // the first one
    boolean sheetSelected = false;
    WritableSheetImpl wsheet = null;
    int selectedSheetIndex = 0;
    for (int i = 0 ; i < getNumberOfSheets() && !sheetSelected ; i++)
    {
      wsheet = (WritableSheetImpl) getSheet(i);
      if (wsheet.getSettings().isSelected())
      {
        sheetSelected = true;
        selectedSheetIndex = i;
      }
    }

    if (!sheetSelected)
    {
      wsheet = (WritableSheetImpl) getSheet(0);
      wsheet.getSettings().setSelected(true);
      selectedSheetIndex = 0;
    }

    Window1Record w1r = new Window1Record(selectedSheetIndex);
    outputFile.write(w1r);

    BackupRecord bkr = new BackupRecord(false);
    outputFile.write(bkr);

    HideobjRecord ho = new HideobjRecord(settings.getHideobj());
    outputFile.write(ho);
    
    NineteenFourRecord nf = new NineteenFourRecord(false);
    outputFile.write(nf);

    PrecisionRecord pc = new PrecisionRecord(false);
    outputFile.write(pc);

    RefreshAllRecord rar = new RefreshAllRecord(settings.getRefreshAll());
    outputFile.write(rar);

    BookboolRecord bb = new BookboolRecord(true);
    outputFile.write(bb);

    // Write out all the fonts used
    fonts.write(outputFile);

    // Write out the cell formats used within this workbook
    formatRecords.write(outputFile);

    // Write out the palette, if it exists
    if (formatRecords.getPalette() != null)
    {
      outputFile.write(formatRecords.getPalette());
    }

    // Write out the uses elfs record
    UsesElfsRecord uer = new UsesElfsRecord();
    outputFile.write(uer);
    
    // Write out the boundsheet records.  Keep a handle to each one's
    // position so we can write in the stream offset later
    int[] boundsheetPos = new int[getNumberOfSheets()];
    Sheet sheet = null;

    for (int i = 0; i < getNumberOfSheets(); i++)
    {
      boundsheetPos[i] = outputFile.getPos();
      sheet = getSheet(i);
      BoundsheetRecord br = new BoundsheetRecord(sheet.getName());
      if (sheet.getSettings().isHidden())
      {
        br.setHidden();
      }

      if ( ( (WritableSheetImpl) sheets.get(i)).isChartOnly())
      {
        br.setChartOnly();
      }

      outputFile.write(br);
    }

    if (countryRecord == null)
    {
      CountryCode lang = 
        CountryCode.getCountryCode(settings.getExcelDisplayLanguage());
      if (lang == CountryCode.UNKNOWN)
      {
        logger.warn("Unknown country code " + 
                    settings.getExcelDisplayLanguage() + 
                    " using " + CountryCode.USA.getCode());
        lang = CountryCode.USA;
      }
      CountryCode region = 
        CountryCode.getCountryCode(settings.getExcelRegionalSettings());
      countryRecord = new CountryRecord(lang, region);
      if (region == CountryCode.UNKNOWN)
      {
        logger.warn("Unknown country code " + 
                    settings.getExcelDisplayLanguage() + 
                    " using " + CountryCode.UK.getCode());
        region = CountryCode.UK;
      }
    }

    outputFile.write(countryRecord);
    
    // Write out the names of any add in functions
    if (addInFunctionNames != null && addInFunctionNames.length > 0)
    {
      // Write out the supbook record
      //      SupbookRecord supbook = new SupbookRecord();
      //      outputFile.write(supbook);

      for (int i = 0 ; i < addInFunctionNames.length; i++)
      {
        ExternalNameRecord enr = new ExternalNameRecord(addInFunctionNames[i]);
        outputFile.write(enr);
      }
    }

    if (xctRecords != null)
    {
      for (int i = 0 ; i < xctRecords.length; i++)
      {
        outputFile.write(xctRecords[i]);
      }
    }

    // Write out the external sheet record, if it exists
    if (externSheet != null)
    {
      //Write out all the supbook records
      for (int i = 0; i < supbooks.size() ; i++)
      {
        SupbookRecord supbook = (SupbookRecord) supbooks.get(i);
        outputFile.write(supbook);
      }
      outputFile.write(externSheet);
    }

    // Write out the names, if any exists
    if (names != null)
    {
      for (int i = 0 ; i < names.size() ; i++)
      {
        NameRecord n = (NameRecord) names.get(i);
        outputFile.write(n);
      }
    }
  
    // Write out the mso drawing group, if it exists
    if (drawingGroup != null)
    {
      drawingGroup.write(outputFile);
    }

    sharedStrings.write(outputFile);

    EOFRecord eof = new EOFRecord();
    outputFile.write(eof);


    // Write out the sheets
    for (int i = 0; i < getNumberOfSheets(); i++)
    {
      // first go back and modify the offset we wrote out for the
      // boundsheet record
      outputFile.setData
        (IntegerHelper.getFourBytes(outputFile.getPos()),
         boundsheetPos[i] + 4);

      wsheet = (WritableSheetImpl) getSheet(i);
      wsheet.write();
    }
  }


Generated by  Doxygen 1.6.0   Back to index