Load CSV document with options

GroupDocs.Conversion provides CsvLoadOptions to give you control over how the source CSV document will be processed. The following options could be set:

OptionDescription
SeparatorSpecifies the delimiter 
AllColumnsInOnePagePerSheetIf true, all column content from a single sheet will be converted into a single page. The width of paper size of page setup will be ignored, while keeping the rest of page settings. 
AutoFitRowsIf enabled, automatically adjusts the content of all rows while converting. 
CheckExcelRestrictionWhether to check restrictions of Excel file when modifying cell objects. 
ConvertNumericData Specifies that strings with digits should be parsed as numbers
ConvertDateTimeData Specifies that date/time strings should be detected and parsed to DateTime
ConvertRange Defines a specific range of cells to be converted. For example: “D1:F8”
CultureInfo Specifies system culture info at the time file is loaded.
DefaultFontSpecify the default font to use if a document font is missing.
Encoding Specifies the encoding to be used during loading
FontSubstitutesSubstitute specific fonts from the source spreadsheet.
HasFormulaSpecifies that if text starts with “=” it should be parsed as a formula
HideComments Specify if the comments from the source spreadsheet should be hidden during conversion.
IsMultiEncodedIf true, this means that the document contains several encodings.
OnePagePerSheet If specified, each spreadsheet will be converted into a single page.
OptimizePdfSize If enabled, optimizes the resulting PDF for smaller file size, rather than for better print quality.
Password  Defines a password to unlock a protected document.
SheetIndexes Defines the indexes of the particular sheets to be converted.
Sheets Defines the names of the particular sheets to be converted.
ShowGridLines Specify if the grid lines should be visible.
ShowHiddenSheets Specify if the hidden sheets should be included in the converted document.
SkipEmptyRowsAndColumns Specify if empty rows and columns should be ignored.

Control behavior of converting date/time and numeric data

The following code snippet shows how to convert a CSV document and control the way the date/time and numeric data have been processed:

Contracts.Func<LoadOptions> getLoadOptions = () => new CsvLoadOptions
{
    ConvertDateTimeData = true,
    ConvertNumericData = true
};
using (Converter converter = new Converter("sample.csv", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

Specify delimiter

The following code snippet shows how to convert a CSV document and specify the delimiter:

Contracts.Func<LoadOptions> getLoadOptions = () => new CsvLoadOptions
{
    Separator = ','
};
using (Converter converter = new Converter("sample.csv", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

Specify encoding

The following code snippet shows how to convert a CSV document and specify the encoding:

Contracts.Func<LoadOptions> getLoadOptions = () => new CsvLoadOptions
{
    Encoding = Encoding.GetEncoding("shift_jis")
};
using (Converter converter = new Converter("sample.csv", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

Automatically fit rows

To fit the row content of all rows while converting, set the AutoFitRows property to true:

Contracts.Func<LoadOptions> getLoadOptions = () => new CsvLoadOptions
{
    AutoFitRows = true
};
using (Converter converter = new Converter("sample.csv", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}