Example #1
0
        /// <summary>
        /// Clones all the style information from another
        /// HSSFCellStyle, onto this one. This
        /// HSSFCellStyle will then have all the same
        /// properties as the source, but the two may
        /// be edited independently.
        /// Any stylings on this HSSFCellStyle will be lost!
        /// The source HSSFCellStyle could be from another
        /// HSSFWorkbook if you like. This allows you to
        /// copy styles from one HSSFWorkbook to another.
        /// </summary>
        /// <param name="source">The source.</param>
        public void CloneStyleFrom(HSSFCellStyle source)
        {
            // First we need to clone the extended format
            //  record
            format.CloneStyleFrom(source.format);

            // Handle matching things if we cross workbooks
            if (workbook != source.workbook)
            {
                // Then we need to clone the format string,
                //  and update the format record for this
                short fmt = (short)workbook.CreateFormat(
                    source.GetDataFormatString()
                    );
                this.DataFormat = (fmt);

                // Finally we need to clone the font,
                //  and update the format record for this
                FontRecord fr = workbook.CreateNewFont();
                fr.CloneStyleFrom(
                    source.workbook.GetFontRecordAt(
                        source.FontIndex
                        )
                    );

                HSSFFont font = new HSSFFont(
                    (short)workbook.GetFontIndex(fr), fr
                    );
                this.SetFont(font);
            }
        }
Example #2
0
        /**
         * Creates an empty workbook object with three blank sheets and all the empty
         * fields.  Use this to Create a workbook from scratch.
         */
        public static InternalWorkbook CreateWorkbook()
        {
            //if (log.Check(POILogger.DEBUG))
            //    log.Log(DEBUG, "creating new workbook from scratch");
            InternalWorkbook retval = new InternalWorkbook();
            List<Record> records = new List<Record>(30);
            retval.records.Records=records;
            List<FormatRecord> formats = new List<FormatRecord>(8);

            records.Add(retval.CreateBOF());
            records.Add(retval.CreateInterfaceHdr());
            records.Add(retval.CreateMMS());
            records.Add(retval.CreateInterfaceEnd());
            records.Add(retval.CreateWriteAccess());
            records.Add(retval.CreateCodepage());
            records.Add(retval.CreateDSF());
            records.Add(retval.CreateTabId());
            retval.records.Tabpos=records.Count - 1;
            records.Add(retval.CreateFnGroupCount());
            records.Add(retval.CreateWindowProtect());
            records.Add(retval.CreateProtect());
            retval.records.Protpos=records.Count - 1;
            records.Add(retval.CreatePassword());
            records.Add(retval.CreateProtectionRev4());
            records.Add(retval.CreatePasswordRev4());
            retval.windowOne = (WindowOneRecord)retval.CreateWindowOne();
            records.Add(retval.windowOne);
            records.Add(retval.CreateBackup());
            retval.records.Backuppos=records.Count - 1;
            records.Add(retval.CreateHideObj());
            records.Add(retval.CreateDateWindow1904());
            records.Add(retval.CreatePrecision());
            records.Add(retval.CreateRefreshAll());
            records.Add(retval.CreateBookBool());
            records.Add(retval.CreateFont());
            records.Add(retval.CreateFont());
            records.Add(retval.CreateFont());
            records.Add(retval.CreateFont());
            retval.records.Fontpos=records.Count - 1;   // last font record postion
            retval.numfonts = 4;

            // Set up format records
            for (int i = 0; i <= 7; i++)
            {
                Record rec;
                rec = retval.CreateFormat(i);
                retval.maxformatid = retval.maxformatid >= ((FormatRecord)rec).GetIndexCode() ? retval.maxformatid : ((FormatRecord)rec).GetIndexCode();
                formats.Add((FormatRecord)rec);
                records.Add(rec);
            }
            retval.formats = formats;

            for (int k = 0; k < 21; k++)
            {
                records.Add(retval.CreateExtendedFormat(k));
                retval.numxfs++;
            }
            retval.records.Xfpos=records.Count - 1;
            for (int k = 0; k < 6; k++)
            {
                records.Add(retval.CreateStyle(k));
            }
            records.Add(retval.CreateUseSelFS());

            int nBoundSheets = 1; // now just do 1
            for (int k = 0; k < nBoundSheets; k++)
            {
                BoundSheetRecord bsr =
                        (BoundSheetRecord)retval.CreateBoundSheet(k);

                records.Add(bsr);
                retval.boundsheets.Add(bsr);
                retval.records.Bspos=records.Count - 1;
            }
            //        retval.records.supbookpos = retval.records.bspos + 1;
            //        retval.records.namepos = retval.records.supbookpos + 2;
            records.Add(retval.CreateCountry());
            for (int k = 0; k < nBoundSheets; k++)
            {
                retval.OrCreateLinkTable.CheckExternSheet(k);
            }
            retval.sst = (SSTRecord)retval.CreateSST();
            records.Add(retval.sst);
            records.Add(retval.CreateExtendedSST());

            records.Add(retval.CreateEOF());
            //if (log.Check(POILogger.DEBUG))
            //    log.Log(DEBUG, "exit Create new workbook from scratch");
            return retval;
        }