How to create Excel file from ListView data and save it in Download directory from your Android app?

preview_player
Показать описание
This video shows the steps to create an excel file from the ListView data. In this demo it first creates the ListView with some sample string data.

Then in the button onClick method, it reads the listView data one by one iteratively and populate the respective cells of an excel file.

It then saves the file in download folder using the StorageManager APIs.

Complete source code and other details/ steps of this video are posted in the below link:

However, the main Java code is copied below also for reference:

public class MainActivity extends AppCompatActivity {
private ListView listView;

@Override
protected void onCreate(Bundle savedInstanceState) {

String[] stringArray = {"This", "is", "an", "example", "Excel", "Sheet", "from", "programmer", "world"};

stringArray));
}

public void buttonCreateExcelFile(View view){
HSSFWorkbook hssfWorkbook = new HSSFWorkbook();

}
saveWorkBook(hssfWorkbook);
}

private void saveWorkBook(HSSFWorkbook hssfWorkbook){
StorageManager storageManager = (StorageManager) getSystemService(STORAGE_SERVICE);

try {
FileOutputStream fileOutputStream = new FileOutputStream(fileOutput);

} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

--
Рекомендации по теме
Комментарии
Автор

Thank you sooo muchhh. such a simple way of doing it. Helped me a lot

shibaadka
Автор

I want to fix the headings horizontal and want to enter the daily data under these headings
Now how to fix the headings

charanlalam
Автор

How to make the result cell vertical in Exel??

amirhatami
Автор

who to can set date in Adjacent cell this source ?

AranSabz
Автор

Doesn't work in any api, it creates a file in 34 api, but i cant ever open it in emulator phone, and on my api 26 phone i used:
file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "Maitinimosi Dienoraščio ataskaita.xls");
and it crashes app.

renisrrenis