title: How to format Excel file output in R
body: <p>I'm writing a code that reads a CSV file, and generates two XLSX files, depending if the sites needed updates and where the location is. For example I would have sample data such as: </p>
  
  <p><img src="https://i.stack.imgur.com/3SjcX.png" alt="Data example 1 "></p>
  
  <p>And the issue I'm having now, is that I want to apply Excel table style "Olive Green, Table Style Medium 18". I have an option where I have to pass a workbook, but since I'm not directly creating a workbook but rather reading a CSV file, how would I continue this? </p>
  
  <p>Right now, I'm just using <code>write.xlsx()</code> to export my data to Excel, but I would like to apply a formatting to the table. </p>
  
  <p>Sample code: </p>
  
  <pre><code>#Determine the input and output parameters 
  input_file &lt;-  choose.files()
  output_eu &lt;- "eu.xlsx"
  output_noteu &lt;- "noteu.xlsx"
  
  #list of EU countries 
  eu &lt;- c("Andorra","Austria","Belarus","Belgium","Bosnia and Herzegovina","Bulgaria","Croatia","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Iceland","Ireland","Italy","Latvia","Liechtenstein","Lithuania","Luxembourg","Malta","Moldova","Monaco","Montenegro","Netherlands","Norway","Poland","Portugal","Romania","Russia","San Marino","Serbia","Slovakia","Slovenia","Spain","Sweden","Switzerland","Ukraine","United Kingdom")
  
  #reading the csv table
  d &lt;- read.table(input_file, sep = ";", header = TRUE, check.names = FALSE) 
  
  # get all cases where there is some text in the Update field
  updates &lt;- d[d$Update != "", ]
  
  #within updates are there countries in EU
  i &lt;- updates$Country %in% eu
  
  eu_up &lt;- updates[i,]
  noteu_up &lt;- updates[!i,]
  
  #Creating the excel files 
  library(openxlsx)
  write.xlsx(eu_up, output_eu) 
  write.xlsx(noteu_up, output_noteu)
  </code></pre>
  
  <p>Update1: Added the sample code to show that I use 1 CSV file that goes into two excel files. </p>
  
  <p>Updated Code: </p>
  
  <pre><code>#Determine the input and output parameters 
  input_file &lt;-  choose.files()
  output_eu &lt;- "eu.xlsx"
  output_noteu &lt;- "noteu.xlsx"
  
  #list of EU countries 
  eu &lt;- c("Andorra","Austria","Belarus","Belgium","Bosnia and Herzegovina","Bulgaria","Croatia","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Iceland","Ireland","Italy","Latvia","Liechtenstein","Lithuania","Luxembourg","Malta","Moldova","Monaco","Montenegro","Netherlands","Norway","Poland","Portugal","Romania","Russia","San Marino","Serbia","Slovakia","Slovenia","Spain","Sweden","Switzerland","Ukraine","United Kingdom")
  
  #reading the csv table
  d &lt;- read.table(input_file, sep = ";", header = TRUE, check.names = FALSE) 
  
  # get all cases where there is some text in the Update field
  updates &lt;- d[d$Update != "", ]
  
  #within updates are there countries in EU
  i &lt;- updates$Country %in% eu
  
  eu_up &lt;- updates[i,]
  noteu_up &lt;- updates[!i,]
  
  
  #importing openxlsx library 
  library(openxlsx)
  
  #create the workbook for each one 
  wb_eu &lt;- createWorkbook()
  wb_xeu &lt;-createWorkbook()
  
  #adding the data to each corresponding workbook 
  addWorksheet(wb_eu, "European Sites") 
  addWorksheet(wb_xeu, "Non-European Sites")
  
  #write our tables into each 
  writeDataTable(wb_eu, 1, eu_up, startRow=1, startCol=1, tableStyle="TableStyleLight11")
  writeDataTable(wb_xeu, 1,  noteu_up, startRow=1, startCol=1, tableStyle="TableStyleLight11")
  
  #setting our column widths 
  setColWidths(wb_eu, 1, cols=1:26, widths = "auto") 
  setColWidths(wb_xeu, 1, cols=1:26, widths = "auto") 
  
  #saving our workbooks 
  saveWorkbook(wb_eu, "European Sites updated.xlsx", overwrite = TRUE) 
  saveWorkbook(wb_xeu, "Non-European Sites updated.xlsx", overwrite = TRUE) 
  </code></pre>