Beispiel #1
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;
        }
Beispiel #2
0
        /**
         * Read support  for low level
         * API.  Pass in an array of Record objects, A Workbook
         * object is constructed and passed back with all of its initialization Set
         * to the passed in records and references to those records held. Unlike Sheet
         * workbook does not use an offset (its assumed to be 0) since its first in a file.
         * If you need an offset then construct a new array with a 0 offset or Write your
         * own ;-p.
         *
         * @param recs an array of Record objects
         * @return Workbook object
         */
        public static InternalWorkbook CreateWorkbook(List<Record> recs)
        {
            //if (log.Check(POILogger.DEBUG))
            //    log.Log(DEBUG, "Workbook (Readfile) Created with reclen=",
            //           recs.Count);
            InternalWorkbook retval = new InternalWorkbook();
            List<Record> records = new List<Record>(recs.Count / 3);
            retval.records.Records=records;

            int k;
            for (k = 0; k < recs.Count; k++)
            {
                Record rec = (Record)recs[k];

                if (rec.Sid == EOFRecord.sid)
                {
                    records.Add(rec);
                    //if (log.Check(POILogger.DEBUG))
                    //    log.Log(DEBUG, "found workbook eof record at " + k);
                    break;
                }
                switch (rec.Sid)
                {

                    case BoundSheetRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found boundsheet record at " + k);
                        retval.boundsheets.Add((BoundSheetRecord)rec);
                        retval.records.Bspos = k;
                        break;

                    case SSTRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found sst record at " + k);
                        retval.sst = (SSTRecord)rec;
                        break;

                    case FontRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found font record at " + k);
                        retval.records.Fontpos = k;
                        retval.numfonts++;
                        break;

                    case ExtendedFormatRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found XF record at " + k);
                        retval.records.Xfpos = k;
                        retval.numxfs++;
                        break;

                    case TabIdRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found tabid record at " + k);
                        retval.records.Tabpos = k;
                        break;

                    case ProtectRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found protect record at " + k);
                        retval.records.Protpos = k;
                        break;

                    case BackupRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found backup record at " + k);
                        retval.records.Backuppos = k;
                        break;
                    case ExternSheetRecord.sid:
                        throw new Exception("Extern sheet is part of LinkTable");
                    case NameRecord.sid:
                    case SupBookRecord.sid:
                        // LinkTable can start with either of these
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found SupBook record at " + k);
                        retval.linkTable = new LinkTable(recs, k, retval.records, retval.commentRecords);
                        k += retval.linkTable.RecordCount - 1;
                        continue;
                    case FormatRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found format record at " + k);
                        retval.formats.Add((FormatRecord)rec);
                        retval.maxformatid = retval.maxformatid >= ((FormatRecord)rec).GetIndexCode() ? retval.maxformatid : ((FormatRecord)rec).GetIndexCode();
                        break;
                    case DateWindow1904Record.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found datewindow1904 record at " + k);
                        retval.uses1904datewindowing = ((DateWindow1904Record)rec).Windowing == 1;
                        break;
                    case PaletteRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found palette record at " + k);
                        retval.records.Palettepos = k;
                        break;
                    case WindowOneRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found WindowOneRecord at " + k);
                        retval.windowOne = (WindowOneRecord)rec;
                        break;
                    case WriteAccessRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found WriteAccess at " + k);
                        retval.writeAccess = (WriteAccessRecord)rec;
                        break;
                    case WriteProtectRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found WriteProtect at " + k);
                        retval.writeProtect = (WriteProtectRecord)rec;
                        break;
                    case FileSharingRecord.sid:
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "found FileSharing at " + k);
                        retval.fileShare = (FileSharingRecord)rec;
                        break;
                    case NameCommentRecord.sid:
                        NameCommentRecord ncr = (NameCommentRecord)rec;
                        retval.commentRecords[ncr.NameText] = ncr;
                        break;
                }
                records.Add(rec);
            }
            //What if we dont have any ranges and supbooks
            //        if (retval.records.supbookpos == 0) {
            //            retval.records.supbookpos = retval.records.bspos + 1;
            //            retval.records.namepos    = retval.records.supbookpos + 1;
            //        }

            // Look for other interesting values that
            //  follow the EOFRecord
            for (; k < recs.Count; k++)
            {
                Record rec = (Record)recs[k];
                switch (rec.Sid)
                {
                    case HyperlinkRecord.sid:
                        retval.hyperlinks.Add((HyperlinkRecord)rec);
                        break;
                }
            }

            if (retval.windowOne == null)
            {
                retval.windowOne = (WindowOneRecord)retval.CreateWindowOne();
            }
            //if (log.Check(POILogger.DEBUG))
            //    log.Log(DEBUG, "exit Create workbook from existing file function");
            return retval;
        }