doubi1624
doubi1624
2011-12-05 16:28

PHP XLS 2003(Excel)文件 - 检测单元格垂直对齐

已采纳

I need to make a slight change to the PHP Excel Reader library; http://code.google.com/p/php-excel-reader/

I want to add support for vertical-alignment of cells (top, middle, bottom).

Here's how the normal alignment is detected:

                    $alignbit = ord($data[$pos+10]) & 3;

And here is the excel 2003 format specification:

http://sc.openoffice.org/excelfileformat.pdf

I'm not sure if this is the correct setting:

Does anyone know what bit I need to get (similar to the $alignbit) in order to get the vertical alignment? (1 of 6 possibilities)

enter image description here

enter image description here Thanks, Wesley

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duancha1065 duancha1065 10年前

    Personally I'd use

    $horizontalAlign = (0x07 & ord($data[$pos+10])) >> 0;
    

    rather than

    $horizontalAlign = ord($data[$pos+10]) & 3;
    

    because you can then match the mask (0x07) up with the spec definition more obviously

    Using the same principle, vertical alignment is bits 6-4, mask 0x70, so

    $verticalAlign = (0x70 & ord($data[$pos+10])) >> 4;
    switch ($verticalAlign) {
        case 0:
            //  VERTICAL_TOP
            break;
        case 1:
            //  VERTICAL_CENTER
            break;
        case 2:
            //  VERTICAL_BOTTOM
            break;
        case 3:
            //  VERTICAL_JUSTIFY
            break;
        case 4:
            //  VERTICAL_DISTRIBUTED
            break;
    }
    

    PS. Why are you still using Open Office's partial spec, when Microsoft have published the full specification

    点赞 评论 复制链接分享