Exemplo n.º 1
0
        /**
         * Writes out the biff record
         * @param r
         * @exception IOException if an error occurs
         */
        private bool writeRecord(CSharpJExcel.Jxl.Read.Biff.Record r, TextWriter os)
        {
            bool cont = true;
            int pos = reader.getPos();
            int code = r.getCode();

            if (bofs == 0)
                {
                cont = (r.getType() == CSharpJExcel.Jxl.Biff.Type.BOF);
                }

            if (!cont)
                {
                return cont;
                }

            if (r.getType() == CSharpJExcel.Jxl.Biff.Type.BOF)
                {
                bofs++;
                }

            if (r.getType() == CSharpJExcel.Jxl.Biff.Type.EOF)
                {
                bofs--;
                }

            StringBuilder buf = new StringBuilder();

            // Write out the record header
            writeSixDigitValue(pos, buf);
            buf.Append(" [");
            buf.Append(recordNames[r.getType()]);
            buf.Append("]");
            buf.Append("  (0x");
            buf.Append(code.ToString("x"));
            buf.Append(")");

            if (code == CSharpJExcel.Jxl.Biff.Type.XF.value)
                {
                buf.Append(" (0x");
                buf.Append(xfIndex.ToString("x"));
                buf.Append(")");
                xfIndex++;
                }

            if (code == CSharpJExcel.Jxl.Biff.Type.FONT.value)
                {
                if (fontIndex == 4)
                    {
                    fontIndex++;
                    }

                buf.Append(" (0x");
                buf.Append(fontIndex.ToString("x"));
                buf.Append(")");
                fontIndex++;
                }

            os.Write(buf.ToString());
            os.WriteLine();

            byte[] standardData = new byte[4];
            standardData[0] = (byte)(code & 0xff);
            standardData[1] = (byte)((code & 0xff00) >> 8);
            standardData[2] = (byte)(r.getLength() & 0xff);
            standardData[3] = (byte)((r.getLength() & 0xff00) >> 8);
            byte[] recordData = r.getData();
            byte[] data = new byte[standardData.Length + recordData.Length];
            Array.Copy(standardData, 0, data, 0, standardData.Length);
            Array.Copy(recordData, 0, data, standardData.Length, recordData.Length);

            int byteCount = 0;
            int lineBytes = 0;

            while (byteCount < data.Length)
                {
                buf = new StringBuilder();
                writeSixDigitValue(pos + byteCount, buf);
                buf.Append("   ");

                lineBytes = Math.Min(bytesPerLine, data.Length - byteCount);

                for (int i = 0; i < lineBytes; i++)
                    {
                    writeByte(data[i + byteCount], buf);
                    buf.Append(' ');
                    }

                // Perform any padding
                if (lineBytes < bytesPerLine)
                    {
                    for (int i = 0; i < bytesPerLine - lineBytes; i++)
                        {
                        buf.Append("   ");
                        }
                    }

                buf.Append("  ");

                for (int i = 0; i < lineBytes; i++)
                    {
                    char c = (char)data[i + byteCount];
                    if (c < ' ' || c > 'z')
                        c = '.';
                    buf.Append(c);
                    }

                byteCount += lineBytes;

                os.Write(buf.ToString());
                os.WriteLine();
                }

            return cont;
        }