Reputation: 1
I have to make 2 business-like reports about media. Therefore I have to analyze data and give colleagues an excel file with multiple custom formatted tables.
Is there a way to make custom formatted tables in R or python and export them to excel?
This way I can automate formatting the 3000+ tables :)
Thanks in advance!
Upvotes: 0
Views: 313
Reputation: 2259
In R
you could use the xlsx
package to generate Excel files with customizable table formats. Here is an example that uses a list of data.frames to output one-table-per-Excel-sheet.
# some data in a list of dataframes
df1 <- data.frame(a = 1:5, b = 11:15, c = c(letters[1:5]))
df2 <- data.frame(a = 21:25, b = 111:115, c = c(letters[1:5]))
table_list = list(df1 = df1, df2 = df2)
library(xlsx)
# create workbook
wb <- createWorkbook()
# create column name style object
colnames_style <- CellStyle(wb) + Font(wb, isBold=TRUE)
# lapply with custom function
lapply(names(table_list),
function(df) {
sheet = createSheet(wb, df)
addDataFrame(as.data.frame(table_list[[df]]),
sheet = sheet,
row.names = FALSE,
colnamesStyle = colnames_style)
} )
saveWorkbook(wb, "table.xlsx")
Upvotes: 2
Reputation: 1899
You could try exploring the pandas library in Python (https://pandas.pydata.org/). After you've installed pandas, loaded your data and performed your analysis, it provides a function pandas.to_excel()
which outputs an excel document.
Upvotes: 0