title: How to use xlsx package to insert blank column in Excel
body: <p>How can I insert a blank column into an existing Excel file while retaining the data in that column?</p>
  
  <p>I have time series data across multiple columns (one year per column) with summary data at the end (Min, Max, Percentiles).</p>
  
  <p>I want to use R to insert a column that contains a new year's data, but the code I have currently pastes on top of the summary data.</p>
  
  <p>Code has been generalized below:</p>
  
  <pre><code># Add necessary packages
  library(rJava)
  library(xlsx)
  library(xlsxjars)
  
  # Import data. Assume 1 column of data
  df &lt;- read.csv("file.csv", header = TRUE)
  
  # Create a workbook using library(xlsx) function
  workbook &lt;- loadWorkbook("existing_workbook.xlsx")
  
  # Import sheet names from above workbook
  sheets &lt;- getSheets(workbook)
  
  # Add the created dataframe into the workbook.
  # Assume the workbook has 100 existing columns and data is to be added to column 99
  addDataFrame(df, sheets$correct_sheet, startColumn = 99, row.names = FALSE)
  
  #Save the created workbook
  saveWorkbook(workbook, "R_Output.xlsx")
  </code></pre>
  
  <p>What this ultimately does is overwrite the data in column 99, which I would prefer be shifted one column to the right.</p>
  
  <p>Is this possible?</p>