Spreadsheets and Excel
Using ES3Spreadsheet, Easy Save has the ability to create spreadsheets and store them in the CSV format which is supported by all popular spreadsheet software included Excel, OSX Numbers and OpenOffice.
Saving to spreadsheet
To create a spreadsheet, you can do the following:
- Create an ES3Spreadsheet object.
- Use SetCell to set the value of a cell.
- Note that columns and row numbers start at 0.
- If the value isn’t a primitive type, the value will be converted to JSON.
- Use Save to store the spreadsheet to a file.
1 2 3 4 5 6 7 8 |
var sheet = new ES3Spreadsheet(); // Add data to cells in the spreadsheet. for(int col=0; col<10; col++) for(int row=0; row<8; row++) sheet.SetCell(col, row, "someData"); sheet.Save("mySheet.csv"); |
Appending rows to a spreadsheet
If you want to append data to an existing spreadsheet, set the append parameter to true when calling Save(). Any rows in the spreadsheet will be added to the end of the one we’re saving to.
Loading a spreadsheet
To load a spreadsheet:
- Create an ES3Spreadsheet object to load the data into.
- Use Load to load the spreadsheet from a CSV file.
1 2 3 4 5 6 7 8 |
// Create a blank ES3Spreadsheet. var sheet = new ES3Spreadsheet(); sheet.Load("spreadsheet.csv"); // Output the first row of the spreadsheet to console. for(int col=0; col<sheet.ColumnCount; col++) Debug.Log(sheet.GetCell<int>(col, 0)); |
Limitations
Currently ES3Spreadsheet is unable to do the following, but may have these implemented in the future:
- Save formulas.
- Store formatting or styling information.
- Save multiple worksheets.