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

Write multiple sheets #18

Open
ruslanss opened this issue Jun 30, 2021 · 2 comments
Open

Write multiple sheets #18

ruslanss opened this issue Jun 30, 2021 · 2 comments

Comments

@ruslanss
Copy link

Is it possible to write multiple worksheets in a single file? I can't work out how to do it, tried this:

                using (FileStream fs = File.Create(fileName))
                {
                    ExcelWriter writer = null;
                    writer = new ExcelWriter(fs, "Sheet1", ci, true);
                    await writer.WriteRecordsAsync(data1);

                    writer = new ExcelWriter(fs, "Sheet2", ci, true);
                    await writer.WriteRecordsAsync(data2);

                    await writer.DisposeAsync();
                }

and end up with a workbook with a single sheet "Sheet2"

@motoyugota
Copy link

Since this is based on CsvHelper, I would guess it isn't possible to do multi-sheet workbooks, but I agree that would be excellent if it could.

@pynej
Copy link

pynej commented Jan 27, 2023

You can make it work pretty easily if you copy the ExcelWriter to you project and add a new constructor that takes the Sheet instead of the stream:

 public XlsxWriter(IXLWorksheet sheet, CultureInfo currentCulture, int startRow = 1, int startColumn = 1)
            : this(sheet, new CsvConfiguration(currentCulture), startRow, startColumn)
        {
        }

        public XlsxWriter(IXLWorksheet sheet, CsvConfiguration configuration, int startRow = 1, int startColumn = 1)
            : base(null, configuration)
        {
            _sheet = sheet;
            row = startRow;
            this.startColumn = index = startColumn;

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

No branches or pull requests

3 participants