Soru & Cevap

Android listview export excel ...

21.01.2020 - 11:36

Arkadaşlar merhaba, Listview çıktısını excel şeklinde almak istiyorum andoridde. Bilgisi olan yardim edebilirse çok sevinirim.. Iyi çalışmalar..

113 Görüntülenme

5 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-112887-1506457490.jpg
recepözen
22.02.2020 - 09:43
    private File saveExcelFile(Context context, String fileName, List<Urun> urunList, String sendEmail, String unvan) {

        //New Workbook
        Workbook wb = new HSSFWorkbook();

        Cell c = null;

        //Cell style for header row
        CellStyle cs = wb.createCellStyle();
        cs.setFillForegroundColor(HSSFColor.LIME.index);
        cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        //New Sheet
        Sheet sheet1 = null;
        sheet1 = wb.createSheet("New Order");

        Row row = sheet1.createRow(0);

        c = row.createCell(0);
        c.setCellValue("Item Number");
        c.setCellStyle(cs);

        c = row.createCell(1);
        c.setCellValue("Ürün adı");
        c.setCellStyle(cs);

        c = row.createCell(2);
        c.setCellValue("Barkod numarası");
        c.setCellStyle(cs);

        c = row.createCell(3);
        c.setCellValue("Birim fiyatı");
        c.setCellStyle(cs);

        c = row.createCell(4);
        c.setCellValue("Adet");
        c.setCellStyle(cs);

        c = row.createCell(5);
        c.setCellValue("Toplam");
        c.setCellStyle(cs);

        for (int i = 0; i < urunList.size(); i++) {
            row = sheet1.createRow((i + 1));

            c = row.createCell(0);
            c.setCellValue((i + 1));
            c.setCellStyle(cs);

            c = row.createCell(1);
            c.setCellValue(urunList.get(i).getName());
            c.setCellStyle(cs);

            c = row.createCell(2);
            c.setCellValue(urunList.get(i).getBarcod());
            c.setCellStyle(cs);

            c = row.createCell(3);
            c.setCellValue(urunList.get(i).getPrice());
            c.setCellStyle(cs);

            c = row.createCell(4);
            c.setCellValue(urunList.get(i).getLsql_adet());
            c.setCellStyle(cs);

            c = row.createCell(5);
            c.setCellValue((Integer.valueOf(urunList.get(i).getPrice()) * urunList.get(i).getLsql_adet()));
            c.setCellStyle(cs);

        }

        row = sheet1.createRow((urunList.size() + 3));

        c = row.createCell(0);
        c.setCellValue(sendEmail);
        c.setCellStyle(cs);

        c = row.createCell(1);
        c.setCellValue(unvan);
        c.setCellStyle(cs);

        sheet1.setColumnWidth(0, (15 * 400));
        sheet1.setColumnWidth(1, (15 * 400));
        sheet1.setColumnWidth(2, (15 * 400));
        sheet1.setColumnWidth(3, (15 * 400));
        sheet1.setColumnWidth(4, (15 * 400));
        sheet1.setColumnWidth(5, (15 * 400));

        // Create a path where we will place our List of objects on external storage
        File file = new File(context.getExternalFilesDir(null), fileName);
        FileOutputStream os = null;

        try {
            os = new FileOutputStream(file);
            wb.write(os);
            Log.w("FileUtils", "Writing file" + file);
        } catch (IOException e) {
            Log.w("FileUtils", "Error writing " + file, e);
        } catch (Exception e) {
            Log.w("FileUtils", "Failed to save file", e);
        } finally {
            try {
                if (null != os)
                    os.close();
            } catch (Exception ex) {
            }
        }
        return file;
    }

 

picture-112887-1506457490.jpg
recepözen
23.01.2020 - 04:37

Sorununuzu çözdünüz mü ?

Busra Akbey
27.01.2020 - 08:32
Evet hallettim. Teşekkür ederim yardımınız icin
picture-112887-1506457490.jpg
recepözen
23.01.2020 - 12:32

Aktaracağınız verileri buradaki formata dönüştürerek kullanabilirsiniz.

 

picture-112887-1506457490.jpg
recepözen
21.01.2020 - 03:28

Öncelikle kullanmamız gereken 2 tane kütüphanemiz var. Aşağıda indirme linklerini verdiğim kütüphaneleri projenize dahil edin. Bulamazsanız diye yüklüyorum. https://dosya.co/s4twzf9tondd/excel.zip.html

Ve son olarak burda hem yazma ve okuma için gerekli adımlar anlatılıyor örnek kod var. 

https://www.cuelogic.com/blog/creatingreading-an-excel-file-in-android#

 

 

Busra Akbey
21.01.2020 - 04:18
burada eliyle verileri belirlemiş fakat ben listviewdan aktarıcam
picture-112887-1506457490.jpg
recepözen
21.01.2020 - 01:24

Bunun tam tersini bir uygulamam da kullanıdım. Hangi dilde yazıcaktınız.

Busra Akbey
21.01.2020 - 03:02
java