jxl処理ピクチャ

7195 ワード

この2,3日使うので、臨時にネットで探しました.
  
/*
   // ok:            ,  xls 
   java.io.File image8 = new java.io.File("E:\\logo.png");
   WritableImage wimage = new WritableImage( 2, 7, 2.5, 2.5, image8 );
   ws.addImage( wimage );
   */
        
        // ok:  internet      ,  xls 
        HttpClient client = new HttpClient();
        String url76 = "http://www.google.cn/images/nav_logo3.png";
        GetMethod get77 = new GetMethod( url76 );
        client.executeMethod( get77 );
        byte[] bb77 = get77.getResponseBody();
        java.io.InputStream is77 = get77.getResponseBodyAsStream();
        //    HttpClient   
        get77.releaseConnection();
        
        //       , ok: 2007-12-11 17:29:35
        BufferedImage bi7 = ImageIO.read( is77 );
        
        // another interface such as: read(InputStream input) 
        int picWidth = bi7.getWidth(); //    ,    150
        int picHeight = bi7.getHeight(); //    ,    105
        
        //test
        System.out.println("--1703");
        System.out.println("Width=" + picWidth );
        System.out.println("Height=" + picHeight );

        //     ,        
        double picBeginCol = 1.2;
        double picBeginRow = 1.2;

        /*
                : 150/105 = 2.78 cm / 3.97 cm = 4832 / 1590
                : 300/210 =           2    = 9600 / 3150   : 32 / 15
        */
        //     ( picCellWidth, picCellHeight ),       ,    100%   : begin
        //       cell   =         cell         cell ratio  
        //       :       ,           ,       ratio,    
        // 
        double picCellWidth = 0.0; //   cell     ,    
        double picCellHeight = 0.0;
        // wc = ws.getWritableCell( picBeginCol, picBeginRow ); //  , 
        // ws.getColumnView( picBeginCol ).getSize();
        // ws.getRowView( picBeginRow ).getSize();

        int _picWidth = picWidth * 32 ; // pic   ,    ,  jxl     , 32/15
        for(int x=0; x< 1234; x++)
        {
            int bc = (int)Math.floor( picBeginCol + x ); // 3.6 to 3 //       cell  
            System.out.println("x =" + x ); //test
            System.out.println("bc =" + bc ); //test
            int v = ws.getColumnView( bc ).getSize(); //  cell ,jxl  
            double _offset0 = 0.0; // >= 0 //        ,   x = 0      
            if( 0 == x )
                _offset0 = ( picBeginCol - bc ) * v ; // 
            
            System.out.println("_offset0 =" + _offset0 ); //test
            System.out.println("_picWidth =" + _picWidth ); //test
            System.out.println("v =" + v ); //test
            System.out.println("cw 00=" + ws.getColumnView( 0 ).getSize() ); //test
            System.out.println("ch 00=" + ws.getRowView( 0 ).getSize() ); //test
            System.out.println("cw 22=" + ws.getColumnView( 2 ).getSize() ); //test
            System.out.println("ch 22=" + ws.getRowView( 2 ).getSize() ); //test
            
            if( 0.0 + _offset0 + _picWidth > v ) // _picWidth         cell 
            {
                //     cell , pic    ratio ,     picCellWidth
                double _ratio = 1.0;
                if( 0 == x )
                    _ratio = ( 0.0 + v - _offset0 ) / v;
                System.out.println("_ratio =" + _ratio ); //test
                // picCellWidth += 1.0;
                picCellWidth += _ratio;
                _picWidth -= (int)( 0.0 + v - _offset0 ); // int
            } 
            else // _picWidth        cell  
            {
                double _ratio = 0.0;
                if( v != 0 )
                    _ratio = ( 0.0 + _picWidth ) / v;
                picCellWidth += _ratio;
                System.out.println("for: picCellWidth =" + picCellWidth ); //test
                break;
            }
            if( x >= 1233 )
                ntTool.ntSysOut("enwl_print_report_xls: 446: x >= 1233,    ,     ,    "); //
        } // for
        //    picCellWidth         

        //
        int _picHeight = picHeight * 15 ; // pic   ,    ,  jxl     , 32/15
        for(int x=0; x< 1234; x++)
        {
            int bc = (int)Math.floor( picBeginRow + x ); // 3.6 to 3 //       cell  
            int v = ws.getRowView( bc ).getSize(); //  cell ,jxl  
            double _offset0 = 0.0; // >= 0 //        ,   x = 0      
            if( 0 == x )
                _offset0 = ( picBeginRow - bc ) * v ; // 
            if( 0.0 + _offset0 + _picHeight > v ) // _picHeight         cell 
            {
                //     cell , pic    ratio ,     picCellHeight
                double _ratio = 1.0;
                if( 0 == x )
                    _ratio = ( 0.0 + v - _offset0 ) / v;
                // picCellHeight += 1.0;
                picCellHeight += _ratio;
                _picHeight -= (int)( 0.0 + v - _offset0 ); // int
            } 
            else // _picHeight        cell  
            {
                double _ratio = 0.0;
                if( v != 0 )
                    _ratio = ( 0.0 + _picHeight ) / v;
                picCellHeight += _ratio;
                break;
            }
            if( x >= 1233 )
                ntTool.ntSysOut("enwl_print_report_xls: 446: x >= 1233,    ,     ,    "); //
        } // for
        //    picCellHeight         
        //     ( picCellWidth, picCellHeight ),       ,    100%   : end
       

        //test
        System.out.println("picBeginCol=" + picBeginCol );
        System.out.println("picBeginRow=" + picBeginRow );
        System.out.println("picCellWidth=" + picCellWidth );
        System.out.println("picCellHeight=" + picCellHeight );
       

        WritableImage wimage = new WritableImage( picBeginCol,picBeginRow, picCellWidth,picCellHeight, bb77 );
        
        // WritableImage wimage = new WritableImage( 2.2, 3.2, 2.3, 2.8, bb77 );
        
        //     xls 
        ws.addImage( wimage );
        //    : end
        
        
        
        //   ,     , protect:
        if( is_rpt_readOnly )
        {
            ws.getSettings().setProtected(true);
            ws.getSettings().setPassword( rpt_readOnly_pwd );
        }

        jxl.write.WritableCell wc = null; // equal to global

    
    //     i_sheet   Sheet 
    Sheet rs = rwb.getSheet( i_sheet );