Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the Fonts collection for the given XlsDocument.
        /// </summary>
        /// <param name="doc">The parent XlsDocument object for the new Fonts collection.</param>
        public Fonts(XlsDocument doc)
        {
            _doc = doc;

            _fonts = new List <Font>();

            AddDefaultFonts();
        }
Esempio n. 2
0
//        private const ushort DEFAULT_LINE_COLOUR_INDEX = 8;

        internal CellFormat(XlsDocument doc)
        {
            _doc = doc;

            _id = null;

            SetDefaults();
        }
Esempio n. 3
0
        private Bytes GetFormatRecord(ushort id, string format)
        {
            Bytes bytes = new Bytes();

            bytes.Append(BitConverter.GetBytes(id));
            bytes.Append(XlsDocument.GetUnicodeString(format, 16));

            return(Record.GetBytes(RID.FORMAT, bytes));
        }
Esempio n. 4
0
        internal Style(XlsDocument doc, CellFormat xf)
        {
            _isInitializing = true;

            _doc = doc;
            _xf  = xf;

            _isInitializing = false;
        }
Esempio n. 5
0
        internal Font(XlsDocument doc)
        {
            _isInitializing = true;

            _doc = doc;
            _id  = null;

            SetDefaults();

            _isInitializing = false;
        }
Esempio n. 6
0
        internal Workbook(XlsDocument doc)
        {
            _doc = doc;

            _worksheets = new Worksheets(_doc);
            _fonts      = new Fonts(_doc);
            _formats    = new Formats(_doc);
            _styles     = new Styles(_doc);
            _xfs        = new CellFormats(_doc, this);
            _palette    = new Palette(this);
        }
Esempio n. 7
0
        private Bytes LABEL()
        {
            Bytes label = new Bytes();

            label.Append(LABELBase());

            //Unicode string, 16-bit string length
            label.Append(XlsDocument.GetUnicodeString((string)Value ?? string.Empty, 16));

            return(Record.GetBytes(RID.LABEL, label));
        }
Esempio n. 8
0
        internal CellFormats(XlsDocument doc, Workbook workbook)
        {
            _doc      = doc;
            _workbook = workbook;

            _xfs = new List <CellFormat>();

            AddDefaultStyleXFs();
            AddDefaultUserXF();
            //AddDefaultFormattedStyleXFs();  //what was I thinking about here?
        }
Esempio n. 9
0
        private void AddStrings(List <string> stringList, ref int remainingRecordBytes, ref Bytes bytes, Bytes sst, ref bool isFirstContinue)
        {
            foreach (string sharedString in stringList)
            {
                Bytes stringBytes = XlsDocument.GetUnicodeString(sharedString, 16);

                //per excelfileformat.pdf sec. 5.22, can't split a
                //Unicode string to another CONTINUE record before
                //the first character's byte/s are written, and must
                //repeat string option flags byte if it is split
                //OPTIM: For smaller filesize, handle the possibility of compressing continued portion of uncompressed strings (low ROI!)
                byte stringOptionFlag = 0xFF;
                bool charsAre16Bit    = false;
                int  minimumToAdd     = int.MaxValue;

                if (stringBytes.Length > remainingRecordBytes)
                {
                    stringOptionFlag = stringBytes.Get(2, 1).ByteArray[0];
                    charsAre16Bit    = (stringOptionFlag & 0x01) == 0x01;
                    minimumToAdd     = charsAre16Bit ? 5 : 4;
                }

                while (stringBytes != null)
                {
                    if (stringBytes.Length > remainingRecordBytes) //add what we can and continue
                    {
                        bool stringWasSplit = false;
                        if (remainingRecordBytes > minimumToAdd)
                        {
                            int overLength = (stringBytes.Length - remainingRecordBytes);
                            bytes.Append(stringBytes.Get(0, remainingRecordBytes));
                            stringBytes           = stringBytes.Get(remainingRecordBytes, overLength);
                            remainingRecordBytes -= remainingRecordBytes;
                            stringWasSplit        = true;
                        }

                        bytes = Continue(sst, bytes, out remainingRecordBytes, ref isFirstContinue);

                        if (stringWasSplit)
                        {
                            bytes.Append(stringOptionFlag);
                            remainingRecordBytes--;
                        }
                    }
                    else //add what's left
                    {
                        bytes.Append(stringBytes);
                        remainingRecordBytes -= stringBytes.Length;
                        stringBytes           = null; //exit loop to continue to next sharedString
                    }
                }
            }
        }
Esempio n. 10
0
        private static Bytes BOUNDSHEET(Worksheet sheet, int basePosition)
        {
            Bytes bytes = new Bytes();

            Bytes sheetName = XlsDocument.GetUnicodeString(sheet.Name, 8);

            bytes.Append(WorksheetVisibility.GetBytes(sheet.Visibility));
            bytes.Append(WorksheetType.GetBytes(sheet.SheetType));
            bytes.Append(sheetName);
            bytes.Prepend(BitConverter.GetBytes((int)basePosition));              //TODO: this should probably be unsigned 32 instead

            bytes.Prepend(BitConverter.GetBytes((ushort)bytes.Length));
            bytes.Prepend(RID.BOUNDSHEET);

            return(bytes);
        }
Esempio n. 11
0
        internal Worksheet(XlsDocument doc)
        {
            _doc = doc;

            _visibility = WorksheetVisibilities.Default;
            _sheettype = WorksheetTypes.Default;
            _streamByteLength = 0;

            _dbCellOffsets = new int[0];

            _cells = new Cells(this);
            _rows = new Rows();
            _rowBlocks = new RowBlocks(this);

            _cachedBlockRow = CachedBlockRow.Empty;

            _columnInfos = new List<ColumnInfo>();
        }
Esempio n. 12
0
        internal Worksheet(XlsDocument doc, Record boundSheet, List<Record> sheetRecords) : this(doc)
        {
            byte[] byteArray = boundSheet.Data.ByteArray;

            byte visibility = byteArray[4];
            if (visibility == 0x00)
                _visibility = WorksheetVisibilities.Visible;
            else if (visibility == 0x01)
                _visibility = WorksheetVisibilities.Hidden;
            else if (visibility == 0x02)
                _visibility = WorksheetVisibilities.StrongHidden;
            else
                throw new Exception(string.Format("Unknown Visibility {0}", visibility));

            byte type = byteArray[5];
            if (type == 0x00)
                _sheettype = WorksheetTypes.Worksheet;
            else if (type == 0x02)
                _sheettype = WorksheetTypes.Chart;
            else if (type == 0x06)
                _sheettype = WorksheetTypes.VBModule;
            else
                throw new Exception(string.Format("Unknown Sheet Type {0}", type));

            List<Record> rowRecords = new List<Record>();
            List<Record> cellRecords = new List<Record>();

            for (int i = 0; i < sheetRecords.Count; i++)
            {
                Record record = sheetRecords[i];
                if (record.IsCellRecord())
                {
                    if (record.RID == RID.FORMULA)
                    {
                        Record formulaStringRecord = null;
                        if ((i + i) < sheetRecords.Count)
                        {
                            formulaStringRecord = sheetRecords[i + 1];
                            if (formulaStringRecord.RID != RID.STRING)
                                formulaStringRecord = null;
                        }
                        record = new FormulaRecord(record, formulaStringRecord);
                    }

                    cellRecords.Add(record);
                }
                else if (record.RID == RID.ROW)
                    rowRecords.Add(record);
            }

            //Add the Rows first so they exist for adding the Cells
            foreach (Record rowRecord in rowRecords)
            {
                Bytes rowBytes = rowRecord.Data;
                ushort rowIndex = rowBytes.Get(0, 2).GetBits().ToUInt16();
                Row row = Rows.AddRow(rowIndex);
                bool isDefaultHeight = rowBytes.Get(6, 2).GetBits().Values[15];
                ushort height = 0;
                if (!isDefaultHeight)
                {
                    height = rowBytes.Get(6, 2).GetBits().Get(0, 14).ToUInt16();
                    //TODO: Set height on Row when reading (after Row Height implemented)
                }
                bool defaultsWritten = (rowBytes.Get(10, 1).ByteArray[0] == 0x01);
                if (defaultsWritten)
                {
                    //TODO: Read ROW record defaults
                }
            }

            foreach (Record record in cellRecords)
                AddCells(record);

            _name = UnicodeBytes.Read(boundSheet.Data.Get(6, boundSheet.Data.Length - 6), 8);
        }
Esempio n. 13
0
 internal Workbook(XlsDocument doc, Bytes bytes, BytesReadCallback bytesReadCallback) : this(doc)
 {
     ReadBytes(bytes, bytesReadCallback);
 }
Esempio n. 14
0
 internal CellFormat(XlsDocument doc, Bytes bytes, Font font, string format) : this(doc)
 {
     ReadBytes(bytes, font, format);
 }
Esempio n. 15
0
 internal Worksheets(XlsDocument doc) : base()
 {
     _doc = doc;
 }
Esempio n. 16
0
 /// <summary>
 /// Initializes a new instance of the ColumnInfo class for the given Doc
 /// and Worksheet.
 /// </summary>
 /// <param name="doc">The parent excel.Doc object for the new ColumnInfo object.</param>
 /// <param name="worksheet">The parent excel.Worksheet object for the new ColumnInfo object.</param>
 public ColumnInfo(XlsDocument doc, Worksheet worksheet)
 {
     _doc       = doc;
     _worksheet = worksheet;
 }
Esempio n. 17
0
 /// <summary>
 /// Initializes a new instance of the Styles object for the give XlsDocument.
 /// </summary>
 /// <param name="doc">The parent XlsDocument object for the new Styles object.</param>
 public Styles(XlsDocument doc)
 {
     _doc = doc;
 }
Esempio n. 18
0
 internal Font(XlsDocument doc, CellFormat xf) : this(doc)
 {
     _target = xf;
 }
Esempio n. 19
0
 internal Font(XlsDocument doc, Bytes bytes) : this(doc)
 {
     ReadBytes(bytes);
 }
Esempio n. 20
0
 internal Formats(XlsDocument doc)
 {
     _doc = doc;
 }