Implementing Data Export (CSV, Excel) from Mobile Apps
User taps "Export" — and waits. If there are 5000 rows in a local SQLite or Room database, and export runs on the main thread, the app freezes for seconds, and on older devices an ANR (Application Not Responding) is almost guaranteed. This is the first and most common mistake when implementing export. In our practice, we encounter such situations constantly and have developed a reliable approach that guarantees stable operation even on devices with 2 GB of RAM.
Our engineers with seven years of mobile development experience have delivered over 50 projects involving data export. Each project was tested on real data volumes up to 500,000 rows. For example, on a logistics app with 500,000 transaction records, we reduced export time from 15 seconds to 2.1 seconds by using batched writes on a background thread. Contact us — we'll review your architecture in 30 minutes.
Why encoding is a trap
CSV is a trap. Excel on Windows expects Windows-1252 encoding and a semicolon `;` as delimiter, not a comma. If you deliver UTF-8 without BOM, Cyrillic becomes garbled. The correct CSV for Excel: UTF-8 with BOM (`\uFEFF` at the start of the file) and semicolon delimiter. Or export directly as `.xlsx` using a library.Problems we solve in practice
UI freeze during file generation. Serializing 10,000 rows to CSV is not instant. On Android, use CoroutineScope(Dispatchers.IO), on iOS DispatchQueue.global(qos: .userInitiated). We always move file generation to a background thread and return the result via callback or Flow.
Encoding and delimiter. CSV is a trap. Excel on Windows expects Windows-1252 encoding and semicolon ; as delimiter, not a comma. If you deliver UTF-8 without BOM, Cyrillic becomes garbled in the client's office. The correct CSV for Excel: UTF-8 with BOM (\uFEFF) and semicolon delimiter. Or export directly as .xlsx using a library.
Export to Excel (.xlsx). On Android we use Apache POI or the lighter FastExcel. On iOS — xlsxwriter via Swift Package or a custom XML generator (.xlsx is a ZIP of XML files). React Native apps can use react-native-xlsx over the js xlsx library.
How we build the export
The scheme is simple: read data from local DB → transform into row model → write to file → share via system ShareSheet / Intent.ACTION_SEND.
On Android with Room:
viewModelScope.launch(Dispatchers.IO) { val rows = database.transactionDao().getAll() val file = CsvExporter.export(rows, context.cacheDir) withContext(Dispatchers.Main) { shareFile(file, "text/csv") } } On iOS similarly via Task.detached:
Task.detached(priority: .userInitiated) { let rows = await store.fetchAll() let url = try CsvExporter.write(rows, to: .cachesDirectory) await MainActor.run { presentShareSheet(url) } } For .xlsx on iOS, we generate XML structure manually or via CoreXLSX / xlsxwriter. For simple tables, the XML approach is faster and dependency-free.
Progress for large volumes
If rows exceed 50,000, we show a ProgressView with real percentage. On Android via StateFlow<Int> in ViewModel, on iOS via @Published var progress: Double. We write the file in batches of 1000 rows and update the counter after each batch.
File format and sharing
After generation, we place the file in cacheDir (Android) or FileManager.default.temporaryDirectory (iOS). We share via:
- Android:
FileProvider+Intent.ACTION_SENDwith correct MIME type (text/csvorapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet) - iOS:
UIActivityViewControllerwith[fileURL]
We never save to Downloads without explicit user request — that violates both platform guidelines.
Why background thread export is critical
Any I/O and serialization work must be off the main thread. In practice, this reduces app response time by 5–10 times for exports starting at 10,000 rows. Our engineers verify this on every project.
How to correctly display Cyrillic in CSV for Excel
Use UTF-8 with BOM and semicolon as delimiter. Alternatively, export to .xlsx where encoding is not an issue. We have experience adapting exports for local markets including Cyrillic and Asian characters.
Step-by-step export implementation
- Choose format (CSV or XLSX) and agree on column structure.
- Read data from DB on a background thread.
- Generate file with correct encoding and delimiters.
- Show progress for large volumes.
- Share via system dialog.
What's included in the work
- Format selection (CSV / XLSX) and column structure agreement
- Background file generation without UI blocking
- Correct encoding and localized delimiters
- Progress indicator for large exports
- System ShareSheet / Intent sharing
- Testing on real data volumes
Timelines
Simple CSV export from an existing database: 0.5–1 day. With format selection (CSV/XLSX), date range filters, and progress: 1.5–2 days. Cost is determined after data structure analysis — we'll assess your project for free. Contact us to discuss your task and get a consultation on format selection and work scope.
| Format | Implementation Complexity | Formatting Support | Dependencies |
|---|---|---|---|
| CSV | Low | No | Minimal |
| XLSX | Medium | Yes | Apache POI / xlsxwriter |
| Data Volume | Recommended Format | Approximate Generation Time |
|---|---|---|
| < 10,000 | CSV or XLSX | < 1 second |
| 10,000 – 100,000 | XLSX | 1–10 seconds |
| > 100,000 | CSV (batched) | 10+ seconds, progress needed |







