Skip to content
AI-powered appsNewChat, vision, voice, generationBookings & schedulingAppointments that book themselvesShops & sellingA storefront in every pocketClient & businessRun the operation from one placeCommunities & clubsA home that is not a group chat
Health & wellnessHabits, tracking and calmGames2D, 3D and multiplayerPersonal & toolsThe tool you wish existedInternal toolsThe tool ops never had time for
See all use cases
ArcadeNewPricingSecurity
EngineThe game engine and World EditorHow it worksFrom one sentence to a live productDocsGuides for building and publishingBlogStories, guides and newsChangelogWhat shipped latelyStatusUptime of every serviceSupportGet help from the team
AI-powered appsBookings & schedulingShops & sellingClient & businessCommunities & clubsHealth & wellnessGamesPersonal & toolsInternal tools
See all use cases
ArcadeNewPricingSecurity
EngineHow it worksDocsBlogChangelogStatusSupport
Language
Blog
IntegrationsNovember 22, 20265 min read

CSV Import and Export

Every business app eventually needs "import from a spreadsheet" and "download as CSV". Both look trivial and both have sharp edges. Here is how to build them so real files work.

Startbase Team
Editorial ink illustration of an open ledger beside a paper sorter fanning index cards into labeled trays, one flying index card in ember orange

Key takeaways

  • Import in four steps: upload, map columns, preview with row-level errors, then commit in batches. Never insert straight from the file.
  • Export with a UTF-8 byte order mark so Excel shows accents correctly, and neutralize cells that start with =, +, - or @.
  • Leading zeros, dates and decimal commas cause most bad imports. Decide how you read each one before users find out for you.

CSV import and export means letting users bring rows in from a spreadsheet and take their data out again as a file Excel, Numbers and Google Sheets can open. A solid import parses the file in the browser, lets the user match columns to your fields, shows a preview with every invalid row flagged, and only then saves valid rows in batches. A solid export writes UTF-8 with a byte order mark, quotes fields properly and defuses spreadsheet formulas. No third-party account is needed: it is your app, your database and a parsing library.

One distinction first. If you only need to load data into your own tables as the app owner, Startbase Cloud already does that: the Data section imports CSV files up to 5 MB with headers auto-mapped to columns, and exports a table (honoring your filter) up to 10,000 rows. This article is about the feature your users get inside the app you are building.

What you will build

An "Import contacts" flow and a "Download CSV" button for a CRM, inventory list, class roster, member directory or anything else that lives in rows. Users drop a file, see their columns matched to yours, fix or skip bad rows, and get a summary ("212 imported, 6 skipped, 3 duplicates updated"). Export gives them exactly what they see on screen, filters included.

What you need

  • A CSV parsing library in the browser (Papa Parse is the common choice for web apps). It handles quoted fields, commas inside quotes, line breaks inside cells and different delimiters.
  • A clear target schema. Which fields are required, their types and formats, and what makes two rows "the same" (email for contacts, SKU for products).
  • A database with access rules so an import can only write into the user's own workspace. On Startbase Cloud that means row level security on the table, or an edge function that checks membership before it writes.

The import flow, step by step

  1. 01Upload and parse locally. Read the file in the browser and parse it there. Nothing reaches your server until the user confirms. Cap the file size (5 to 10 MB is a sensible start) and the row count (say 20,000) and say so on the upload screen.
  2. 02Detect the basics. Delimiter (comma, semicolon or tab), whether row one is a header, and encoding. Files saved from Excel on European systems often use semicolons because the comma is the decimal separator there.
  3. 03Map columns. Show each of your fields with a dropdown of their columns, pre-filled by fuzzy name matching ("E-mail", "Email Address" and "email" all map to email). Let users mark columns to ignore. Remember the mapping for next time.
  4. 04Validate and preview. Run every row through the same validation your forms use. Show the first 20 rows plus a count of problems, with each bad cell highlighted and a reason ("not a valid email", "date not recognized", "required"). Offer: fix inline, skip invalid rows, or cancel.
  5. 05Decide on duplicates. For rows that match an existing record by your key, let the user choose: skip, update, or create anyway. Default to skip; overwriting someone's cleaned data silently is the worst outcome.
  6. 06Commit in batches. Send valid rows in chunks of about 500, so one failure does not lose everything and progress can be shown. Tag every inserted row with an import_id.
  7. 07Report and undo. Show the summary and keep an imports table (id, user, file name, counts, created_at). With the import_id on each row, "Undo this import" becomes a single delete.

The data that breaks imports

  • Leading zeros. ZIP codes like 02139, phone numbers and product codes lose their zeros if you treat them as numbers. Keep these fields as text from parse to database.
  • Dates. 03/04/2026 is March 4 in the US and 3 April almost everywhere else. Ask the user for the date format during mapping when the column is ambiguous, or detect it from values above 12. Store dates as ISO dates.
  • Decimal commas. "1.234,50" is one thousand two hundred thirty-four and a half in much of Europe. If you serve those users, let them pick the number format.
  • Encoding. Files from older Excel versions may not be UTF-8, and names like José turn into garbage. Try UTF-8 first and offer a "characters look wrong?" fallback to Windows-1252.
  • Blank lines and totals rows. Spreadsheets often end with empty rows or a "Total" line. Skip fully empty rows and flag rows that fail validation rather than crashing.

Export that opens cleanly everywhere

  • Add a UTF-8 byte order mark (the invisible character U+FEFF) at the start of the file. Without it, Excel on many systems misreads accented characters.
  • Quote properly. Wrap fields containing commas, quotes or line breaks in double quotes, and double any quotes inside. Use a library's unparse function rather than joining strings.
  • Defuse formulas. A cell starting with =, +, - or @ can run as a formula when opened in a spreadsheet, which is a known attack called CSV or formula injection. Prefix such text values with a single quote on export (leave real numeric columns, like negative amounts, as numbers).
  • Export what they see. Apply the current filters and sort, use human column names, and format dates as ISO (2026-11-22), which every spreadsheet understands.
  • Large exports on the server. For tens of thousands of rows, build the file in an edge function, save it to a private storage bucket and give the user a signed link, rather than holding everything in the browser.

A brief you can paste

Add CSV import and export to the Contacts page. Import: a dialog where I drop a CSV (max 10 MB, 20,000 rows), parsed in the browser with automatic delimiter detection. Step 2 maps their columns to our fields (name, email, phone, company, tags, notes) with smart pre-matching; email is required. Step 3 previews the first 20 rows, highlights invalid cells with a reason, and shows counts of valid, invalid and duplicate rows (duplicates matched by email, default skip, option to update). Commit valid rows in batches of 500 tagged with an import_id, show progress, then a summary with an Undo button. Keep phone numbers as text. Export: a Download CSV button that exports the current filtered view with a UTF-8 BOM, ISO dates, and any value starting with =, +, - or @ prefixed with a single quote.

Pitfalls

  • Inserting straight from the file. One bad row then fails the whole batch, or worse, half the rows land and the user cannot tell which. Validate first, commit second.
  • Trusting the browser's validation alone. The database should still enforce required fields and types, and access rules must stop a crafted request from writing into someone else's workspace.
  • No undo. People import the wrong file. An import_id on each row costs one column and saves support tickets.
  • Silent truncation. If you cap rows or skip invalid ones, say exactly how many and why. A downloadable "rows we skipped" CSV with an error column is the friendliest version.

If your app starts life as a spreadsheet, import is often the first feature users touch. Turn a spreadsheet into an app covers designing the tables that the import fills, and the inventory app guide shows a schema where SKU-based duplicate handling matters.

Frequently asked questions

Why does Excel show strange characters in my exported CSV?

Excel often assumes a legacy encoding unless the file starts with a UTF-8 byte order mark. Add the BOM character at the start of the export and accents display correctly.

How do I keep leading zeros when importing a CSV?

Treat columns like ZIP codes, phone numbers and product codes as text throughout: parse them as strings, validate them as strings, and store them in text columns.

What is CSV injection?

A cell value that starts with =, +, - or @ can be run as a formula when someone opens the file in a spreadsheet. Prefix such values with a single quote on export to keep them as plain text.

Should CSV parsing happen in the browser or on the server?

Parse and preview in the browser for instant feedback, then send validated rows to the server in batches. The server still enforces types and access rules before anything is saved.

On this page

  • What you will build
  • What you need
  • The import flow, step by step
  • The data that breaks imports
  • Export that opens cleanly everywhere
  • A brief you can paste
  • Pitfalls

Keep reading

More in Integrations
Editorial ink illustration of a folded paper street map with a brass compass and pushpins, the center pushpin in ember orange
IntegrationsNovember 22, 2026

How to add a map to your app

A map is two jobs: drawing tiles in the browser and turning addresses into coordinates. One key can be public, the other never should be.

6 min read
Editorial ink illustration of a carrier pigeon on a windowsill with a rolled note tied to its leg, the note in ember orange
IntegrationsNovember 22, 2026

How to send SMS from your app

Sending one text is ten lines of code. Sending texts people agreed to, that arrive, and that nobody can abuse, is the real work.

5 min read

Read less. Ship more.

Everything in this post is one prompt away. Describe your app and watch it build.

Start building

Apps, games, backends and publishing from one conversation.

Product

  • Features
  • Use cases
  • Pricing
  • Changelog

Resources

  • Blog
  • Docs
  • Support
  • Status
  • Security

Contact

  • w@startbase.ai
  • X / Twitter
  • LinkedIn
  • Instagram

Legal

  • Terms
  • Privacy

© 2026 Startbase. All rights reserved.