I have an API which get csv file in the request and all I need to do is format and send the response as excel file. I am reading the data into dataframe and directly writing into excel.
The issue is that writing data into excel itself taking around 26 seconds and in total it’s taking around 3 mins(sometimes taking even more than that) which includes writing into excel file and reading the content from buffer for around 370k (70 - 80 MB) records.
I have added the code which I have currently written.
df = CSV.read(data, DataFrame)
@info "Rows **", nrow(df)
filename = "data.xlsx"
filecontent = @time create_excel_file(df)
HTTP.Response(200, [
"Content-Type" => "application/vnd.ms-excel",
"Content-Disposition" => "attachment; filename=\"$filename\""
], body=filecontent)
function create_excel_file(df)
# Create an in-memory buffer for the Excel file
io = IOBuffer()
XLSX.openxlsx(io, mode="w") do xf
sheet = xf[1]
@time XLSX.writetable!(sheet, collect(DataFrames.eachcol(df)), DataFrames.names(df))
end
return take!(io)
end