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

Update multiple worksheets at onces #52

Open
piwonesien opened this issue Jun 16, 2020 · 3 comments
Open

Update multiple worksheets at onces #52

piwonesien opened this issue Jun 16, 2020 · 3 comments
Labels

Comments

@piwonesien
Copy link

piwonesien commented Jun 16, 2020

We have the situation that we want to fill an excel template that has several worksheets. Is there a better way to do this instead of:

using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(templateFile, outputFileTmp))
{
    fastExcel.Write(worksheet1, "sheet1", 1);
}
using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(new FileInfo(outputPathTmp), outputFile))
{
    fastExcel.Write(worksheet2, "sheet2", 1);
}
File.Delete(outputPathTmp);
@mrjono1
Copy link
Collaborator

mrjono1 commented Jun 19, 2020

I haven't tested this but this should work

using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(templateFile, outputFileTmp))
{
    fastExcel.Write(worksheet1, "sheet1", 1);
    fastExcel.Write(worksheet2, "sheet2", 1);
}
File.Delete(outputPathTmp);

@piwonesien
Copy link
Author

@mrjono1 yeah, it would be nice if this solution would work (that was also my first idea), but I'll get an error then:

System.Exception: 'Could not copy template to output file path'

IOException: The file '{...}' already exists.

@TorstenL
Copy link
Contributor

TorstenL commented Jul 7, 2020

Currently you have to reopen the file as a workaround.

using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(templateFile, outputFileTmp))
{
fastExcel.Write(worksheet1, "sheet1", 1);
}
using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(outputFileTmp))
{
fastExcel.Write(worksheet2, "sheet2", 1);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants