Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to force save_as to use different file_type than the extension. #182

Closed
rgacote opened this issue Jun 12, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@rgacote
Copy link

commented Jun 12, 2019

Need to write to an intermediate filename with a non-csv extension.
Example code:
pyexcel.save_as( array=rows, dest_file_name=filename.csv.prg, encoding="utf-8", dialect="excel" ) os.rename(progress_path, export_path)
Tried adding dest_file_type argument, but that looks to only work when I write to memory.
Is there a way to tell save_as this is a .csv file even though the extension is not .csv?

@chfw

This comment has been minimized.

Copy link
Member

commented Jun 12, 2019

yes, dest_file_type works only when the destination is a stream. I am afraid that pyexcel cannot do that ATM.

Let me think about it. It should not be a rocket science to get it supported. Your use case is symmetric to force file type on read: #148

@chfw chfw closed this in c4079dc Jun 12, 2019

@chfw chfw referenced this issue Jun 12, 2019

Merged

release 0.5.14 #183

@chfw

This comment has been minimized.

Copy link
Member

commented Jun 12, 2019

example usage:

    def test_force_file_type(self):
        pe.save_as(array=[[1, 2]], dest_file_name="a.txt",
                   dest_force_file_type='csv')
        actual = pe.get_array(file_name="a.txt", force_file_type="csv")
        eq_([[1, 2]], actual)
        os.unlink("a.txt")

    def test_force_file_type_for_save_book_as(self):
        pe.save_as(bookdict={"sheet1": [[1, 2]]}, dest_file_name="a.bin",
                   dest_force_file_type='xls')
        actual = pe.get_book_dict(file_name="a.bin", force_file_type="xls")
        eq_({"sheet1": [[1, 2]]}, actual)
        os.unlink("a.bin")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.