Hello!

While I was studying the String functions and Excel structure, Patrick has
already done the patch. :)
Thank you, Patrick, but I have something to say, it seems to me that there
is a way to make it better.

For reading it is good. I have test it, it reads Russian also. But the code
is too obfuscating for me. :( Using SSTDeserialiser, BinaryTree. Somehow I
understood these the offsets, but it was not from the first time.
I tried to simplify the process, but failed, so after the attemptes I have
the question:
How is StringUtil.getFromUnicode(...) working?
( I tried to simply use this function ). I want it to be such easy, but it
was not this way. %)


What do you think about idea to get rid of autodetecting coding, I suggest
the way:

To the BoundSheetRecord change:
    public void setSheetname( String sheetname )
    {
        field_5_sheetname = sheetname;
    }

With the purpose to set all the features in the Workbook:

To the Workbook add
    public void setSheetName(int sheetnum, String sheetname, short
encoding ) {
        checkSheets(sheetnum);

        BoundSheetRecord sheet =
(BoundSheetRecord)boundsheets.get( sheetnum );
        sheet.setSheetname(sheetname);
        sheet.setSheetnameLength( (byte)sheetname.length() );
        sheet.setCompressedUnicodeFlag( (byte)encoding );
    }

And make it available to the user to do it manually, so add to the
HSSFWorkbook:
 public final static byte ENCODING_COMPRESSED_UNICODE = 0;
 public final static byte ENCODING_UTF_16                                 =
1;

    public void setSheetName(int sheet, String name)
    {
        workbook.setSheetName( sheet, name, ENCODING_COMPRESSED_UNICODE );
    }
    public void setSheetName( int sheet, String name, short encoding )
    {
        if (sheet > (sheets.size() - 1))
        {
            throw new RuntimeException("Sheet out of bounds");
        }

        switch ( encoding ) {
        case ENCODING_COMPRESSED_UNICODE:
        case ENCODING_UTF_16:
            break;

        default:
           throw new RuntimeException( "Unsupported encoding" );
        }
        workbook.setSheetName( sheet, name, encoding );
    }


User's example may be like this:
        hssfWorkbook.setSheetName(0, "�������� ������",
HSSFWorkbook.ENCODING_UTF_16 );
    or
        hssfWorkbook.setSheetName(0, "HSSF Test",
HSSFWorkbook.ENCODING_COMPRESSED_UNICODE );




The most unpleasent thing, that saving is not working at my side.
The MS Excel on the opening  such a file tells that the name is incorrect
and fixes the error. :(

So simply StringUtil.putUncompressedUnicode(getSheetname(), data, 12 +
offset); seems not to working.
I tried:
    public int serialize(int offset, byte [] data)
    {
        LittleEndian.putShort(data, 0 + offset, sid);
        LittleEndian.putShort( data, 2 + offset,
                (short)( 0x08 + getSheetnameLength() ) );
        LittleEndian.putInt(data, 4 + offset, getPositionOfBof());
        LittleEndian.putShort(data, 8 + offset, getOptionFlags());
        /*
        data[ 10 + offset ] = getSheetnameLength();
        data[ 11 + offset ] = getCompressedUnicodeFlag();
        */
        UnicodeString name = new UnicodeString();
        name.setOptionFlags( (byte)( field_4_compressed_unicode_flag &
0x01 ) );
        name.setString( getSheetname() );
        System.arraycopy( name.serialize(), 0, data, 10 + offset,
name.getRecordSize() );

        return getRecordSize();
    }
But it is not working too. :(
By the way what is the 0x08 in the expression "0x08 + getSheetnameLength()"
?


Also what is the 0x3 in the class UnicodeString?
    public int serialize(int offset, byte [] data)
    {
        .....
                StringUtil.putCompressedUnicode(getString(), data, 0x3 +
                                                offset);
            }
            else
            {
                StringUtil.putUncompressedUnicode(getString(), data,
                                                  0x3 + offset);
        .....
    }


And while reading excel specification the length of the Unicode String may
be 1 or 2.
How to detect, when it is 1 and when it is 2?

What is your opinion?


Sincerely yours, Sergei Kozello.


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

  • ... Сергей Козелло
    • ... Andrew C. Oliver

Reply via email to