Как добавить изображение из Blob в ячейку из sqlite? - PullRequest
0 голосов
/ 08 января 2019

Я хочу использовать свою базу данных, которая содержит строковые данные и изображение, чтобы преобразовать их в Excel. Затем я сохранил в своем sqlite серию строк данных и изображение (Blob), но не могу понять, как отобразить изображение в ячейке Excel. База данных загружена правильно, но мне трудно преобразовать мой BLOB-объект (он хранится в виде байтового массива) и показать его. Я использую библиотеку JXL. Я надеюсь, что вы можете помочь мне, спасибо! Вот мой код:

private void openActivity() {
    //add your further process after giving permission or to download images from remote server.
    DBHelper dbHelper = new DBHelper ( this );
    dbHelper.insertData ();

    final Cursor cursor = dbHelper.getuser ();

    File sd = Environment.getExternalStorageDirectory ();
    String csvFile = "LectorDeEstados.xls";

    File directory = new File ( sd.getAbsolutePath () );
    //create directory if not exist
    if (!directory.isDirectory ()) {
        directory.mkdirs ();
    }
    try {

        //file path
        File file = new File ( directory, csvFile );
        WorkbookSettings wbSettings = new WorkbookSettings ();
        wbSettings.setLocale ( new Locale ( "en", "EN" ) );
        WritableWorkbook workbook;
        workbook = Workbook.createWorkbook ( file, wbSettings );

        WritableSheet sheet = null;


        sheet = workbook.createSheet ( "Lectura de estados - Cooperativa", 0 );



            sheet.addCell ( new Label ( 0, 0, "ID" ) );
            sheet.addCell ( new Label ( 1, 0, "Nombre" ) );
            sheet.addCell ( new Label ( 2, 0, "Domicilio" ) );
            sheet.addCell ( new Label ( 3, 0, "Número de Medidor" ) );
            sheet.addCell ( new Label ( 4, 0, "Ultima Lectura" ) );
            sheet.addCell ( new Label ( 5, 0, "Foto" ) );

            if (cursor.moveToFirst ()) {
                do {
                    String title = cursor.getString ( cursor.getColumnIndex ( "id" ) );
                    String email = cursor.getString ( cursor.getColumnIndex ( "name" ) );
                    String mobile = cursor.getString ( cursor.getColumnIndex ( "address" ) );
                    String mobile2 = cursor.getString ( cursor.getColumnIndex ( "medidor" ) );
                    String mobile1 = cursor.getString ( cursor.getColumnIndex ( "nueva" ) );
                  //  byte[] mobile3 = cursor.getBlob ( cursor.getColumnIndex ( "foto" ) );
                    byte[] mobile3 = cursor.getBlob(cursor.getColumnIndex ("foto"));



                    int i = cursor.getPosition () + 1;

                    sheet.addCell ( new Label ( 0, i, title ) );
                    sheet.addCell ( new Label ( 1, i, email ) );
                    sheet.addCell ( new Label ( 2, i, mobile ) );
                    sheet.addCell ( new Label ( 3, i, mobile2 ) );
                    sheet.addCell ( new Label ( 4, i, mobile1 ) );


                    sheet.addCell ( new Label ( 5, i, mobile3 )  );

                } while (cursor.moveToNext ());
            }

            //closing cursor
            cursor.close ();
            workbook.write ();
            workbook.close ();
            Toast.makeText ( getApplication (), " EXCEL ha sido Exportado a la Memoria Interna del Dispositivo ", Toast.LENGTH_LONG ).show ();


        } catch(Exception e){
            e.printStackTrace ();
        }

    }
...