示例#1
0
        /// <summary>
        /// 放回公用样式
        /// </summary>
        /// <param name="xls"></param>
        /// <returns></returns>
        public static XF SetCommonStyle(XlsDocument xls)
        {
            XF xf = xls.NewXF();

            xf.HorizontalAlignment = HorizontalAlignments.Centered;
            xf.VerticalAlignment   = VerticalAlignments.Centered;
            return(xf);
        }
示例#2
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();
        }
示例#3
0
//        private const ushort DEFAULT_LINE_COLOUR_INDEX = 8;

        internal XF(XlsDocument doc)
        {
            _doc = doc;

            _id = null;

            SetDefaults();
        }
示例#4
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));
        }
示例#5
0
        /// <summary>
        /// 设置某一列值的宽度
        /// </summary>
        /// <param name="xls"></param>
        /// <param name="wks"></param>
        /// <param name="columnindex"></param>
        /// <param name="widthline"></param>
        public static void SetColumnWidth(XlsDocument xls, Worksheet wks, ushort columnindex, ushort widthline)
        {
            ColumnInfo colinfo = new ColumnInfo(xls, wks);

            colinfo.ColumnIndexStart = columnindex;
            colinfo.ColumnIndexEnd   = columnindex;
            colinfo.Width            = (ushort)(widthline * 256);
            wks.AddColumnInfo(colinfo);
        }
示例#6
0
        internal Style(XlsDocument doc, XF xf)
        {
            _isInitializing = true;

            _doc = doc;
            _xf  = xf;

            _isInitializing = false;
        }
示例#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));
        }
示例#8
0
        internal Font(XlsDocument doc)
        {
            _isInitializing = true;

            _doc = doc;
            _id  = null;

            SetDefaults();

            _isInitializing = false;
        }
示例#9
0
        internal XFs(XlsDocument doc, Workbook workbook)
        {
            _doc      = doc;
            _workbook = workbook;

            _xfs = new List <XF>();

            AddDefaultStyleXFs();
            AddDefaultUserXF();
            //AddDefaultFormattedStyleXFs();  //what was I thinking about here?
        }
示例#10
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 XFs(_doc, this);
            _palette    = new Palette(this);
        }
示例#11
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
                    }
                }
            }
        }
示例#12
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);
        }
示例#13
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>();
        }
示例#14
0
 internal Formats(XlsDocument doc)
 {
     _doc = doc;
 }
示例#15
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 ApplicationException(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 ApplicationException(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);
        }
示例#16
0
 internal Font(XlsDocument doc, XF xf) : this(doc)
 {
     _target = xf;
 }
示例#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;
 }
示例#18
0
 internal Font(XlsDocument doc, Bytes bytes) : this(doc)
 {
     ReadBytes(bytes);
 }
示例#19
0
 internal XF(XlsDocument doc, Bytes bytes, Font font, string format) : this(doc)
 {
     ReadBytes(bytes, font, format);
 }
示例#20
0
 internal Worksheets(XlsDocument doc) : base()
 {
     _doc = doc;
 }
示例#21
0
 internal Workbook(XlsDocument doc, Bytes bytes, BytesReadCallback bytesReadCallback) : this(doc)
 {
     ReadBytes(bytes, bytesReadCallback);
 }
示例#22
0
 /// <summary>
 /// Initializes a new instance of the ColumnInfo class for the given Doc
 /// and Worksheet.
 /// </summary>
 /// <param name="doc">The parent MyXls.Doc object for the new ColumnInfo object.</param>
 /// <param name="worksheet">The parent MyXls.Worksheet object for the new ColumnInfo object.</param>
 public ColumnInfo(XlsDocument doc, Worksheet worksheet)
 {
     _doc       = doc;
     _worksheet = worksheet;
 }