PydPiper / pylightxl

A light weight, zero dependency, minimal functionality excel read/writer python library
https://pylightxl.readthedocs.io
MIT License
303 stars 47 forks source link

Feature request: writing csv files to stream, not just file paths #22

Closed infokiller closed 4 years ago

infokiller commented 4 years ago

AFAIK, doing an in-memory conversion from xlsx to csv is cumbersome right now, because writecsv doesn't allow writing to any stream like io.StringIO

PydPiper commented 4 years ago

Hi there good morning,

Thank you for considering using pylightxl and submitting a feature improvement. This should be any easy addin. I can cook this up later today and let you know when it is done

PydPiper commented 4 years ago

i started working on this and realized i might not have all the information i need from your request. Can you add a bit more clarification?

would you like the writecsv return a in memory string? ex: "THIS,THAT\nONE,TWO\n"

infokiller commented 4 years ago

I think the most flexible and backwards compatible way would be to have it write to a file object, which can be either a real opened file or something like io.StringIO. So you would change the second parameter of writecsv to accept one of str, pathlib.Path, or file-like. The latter is what csv.writer accepts.

PydPiper commented 4 years ago

take a look at the latest commit on master branch. I wrote some tests against it as well so it should work 👍

infokiller commented 4 years ago

Thanks, that works!