Excel

Creating Workbooks and Sheets

WithNewFile starts a workbook of your own at the name given, holding one sheet and nothing else. WithNewSheet adds a sheet and works on it from there, called once for each tab the workbook is to hold. InputFrom writes a grid into the sheet, at the cell WithCell named or A1, and is how data of your own gets into a workbook: every other method here moves data the workbook already held. Nothing reaches the disk until SaveTo or Close(true), the same as a workbook that was loaded.

NOTE

GPAL.Converter turns one format into another and writes a single sheet, because the tab layout it uses comes from a workbook it read. Anything with more than one tab is authored here.

Examples

GPAL Fluent: High-level fluent C# API

//WithNewFile names the file and gives you Sheet1 to work on. WithSheet(1) selects it, InputFrom fills it from A1, then WithNewSheet adds the second tab and InputFrom fills that one. SaveTo writes the file and Close(true) releases it. Write to a cell other than A1 by naming it with WithCell before InputFrom.

// a workbook of two sheets, built from grids and saved

GPALFile book = @"C: eportsmonth.xlsx";


IGPALGrid<string> sales = GPAL.GridForType<string>();


sales.AddRow(new List<string> { "Name", "Tally" });

sales.AddRow(new List<string> { "row one", "10" });


IGPALGrid<string> places = GPAL.GridForType<string>();


places.AddRow(new List<string> { "Code", "City" });

places.AddRow(new List<string> { "TX", "Austin" });


GPAL.Excel.ToGPALObject()

.WithNewFile(book)

.WithSheet(1)

.InputFrom(sales)

.WithNewSheet("Places")

.InputFrom(places)

.SaveTo(book)

.Close(true);

💬 Ask GPAL