Excel Data Serializer

Excel Data Serializer


When defining game master data, there is always several requirements are followed.
one can write data set with easy?  Is it easily (means simply and with low cost) applied to game client or server?

The Excel made by Microsoft is widely used for organizing data. It could contain formula, macro, and cell referencing, etc. So, using this tool has lots of merits for organizing and sharing data set.

In this chapter, I will introduce one method about how to use excel file for game master data packaging.

Overall Design Concept

The main concept of excel data serializer is building continuous data generating pipe line(fig.1).

Fig.1 Overall data pipe line

Write down master data into excel, compile (I prefer to calling it cooking) excel, then related header and binary stream file are generated. It’s so simple and effective.

(if you need more detailed description, please comment it)

Excel File Handler

The Excel file could be handled Microsoft Office COM. But the problem is it is too slow just for reading mode. Because COM implements all redundant functions not required, it is still usable but need to improve handling speed.

As alternative loading tool, I choose Open XML(https://docs.microsoft.com/en-us/office/open-xml/open-xml-sdk). It’s quite fast and handy(because it’s not COM, the dependency with Microsoft Office installation could be removed).

the loading speed with OpenXML SDK is so fast compared with Office COM, I recommend using it though it needs a little more efforts(empty cell handling, macro handling, etc).

However, OpenXML SDK is good.


The handler (aka. Generator) ‘s main role is verifying excel file, generating header and serializing excel data into binary stream file.

For defining master data’s structure, I will preserve certain cell region as meta data(fig. 2).

Fig2. Defining meta data

This meta field could be converted as below(like class definition).

Fig.3 meta data into class declaration

And, again this class definition could be parsed with Protocol Generator for producing header and related binary stream loader/saver.


Once the class definition is generated from meta data and it’s ready to package(passed certain verifications), the actual cell data is convert into binary stream.

You may iterate all columns and rows one by one while matching structure variables. Or you may use specific functionality of C# language – ie. System.Reflection.

What I choose is using System.Reflection and embedded into Protocol Generator. One shot, multiple kill. J

Additional Consideration

You could give some modification onto meta data declaration in order to support multi rows with same key.

What it means is, as of above declaration, each row occupies exactly one structure. But you may implement excel loader packaging certain amount rows are mapped into one single row as List type and furthermore, could bind certain columns into structure(fig.4).

Fig.4 declaring custom type on Excel

Let’s suppose you want to support list or map type. A list or map contains certain amount of elements. We need to write down total count at first so we could decode memory stream just fit whole amount of items as it.

If you define List variable with int32 type, you could notation it like below

List<int32> someList;

let’s add some values. ie. {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

The Variable ‘someList’ has 10 items and could be serialized as below

Detailed Implementation

Coming Soon

Leave a Reply