Excel Reports
AddWorksheet(Workbook,String) Method
Example 



KellermanSoftware.ExcelReports Namespace > ExcelReportsGenerator Class > AddWorksheet Method : AddWorksheet(Workbook,String) Method
The workbook to add the worksheet to
The name of the worksheet
Add a worksheet to a workbook with a specified name
Syntax
Public Overloads Function AddWorksheet( _
   ByVal workbook As Workbook, _
   ByVal worksheetName As String _
) As Worksheet
Dim instance As ExcelReportsGenerator
Dim workbook As Workbook
Dim worksheetName As String
Dim value As Worksheet
 
value = instance.AddWorksheet(workbook, worksheetName)
public Worksheet AddWorksheet( 
   Workbook workbook,
   string worksheetName
)
public:
Worksheet^ AddWorksheet( 
   Workbook^ workbook,
   String^ worksheetName
) 

Parameters

workbook
The workbook to add the worksheet to
worksheetName
The name of the worksheet

Return Value

The worksheet that was added
Example
ExcelReportsGenerator generator = new ExcelReportsGenerator(); //Trial Mode
//ExcelReportsGenerator generator = new ExcelReportsGenerator("place user name here", "place license key here"); //License Mode
 
//Parameters
string filePath = "AddWorksheetNamedExample.xlsx";
 
Workbook workbook = generator.WorkbookFactory(filePath);
 
workbook.Author = "John Smith";
workbook.CreatedTime = DateTime.Now;
workbook.LastSavedBy = "John Smith";
workbook.Subject = "This is a subject";
workbook.Title = "This is a title";
 
Worksheet worksheet = generator.AddWorksheet(workbook, "Employees");
 
string csvString = @"FirstName,LastName,Married,NumberOfChildren,Salary,BirthDate
John,Smith,True,3,""$60,000"",12/15/1977
Joe,Jones,False,0,""$30,000"",6/25/1993";
 
generator.FillFromCsvString(worksheet, csvString);
generator.SaveWorkbook(workbook);
Dim generator As New ExcelReportsGenerator() 'Trial Mode
'Dim generator As New ExcelReportsGenerator("place user name here", "place license key here") 'License Mode
 
'Parameters
Dim filePath As String = "AddWorksheetNamedExample.xlsx"
 
Dim workbook As Workbook = generator.WorkbookFactory(filePath)
 
workbook.Author = "John Smith"
workbook.CreatedTime = Date.Now
workbook.LastSavedBy = "John Smith"
workbook.Subject = "This is a subject"
workbook.Title = "This is a title"
 
Dim worksheet As Worksheet = generator.AddWorksheet(workbook, "Employees")
 
Dim csvString As String = "FirstName,LastName,Married,NumberOfChildren,Salary,BirthDate" & ControlChars.CrLf & "John,Smith,True,3,""$60,000"",12/15/1977" & ControlChars.CrLf & "Joe,Jones,False,0,""$30,000"",6/25/1993"
 
generator.FillFromCsvString(worksheet, csvString)
generator.SaveWorkbook(workbook)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

ExcelReportsGenerator Class
ExcelReportsGenerator Members
Overload List