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

Function SaveTo to save file to writer #744

Closed
Donaldas opened this issue Dec 11, 2020 · 7 comments
Closed

Function SaveTo to save file to writer #744

Donaldas opened this issue Dec 11, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@Donaldas
Copy link

Hi,
it would be great to have possibility to pass unlocked file to io.Writer interface.

Use case:
Web service downloads excel files from cloud storage and processes it. In case excel file is password protected, service should unlock it with provided password and upload unlocked file back to cloud storage.

Description

Current implementation allows to save unlocked filed to the file on file system via:
func (f *File) SaveAs(name string, opt ...Options) error

New function SaveTo would allow to upload unlocked file without persisting it on file system.
func (f *File) SaveTo(w io.Writer, opt ...Options) (int64, error)

Other option would be to allow reset options in order to save unlocked file using:

func (f *File) Write(w io.Writer) error
func (f *File) WriteTo(w io.Writer) (int64, error)
func (f *File) WriteToBuffer() (*bytes.Buffer, error)

Thanks!

@xuri xuri added the enhancement New feature or request label Dec 13, 2020
@ronna-s
Copy link

ronna-s commented Sep 6, 2022

Any update on this from the contributors?

@xuri
Copy link
Member

xuri commented Sep 6, 2022

This library has added the WriteTo function since version 1.4.1, which can be used to save the file to the writer. I will add options support for it recently.

@ronna-s
Copy link

ronna-s commented Sep 6, 2022

Thanks for the quick reply @xuri I see the functions but they don't seem to set the contentType using the file extension as SaveAs does and that functionality is not exported (setContentTypePartProjectExtensions). I have a case for a file upload that doesn't need local storage.

@xuri
Copy link
Member

xuri commented Sep 6, 2022

Okay, thanks for your feedback. I will add support for it at this week.

@ronna-s
Copy link

ronna-s commented Sep 6, 2022

I can create a proposal PR. Against v2 or master?

@xuri xuri closed this as completed in fb1aab7 Sep 8, 2022
@xuri
Copy link
Member

xuri commented Sep 8, 2022

I have fixed this issue. Now the Save, Write and WriteTo function accept saving options, and here is an example for handle a workbook without a touch file system. Please upgrade to the master branch code, and this patch will be released in the next version.

xuri added a commit to carbin-gun/excelize that referenced this issue Oct 9, 2022
@itmecho
Copy link

itmecho commented Jan 11, 2023

Heads up for anyone who might've had the same issue as me related to this!

I've just upgraded to 2.7.0 and this change has broken my code as the *excelize.File type no longer implements the standard library io.WriterTo interface.

I've had to implement this wrapper type to get it to work again:

package server

import (
	"io"

	"github.com/xuri/excelize/v2"
)

type fileWriterTo struct {
	*excelize.File
}

// WriteTo implements io.WriterTo
func (f *fileWriterTo) WriteTo(w io.Writer) (n int64, err error) {
	return f.File.WriteTo(w)
}

func wrapFileWriteTo(f *excelize.File) io.WriterTo {
	return &fileWriterTo{f}
}

xuri added a commit to JDavidVR/excelize that referenced this issue Jul 11, 2023
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants