ReoGrid
DOCUMENT
RGF format

A RGF file is a file format that contains ReoGrid worksheet data, stylesborders, formulas and other information to a spreadsheet. RGF file can be saved by ReoGrid and ReoGridEditor.

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

worksheet.SaveRGF(path or stream);

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

worksheet.LoadRGF(path or stream);

RGF file snapshot

Below is a piece 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 the basic information such as cells count, view settings, print settings and etc.

meta element

meta element stores the meta information of a worksheet, such as culture information and ReoGrid versions. 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 number of columns of the worksheet in this RGF file. For example:

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

The print-settings element stores the print and printer settings of 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 the worksheet settings, such as whether or not to show grid lines or print break lines. For example:

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

style element

Style elements store the style information to 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 stores the row header information, such as height of row and title of row. For example:

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

column element

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

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

h-border and v-border element

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

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

cell element

The cell elements store the cell information, such as cell data, cell styles, cell data format and etc. 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 image

When add an instance of CellTypes.ImageCell to show an image inside cell, the image will also be saved in RGF and loaded from a RGF. Image is stored as base64 string.

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

Saving and Loading

Single worksheet

By calling method from worksheet instance to save or load the single worksheet:

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

Multiple worksheet or entire workbook

Current version of ReoGrid does not support saving and loading entire workbook as RGF format. Application should save and load the worksheets by call the method from each worksheet.

This is a practice to save and load given worksheets from a workbook:

Save multiple worksheet

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 worksheet

foreach(var sheetName in savingList)
{
  // create worksheet instance by 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 between Excel file format

There is some difference when saving worksheet between ReoGrid format and Excel format, for details see Difference between Excel and RGF format.


Was the content of the page helpful?

© 2012-2024UNVELL Inc.