Load CSV document with options

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Conversion MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-conversion -- dnx GroupDocs.Conversion.Mcp --yes
Folders, licensing and more →

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.