Load Spreadsheet document with options

The GroupDocs.Conversion for Java library allows developers to load and manipulate spreadsheet files with advanced configuration using the SpreadsheetLoadOptions. This class provides a flexible approach for customizing how spreadsheet data is interpreted and loaded prior to conversion. For this the following options could be set:

OptionDescription
setFormat()Allows you to specify explicitly the type of the source spreadsheet document. Available options are: Xls, Xlsx, Xlsm, Xlsb, Ods, Ots, Xltx, Xlt, Xltm, Tsv, Xlam, Csv.
setDefaultFont()Sets a default font. The following font will be used if a spreadsheet font is missing.
setFontSubstitutes()Sets substitute specific fonts from the source spreadsheet document.
setShowGridLines()Specifies that grid lines should be visible.
setShowHiddenSheets()Specifies that hidden sheet should be included in the converted document.
setOnePagePerSheet()Specifies that one sheet from the spreadsheet must be converted to a single page.
setConvertRange()Specifies that a specific range of cells must be converted. Example: “D1:F8”.
setSkipEmptyRowsAndColumns()Specifies that empty rows and columns must be ignored.
setPassword()Specifies a password to unlock the protected document.
setHideComments()Specifies that comments from the source spreadsheet must be hidden during conversion.

These options enable precise handling of spreadsheet formats like XLS, XLSX, CSV, and others, simplifying the process of preparing files for conversion into a target format.

Hide comments

The following code snippet shows how to convert a spreadsheet and hide comments:

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

public class ConvertSpreadsheetAndHideComments {
    public static void convert() {
        SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
        loadOptions.setHideComments(true);
        loadOptions.setOnePagePerSheet(true);

        try(Converter converter = new Converter("cost-analysis.xlsx", () -> loadOptions)) {
            PdfConvertOptions options = new PdfConvertOptions();
            converter.convert("converted_without_comments.pdf", options);
        }
    }

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

cost-analysis.xlsx is sample file used in this example. Click here to download it.

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

Show grid lines

The following code snippet shows how to convert a spreadsheet and show grid lines:

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

public class ConvertSpreadsheetByShowingGridLines {
    public static void convert() {
        SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
        loadOptions.setShowGridLines(true);
        loadOptions.setOnePagePerSheet(true);

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

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

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

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

Skip empty rows and columns

The following code snippet shows how to convert a spreadsheet and skip empty rows and columns:

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

public class ConvertSpreadsheetBySkippingEmptyRowsAndColumns {
    public static void convert() {
        SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
        loadOptions.setSkipEmptyRowsAndColumns(true);
        loadOptions.setOnePagePerSheet(true);

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

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

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

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

Specify font substitution

The following code snippet shows how to convert a spreadsheet and specify font substitution for missing fonts:

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.contracts.FontSubstitute;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.SpreadsheetLoadOptions;
import java.util.ArrayList;
import java.util.List;

public class ConvertSpreadsheetBySpecifyingFontSubstitution {
    public static void convert() {
        SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();

        List<FontSubstitute> fontSubstitutes = new ArrayList<FontSubstitute>();
        fontSubstitutes.add(FontSubstitute.create("Aharoni", "Arial"));

        loadOptions.setOnePagePerSheet(true);
        loadOptions.setFontSubstitutes(fontSubstitutes);

        try(Converter converter = new Converter("cost-analysis.xlsx", () -> loadOptions)) {
            PdfConvertOptions options = new PdfConvertOptions();
            converter.convert("converted_with_fontsubstitution.pdf", options);
        }
    }

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

cost-analysis.xlsx is sample file used in this example. Click here to download it.

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

Specify range

The following code snippet shows how to convert a spreadsheet and specify the exact range of rows and columns to be converted:

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

public class ConvertSpreadsheetBySpecifyingRange {
    public static void convert() {
        SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
        loadOptions.setConvertRange("10:30");
        loadOptions.setOnePagePerSheet(true);

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

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

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

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

Include hidden sheets

The following code snippet shows how to convert a spreadsheet including the hidden sheets:

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

public class ConvertSpreadsheetWithHiddenSheetsIncluded {
    public static void convert() {
        SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
        loadOptions.setShowHiddenSheets(true);
        loadOptions.setOnePagePerSheet(true);

        try(Converter converter = new Converter("with_hidden_sheet.xlsx", () -> loadOptions)) {
            PdfConvertOptions options = new PdfConvertOptions();
            converter.convert("converted_with_hidden_sheets.pdf", options);
        }
    }

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

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

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