Worksheet Extensions

Add

Specification

Add an IEnumerable data starting from the cell.

Usage

// get worksheet
var sheet = package.Workbook.Worksheets["Sheet1"];
// get starting cell
var startingCell = sheet.GetCell(1, 1);
// create a test list of data
var listOfData = new List<string> {"test1", "test2", "test3"};

// do add
// return an excelrange with starting and ending cells
// InsertDirection can be Across or Down
var modifiedCells = sheet.Add(startingCell, InsertDirection.Across, listOfData);

// or
package.Workbook.Worksheets["Sheet1"].Add(startingCell, InsertDirection.Across, listOfData);

GetCellValue

Specification

Get a strongly type cell value

Usage

// get worksheet
var sheet = package.Workbook.Worksheets["Sheet1"];
// set cell value
sheet.SetCellValue(1, 1, "test");

// get cell value
var cellValue = sheet.GetCellValue<string>(1, 1);
// or
var cellValue = sheet.GetCellValue(1, 1, string.Empty);
// or
var cellValue = package.Workbook.Worksheets["Sheet1"].GetCellValue(1,1, string.Empty);

GetCell

Specification

Get an excel cell

Usage

// get worksheet
var sheet = package.Workbook.Worksheets["Sheet1"];
// set cell value
sheet.SetCellValue(1, 1, "test");

// get cell
var cell = sheet.GetCell(1, 1);

GetColumn

Specification

Get an excel column

Usage

// get worksheet
var sheet = package.Workbook.Worksheets["Sheet1"];
// get column
var column = sheet.GetColumn(1, 1);

GetRow

Specification

Get an excel row

Usage

// get worksheet
var sheet = package.Workbook.Worksheets["Sheet1"];
// get row
var row = sheet.GetRow(1, 1);

SetCellValue

Specification

Set a strongly type value to a cell value

Usage

// get worksheet
var sheet = package.Workbook.Worksheets["Sheet1"];
// set cell value
var cell = sheet.SetCellValue(1, 1, "testvalue");
// or
package.Workbook.Worksheets["Sheet1"].SetCellValue(1, 1, "testvalue");

Last edited Dec 27, 2010 at 9:15 AM by akronite, version 3