Create excel file using data from two dataframes

The "rw" mode is a little dangerous, especially if your Excel document contains formulas (reference). Also, the do block form is more robust; it will always automatically close the file.

This is how I would do it.

using DataFrames, XLSX
df1 = DataFrame(
    A = [1, 2, 3, 4, 1],
    B= ["M", "F", "F", "M", "O"],
)
df2 = DataFrame(
    AA = ["aa", "bb"],
    AB = [10.1, 10.2],
)
filepath = "./xlsxtest.xlsx"
startrow = nrow(df1) + 3
startcolumn = 1

XLSX.openxlsx(filepath, mode="w") do file
    sheet = file[1]
    XLSX.writetable!(sheet, df1)
    XLSX.writetable!(sheet, df2, anchor_cell=XLSX.CellRef(startrow, startcolumn)) # or XLSX.CellRef("A8")
end

Additional options are shown in the documentation here.

2 Likes