Load CSV document with options

This documentation outlines how to load CSV documents with configurable options using GroupDocs.Conversion for Java. It enables developers to handle and convert CSV files into various target formats (e.g., PDF, XLSX, DOCX) while providing fine-grained control over the loading and rendering process. The CsvLoadOptions class gives you the ability to set the following options:

OptionDescription
setSeparator()Specifies the delimiter.
setMultiEncoded()Whether true, this means that the document contains several encodings.
setFormula()Specifies that if text starts with “=” it should be parsed as a formula.
setConvertNumericData()Specifies that strings with digits should be parsed as numbers.
setConvertDateTimeData()Specifies that date/time strings should be detected and parsed to DateTime.
setEncoding()Specifies the encoding to be used during loading.

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:

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.SpreadsheetConvertOptions;
import com.groupdocs.conversion.options.load.CsvLoadOptions;

public class ConvertCsvByConvertingDateTimeAndNumericData {
    public static void convert() {
        CsvLoadOptions loadOptions = new CsvLoadOptions();;
        loadOptions.setConvertDateTimeData(true);
        loadOptions.setConvertNumericData(true);

        try(Converter converter = new Converter("sample.csv", () -> loadOptions)) {
            SpreadsheetConvertOptions options = new SpreadsheetConvertOptions();
            converter.convert("converted_with_data.xlsx", options);
        }
    }

    public static void main(String[] args){
        convert();
    }
}

sample.csv is sample file used in this example. Click here to download it.

converted_with_data.xlsx is converted XLSX document. Click here to download it.

Specify delimiter

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

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.CsvLoadOptions;

public class ConvertCsvBySpecifyingDelimiter {
    public static void convert() {
        CsvLoadOptions loadOptions = new CsvLoadOptions();;
        loadOptions.setSeparator(',');

        try(Converter converter = new Converter("sample.csv", () -> loadOptions)) {
            PdfConvertOptions options = new PdfConvertOptions();
            converter.convert("converted_with_delimiter.pdf", options);
        }
    }

    public static void main(String[] args){
        convert();
    }
}

sample.csv is sample file used in this example. Click here to download it.

converted_with_delimiter.pdf is converted PDF document. Click here to download it.

Specify encoding

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

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.CsvLoadOptions;

public class ConvertCsvBySpecifyingEncoding {
    public static void convert() {
        CsvLoadOptions loadOptions = new CsvLoadOptions();;
        loadOptions.setEncoding(java.nio.charset.Charset.forName("shift_jis"));

        try(Converter converter = new Converter("sample.csv", () -> loadOptions)) {
            PdfConvertOptions options = new PdfConvertOptions();
            converter.convert("converted_with_encoding.pdf", options);
        }
    }

    public static void main(String[] args){
        convert();
    }
}

sample.csv is sample file used in this example. Click here to download it.

converted_with_encoding.pdf is converted PDF document. Click here to download it.