using System;
using esegece.sgcDocs;
using esegece.sgcGrid;
static class SalesReport
{
public static void Create()
{
using (var sheet = new TsgcDocsSpreadsheet())
{
sheet.New();
sheet.RenameSheet(0, "Sales");
// a header row and three data rows, from one and two dimensional arrays
sheet.SetRange("A1", new object[] { "Product", "Units", "Price", "Total" });
sheet.SetRange("A2", new object[,]
{
{ "Paper", 12, 4.5 },
{ "Toner", 3, 39.9 },
{ "Labels", 20, 2.75 }
});
// formulas, calculated by the engine and saved with the file
sheet.SetFormulas("D2", "=B2*C2");
sheet.SetFormulas("D3", "=B3*C3");
sheet.SetFormulas("D4", "=B4*C4");
sheet.SetValues("A5", "Total");
sheet.SetFormulas("D5", "=SUM(D2:D4)");
// a bold, centred header with a fill colour (ARGB)
TsgcGridCellFormat header = sgcGrid_CellFormat.sgcGridCellFormatEmpty();
header.Bold = true;
header.Alignment = TsgcGridAlignment.gaCenter;
header.FillColor = 0xFFDDEBF7;
sheet.SetFormat("A1:D1", header);
// a number format for the money columns
TsgcGridCellFormat money = sgcGrid_CellFormat.sgcGridCellFormatEmpty();
money.NumberFormat = "#,##0.00";
sheet.SetFormat("C2:D5", money);
// column widths in DIPs
sheet.SetColumnWidths("A", 140);
sheet.SetColumnWidths("D", 90);
sheet.Calculate();
Console.WriteLine("Total: " + sheet.Text("D5"));
sheet.SaveToFile("sales.xlsx");
}
}
}