Skip to content

Unable to write xlsx data into memory stream #38

@yoliva

Description

@yoliva

Hi, I'm unable to get the bytes of the xlsx file from the MemoryStream. the code in approach 1 generates the file but in approach 2 I get always an empty byte[]. What I'm missing here? thanks!

Approach 1:
            using (var writer = new ExcelWriter("test_123.xlsx"))
            {
                writer.WriteRecords(sections.ToList());
            }

Approach 2:
            using var stream = new MemoryStream();
            using var writer = new ExcelWriter(stream, CultureInfo.InvariantCulture);
            {
                writer.WriteRecords(sections.ToList());
            }

            var data = stream.ToArray();
            var fileName = $"{DateTime.UtcNow.ToStandardFullFormat()}.{FileExtensions.XLSX}";

            return new DataFile(fileName, ContentTypes.XLSX, FileType, data);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions