An RGF file is a file format that stores ReoGrid worksheet data, including styles, borders, formulas, and other spreadsheet information. RGF files can be saved by ReoGrid and ReoGridEditor.

The RGF file format is XML-based and describes a spreadsheet in the ReoGrid component. To save a spreadsheet as an RGF file, use the SaveRGF method of the worksheet instance:

worksheet.SaveRGF(path or stream);

To load a spreadsheet from an RGF file, use the LoadRGF method of the worksheet instance:

worksheet.LoadRGF(path or stream);

RGF file snapshot

Below is a sample snippet of RGF file content:

<?xml version="1.0"?>
<grid xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <head>
    <meta>
      <culture>en-US</culture>
      <editor>ReoGrid Core </editor>
      <core-ver>0.8.9.2</core-ver>
    </meta>
    <print-settings>
      <paper-size>A4</paper-size>
      ...
    </print-settings>
  </head>
  <style color="#000000" font="Arial" font-size="9.75" bold="true" align="left" valign="middle" />
  <rows>
    <row row="0" height="11" auto-height="false" />
    ...
  </rows>
  <cols>
    <col col="0" width="10" auto-width="false" />
    ...
  </cols>
  <v-borders>
    <v-border row="23" col="3" color="#000000" style="Solid" pos="left" rows="8" />
    ...
  </v-borders>
  <h-borders>
    <h-border row="3" col="1" color="#000000" style="BoldSolid" pos="top" cols="14" />
    ...
  </h-borders>
  <cells>
    <cell row="1" col="1" colspan="14" format="text">Project Cost Summary
      <style bgcolor="#00007d" color="#ffffff" font-size="20.25" align="center" />
    </cell>
    ...
  </cells>
</grid>

RGF file XML structure

Root element

<grid>
  ...
</grid>

head element

The head element stores basic information such as cell count, view settings, print settings, and so on.

meta element

The meta element stores metadata about the worksheet, such as culture information and the ReoGrid version. For example:

<meta>
  <culture>en-US</culture>
  <editor>ReoGrid Core</editor>
  <core-ver>0.8.9.2</core-ver>
</meta>

rows and cols element

The rows and cols elements store the maximum number of rows and columns in the worksheet. For example:

<rows>100</rows>
<cols>50</cols>

The print-settings element stores the print and printer settings for the current worksheet. For example:

<print-settings>
  <page-break-rows>0,42</page-break-rows>
  <page-break-cols>1,15</page-break-cols>
  <scale-factor>0.8637016</scale-factor>
  <paper-size>A4</paper-size>
  <landscape>true</landscape>
  <page-order>down-over</page-order>
</print-settings>

settings element

The settings element stores worksheet settings, such as whether to show grid lines or page break lines. For example:

<settings meta="2087944062">
  <show-page-break>true</show-page-break>
</settings>

style element

Style elements store style information for cells, rows, and columns. For example:

<style color="#000000" font="Arial" font-size="9.75" bold="true" align="left" valign="middle" />

row element

Row elements store row header information, such as row height and title. For example:

<row row="0" height="11" auto-height="false" />

column element

Column elements store column header information, such as column width and title. For example:

<col col="0" width="10" auto-width="false" />

h-border and v-border element

The h-border and v-border elements store border information for the spreadsheet. For example:

<v-border row="24" col="4" color="#000000" style="Dotted" pos="all" rows="7" />

cell element

Cell elements store cell information, such as cell data, cell styles, and data formats. For example:

<cell row="1" col="1" colspan="14" format="text">
  <style bgcolor="#00007d" color="#ffffff" font-size="20.25" align="center" />
  Project Cost Summary
</cell>

Saving images

When an instance of CellTypes.ImageCell is added to display an image inside a cell, the image is also saved in the RGF file and loaded from it. Images are stored as base64-encoded strings.

<cell row="0" col="0" body-type="ImageCell">image/png,iVBORw0KGgoAAAANSUhEUgA...M1P+eGgAAAABJRU5ErkJggg==</cell>

Saving and Loading

Single worksheet

Call the method from the worksheet instance to save or load a single worksheet:

// save
worksheet.SaveRGF(file or stream);
// load
worksheet.LoadRGF(file or stream);

Multiple worksheets or entire workbook

The current version of ReoGrid does not support saving and loading an entire workbook as a single RGF file. Applications should save and load each worksheet individually.

Here is a practice pattern for saving and loading a set of worksheets from a workbook:

Save multiple worksheets

var savingList = new List<string>();

foreach (var worksheet in reoGridControl.Worksheets)
{
  if (_ShouldSaveThisWorksheet_(worksheet) == true)
  {
    // save
    worksheet.SaveRGF(string.Format("C:\\MyPath\\{0}.rgf", worksheet.Name));

    // add worksheet name into saving list
    savingList.Add(worksheet.Name);
  }
}

Load multiple worksheets

foreach(var sheetName in savingList)
{
  // create worksheet instance with the given name
  var worksheet = reoGridControl.CreateWorksheet(sheetName);

  // load worksheet from stream
  worksheet.LoadRGF(string.Format("C:\\MyPath\\{0}.rgf", sheetName));
}

Target: Generic Stream

using(var ms = new MemoryStream())
{
  // save
  worksheet.SaveRGF(ms);
  // load
  worksheet.LoadRGF(ms);
}

Target: File

// save
worksheet.SaveRGF("C:\\MyPath\\MyFile.rgf");
// load
worksheet.LoadRGF("C:\\MyPath\\MyFile.rgf");

Target: Byte Array

byte[] buf = null;

// save
using (var ms = new MemoryStream())
{
  worksheet.SaveRGF(ms);
  buf = ms.ToArray();
}

// load
using (var ms = new MemoryStream(buf))
{
  worksheet.LoadRGF(ms);
}

### Target: String

string content = null;

// save
using (var ms = new System.IO.MemoryStream())
{
  sheet.SaveRGF(ms);
  content = Encoding.Default.GetString(ms.ToArray());
}

// load
using (var ms = new System.IO.MemoryStream(Encoding.Default.GetBytes(content)))
{
  sheet.LoadRGF(ms);
}

Difference from the Excel file format

There are some differences when saving a worksheet in ReoGrid format versus Excel format. For details, see Difference between Excel and RGF format.

Was this article helpful?