1

Solution must be in R. Related questions are providing solution for other languages. (e.g., here freeze top row using spreadsheetgear)

An Excel counterpart of

library(tidyverse)
mtcars %>% write_csv('IneedExcelNotCSV.csv')

with some part of code that freezez the top row.

Solution for similar format to .xls(x) (e.g., OpenOffice) would work too. (.sxc?)

userJT
  • 11,486
  • 20
  • 77
  • 88
  • 1
    [WriteXLS](https://cran.r-project.org/web/packages/WriteXLS/index.html)'s `WriteXLS` function has a `FreezeRow` argument where you specify the number of rows to be frozen. Perhaps something like this: `mtcars %>% WriteXLS::WriteXLS('MyFile.xls', FreezeRow = 1)`. – Dan Jun 07 '19 at 18:09
  • 1
    It is _impossible_ for a csv file. csv is a text format that does not support formatting. You must use xls or xlsx. – G5W Jun 07 '19 at 18:36
  • I know it is impossible in CSV. The code is there to illustrate. I am asking for Excel counterpart and plus some code. read the question! – userJT Jun 07 '19 at 19:14

2 Answers2

2

If you use the XLSX R package to save as .xlsx file you can add

 createFreezePane(sheet, 2, 1, startRow = 2, startColumn = 1)

and the first row is frozen.

fc9.30
  • 2,293
  • 20
  • 19
1

You can freeze panes when exporting data as an .xlsx file with the openxlsx package via the freezePane parameters: firstActiveRow, firstActiveCol, firstRow, and firstCol.

For example, to freeze the top row:

library(openxlsx)
write.xlsx(sheetname, file = filename, firstRow = TRUE) #freezes top row
write.xlsx(sheetname, file = filename, firstRow = TRUE, firstCol = TRUE) #freezes top row and first column
write.xlsx(sheetname, file = filename, firstActiveRow = 4, firstActiveCol = 3) #freezes fourth row and third column
coip
  • 1,312
  • 16
  • 30