API support for .xlsx files

Is it possible to work with .xlsx files via the API?

They work pretty well in AI Studio but I haven’t figured out how to upload them effectively via the API. I’ve tried a few mime types, text/plain, text/csv, text/xml. None seem to work.

What is best practice for working with these file types?

Hi @eanna

Currently, Gemini cannot process .xlsx files directly using files API. If you’re working with Excel data, consider converting it to a pandas DataFrame. You can then provide the DataFrame as input to Gemini and extract the necessary information.

Thanks

1 Like

Is it possible in the meantime to process xlsx and other Sheet file formats directly?
And how would I provide the DataFrame directly as input to Gemini?

Hi,

the MIME type of spreadsheet documents is not listed as supported.
Right now, I’d try to convert / export the sheets to CSV, XML, HTML or JSON and feed it to the API.

Cheers

1 Like

OK, so that means converting to one of several text-based formats … Is there any difference to be expected between just including that CSV, HTML or JSON directly in the prompt text or upload it separately as a file?
I mean ultimately it will all end up in a prompt, but does Gemini have any special tokens to enclose the uploaded files in which would make that approach preferable?

Hi @Johann_Petrak

I assume it would depend on your data and your preference.
See here: Explore document processing capabilities with the Gemini API  |  Google AI for Developers regarding what’s supported.

Cheers

1 Like