示例#1
0
    public void Save(string path, ES2Settings settings)
    {
        if (append)        // If append is enabled, set file stream to append.
        {
            settings.fileMode = ES2Settings.ES2FileMode.Append;
        }

        using (ES2Writer writer = ES2Writer.Create(path, settings))
        {
            for (int rowNo = 0; rowNo < sheet.Count; rowNo++)        // For each row ...
            {
                ES2SpreadsheetRow row = sheet[rowNo];

                if (row != null)                                        // If row is set ...
                {
                    for (int colNo = 0; colNo < row.cellCount; colNo++) // Write each cell.
                    {
                        if (colNo != 0)                                 // Only prepend a comma if this isn't the first column.
                        {
                            writer.WriteRaw(comma);
                        }
                        writer.WriteRaw(row.GetCellBytes(colNo));
                    }
                }
                writer.WriteRaw(newline);                  // Write a newline to signify the end of the row.
            }
            writer.Save(false);
        }
    }
示例#2
0
 /*
  *      Sets the cell at the given column and row, expanding the spreadsheet if necessary.
  *      Uses ToString() to get the string representation of the object.
  */
 public void SetCell(int col, int row, object value)
 {
     SizeSpreadsheetToFitRow(row);
     if (sheet[row] == null)
     {
         sheet[row] = new ES2SpreadsheetRow();
     }
     sheet[row].SetCell(col, value.ToString());
 }
示例#3
0
    public string GetCell(int col, int row)
    {
        int highestRow = sheet.Count - 1;

        if (highestRow <= row || sheet[row] == null)
        {
            return(null);
        }

        ES2SpreadsheetRow rowObject = sheet[row];

        if (rowObject == null)
        {
            return(null);
        }
        return(rowObject[col]);
    }
示例#4
0
    public override string ToString()
    {
        string str = "";

        for (int i = 0; i < sheet.Count; i++)
        {
            if (i != 0)
            {
                str += "\n";
            }
            ES2SpreadsheetRow row = sheet[i];
            if (row == null)
            {
                str += "{}";
            }
            else
            {
                str += row.ToString();
            }
        }
        str += "}";
        return(str);
    }