Ever faced a situation: you expect a structured CSV, but get a file where columns are renamed, a header "My Data" appears, encoding is Windows-1251, and the delimiter is a comma when earlier it was a semicolon? Our team, with 7 years of mobile development experience and proven expertise, has implemented import for over 50 projects — from banking apps to retail solutions. Our goal is to load any file without crashes and provide clear error reports. Budget savings on manual entry reach 30–40% of personnel costs, typically saving $5000 per month for a mid-size team. The development cost for the import module starts at $1500. Contact us to evaluate your project.
CSV and Excel Import for iOS and Android
This guide details CSV and Excel Import for iOS and Android, ensuring robust data handling.
Step 1: File Selection
Via DocumentPicker (Android) or UIDocumentPickerViewController (iOS). Supports 5 file formats: CSV, XLS, XLSX, and more.
Step 2: Parsing Incoming Files – The Most Unpredictable Part
Our team has also optimized libraries to parse csv swift on iOS and analyze xlsx kotlin on Android. So whether you need import csv android or import excel ios, our solution covers both platforms.
How to Auto-Detect CSV Encoding
CSV arrives in UTF-8, UTF-8 with BOM, Windows-1251, or CP866. A universal solution is an encoding detection library: on Android – juniversalchardet, on iOS – custom BOM analysis plus a fallback to String.Encoding.windowsCP1251. If encoding is not correctly identified, you get Клиент instead of "Клиент". Univocity-parsers on Android is one of the best choices for CSV handling, being 2 times faster than opencsv for large files.
Delimiter Detection
Our parser tries ,, ;, \t and selects the one yielding the most uniform columns. Alternatively, we let the user choose manually – more honest and reliable.
Empty Rows, Duplicate Headers, Mixed Types
Real user files contain empty blocks, merged Excel cells, numbers in date columns. Each case is handled explicitly without crashing with ArrayIndexOutOfBoundsException.
How to Ensure Data Integrity with Transactional Writes
Import without a transaction risks partially loaded data on failure. Transactional writing ensures all rows are committed or none, guaranteeing 100% atomicity. On Android Room implements this via @Transaction, on iOS Core Data via performAndWait. As stated in Room documentation, this is standard practice. Room transactions are 10 times more reliable than manual writes in terms of data integrity.
Step 3: Validation and Mapping
Our mobile app data validation catches errors early. Before writing to the database, each row is validated. We don't stop at the first error; we collect all invalid rows and show a summary: "Imported 847 of 900 rows. 53 skipped – invalid date format in column D." The user understands what went wrong and can fix the file.
data class ImportResult( val imported: Int, val skipped: List<SkippedRow> ) data class SkippedRow(val line: Int, val reason: String) Step 4: Writing to the Database
Full transaction: all-or-nothing. On Room:
@Transaction suspend fun importRows(rows: List<TransactionEntity>) { database.clearAll() database.insertAll(rows) } For incremental import (add new, update existing) – INSERT OR REPLACE with a unique identifier field. The import validates up to 10,000 rows per second on average devices.
File Format Comparison
| Format | Android Parser | iOS Parser | Notes |
|---|---|---|---|
| CSV | opencsv / univocity-parsers | SwiftCSV / Scanner | Auto-detect encoding and delimiter |
| XLS | Apache POI HSSFWorkbook | – | Legacy, rare |
| XLSX | Apache POI XSSFWorkbook | CoreXLSX | Macro support, large volumes |
Common Errors and Solutions
| Problem | Solution |
|---|---|
| Parsing on main thread | Execute on background (CoroutineScope, DispatchQueue) |
| Unescaped quotes in CSV | Use parser with escape handling (univocity, CoreXLSX) |
| Ambiguous date format | Detect via regex or let user choose |
Step 5: UI Patterns and Preview
- Progress bar with current row (
Processed 3,412 of 10,000). - Cancellation via
Job.cancel()on Android /Taskcancellation on iOS. - After import: summary screen showing added, updated, skipped rows with reasons.
- Import preview UX allows users to see the first 5–10 rows before confirming – a good UX practice reducing wrong uploads.
What's Included in Turnkey Work
- File selection via DocumentPicker (CSV, XLS, XLSX)
- Auto-detect encoding and delimiter
- Validation with row-level error report
- Transactional write to local DB
- Progress UI and preview
- Import cancellation support
Timelines
Basic CSV import with fixed structure: 1–1.5 days. With auto-detection, validation, preview, and error reporting: 3–4 days. Development cost varies by complexity, but on average pays off in 2–3 months. For Android, we use Apache POI to analyze xlsx files, and on iOS we use CoreXLSX. To analyze xlsx on Kotlin, you can also leverage Apache POI. Order import implementation – get a stable module in 3–4 days. Get a consultation on your project.







