I haven´t thought about that, but it turns out it just works. As long as your data cells has no formatting applied to them. I would say this gets unstable, so might not work in a complicated workbook.
import XLSX
f = XLSX.openxlsxtemplate("fig_template.xlsx") # opens existing excel file with figure as template
s = f[1] # gets the first worksheet
using DataFrames
df = DataFrame(X=[1,2,3,4,5,6], Y=[0.2, 0.3, 0.4, 0.5, 0.1, 1])
XLSX.writetable!(s, DataFrames.columns(df), DataFrames.names(df)) # write table to worksheet
XLSX.writexlsx("out.xlsx", f) # saves as new excel file
I guess I should improve the package to leave unedited worksheets untouched when saving the Excel file. So you would be able to export data to a worksheet with no formats using Julia, and write a pretty report on another worksheet.
It looks like this problem is not with XLSX but with this line
sheet["C2:C61"] = value.(B)
specifically the function value not being known as the ERROR message suggests: “no method matching value(::Float64)”. What was the function there for?
For me sheet["C2:C61"] wouldn’t work (although it did in an example) but replacing the above line with this:
sheet["C2", dim = 1] = B
seemed to work the way you intended it.
Finally, I think it could benefit your post if you read this suggestions to improve posts for help. In this case, for example, quoting your code, making sure it runs if someone want’s to try it (I happened to know I need to import Distributions but maybe that’s not the case for everyone), or creating a separate thread for your question.
Thank you very much for your help, It was very useful. I will consider your tips for upcoming questions. It was my first time participating in a forum.
Hi Felipe, I have a problem with XLSX. I would like to export results from Julia to an excel file. However, it tells me that excel file already exists in my file although it doesn’t.
I don’t think it is a good idea to revive a 3 year old posting to get help.
As your problem description is a bit vague I’ll try to guess.
It is a bit annoying that this package does not set the file date (at least on win), hence you sometimes just don’t find the file because it is not where you think it should be, if you are sorting by most recent files.
Anyway, you can just try the overwrite mode like so