Can we write a dataframe (without headers) to a specified sheet and specified cell in Excel? I have a dataframe that I want to write to a specific sheet in a spreadsheet. Consider this dataframe
df = DataFrame(Name=["aaaa","bbbb","cccc"], Type = [1,2.0,5.5])
I have a spreadsheet “MyXLfile.xlsx” which has a tab called “Required_tab”, and I want to write this dataframe df (without headers) to the cell starting A1 in this tab.
Yes, I have gone through documentation of XLSX. The examples given in documentation either write single values to cells or just write a dataframe by creating a new Excel file: https://felipenoris.github.io/XLSX.jl/stable/tutorial/#Writing-Excel-Files
I have tried the code below but it gives an error message
XLSX.openxlsx("MyXLfile.xlsx", mode="rw") do xf
sheet = xf["Required_tab"]
sheet["A1"] = XLSX.writetable(sheet, collect(DataFrames.eachcol(df1)), DataFrames.names(df1))
end
The code below also doesn’t work
XLSX.openxlsx("MyXLfile.xlsx", mode="rw") do xf
sheet = xf["Required_tab"]
sheet["A1"] = df1
end
Maybe @felipenoris can point me in the right direction
using DataFrames
using XLSX
df = DataFrame(Name=["aaaa","bbbb","cccc"], Type = [1,2.0,5.5])
XLSX.openxlsx("MyXLfile.xlsx",mode="rw") do xf
XLSX.addsheet!(xf,"Required_tab")
sheet = xf["Required_tab"]
for r in 1:size(df,1), c in 1:size(df,2)
sheet[XLSX.CellRef(r , c )] = df[r,c]
end
end