Excel Reports
FillFromCsvFile Method
Example 



KellermanSoftware.ExcelReports Namespace > ExcelReportsGenerator Class : FillFromCsvFile Method
The worksheet to fill
The path to the CSV file
Fill a worksheet using data from a CSV file
Syntax
Public Sub FillFromCsvFile( _
   ByVal worksheet As Worksheet, _
   ByVal csvFilePath As String _
) 
Dim instance As ExcelReportsGenerator
Dim worksheet As Worksheet
Dim csvFilePath As String
 
instance.FillFromCsvFile(worksheet, csvFilePath)
public void FillFromCsvFile( 
   Worksheet worksheet,
   string csvFilePath
)
public:
void FillFromCsvFile( 
   Worksheet^ worksheet,
   String^ csvFilePath
) 

Parameters

worksheet
The worksheet to fill
csvFilePath
The path to the CSV file
Example
ExcelReportsGenerator generator = new ExcelReportsGenerator(); //Trial Mode
//ExcelReportsGenerator generator = new ExcelReportsGenerator("place user name here", "place license key here"); //License Mode
 
//Parameters
string filePath = "FillWorksheetWithCsvFileExample.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";
 
File.WriteAllText("Input.csv", csvString);
 
generator.FillFromCsvFile(worksheet, "Input.csv");
 
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 = "FillWorksheetWithCsvFileExample.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"
 
File.WriteAllText("Input.csv", csvString)
 
generator.FillFromCsvFile(worksheet, "Input.csv")
 
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