# Print

DsExcel is a Document Solutions product that offers a comprehensive library to create, manipulate, convert, and share Microsoft Excel-compatible spreadsheets.

## Content

DsExcel.NET allows you to output a workbook or worksheet to a printer using the `PrintOut` method provided by [IWorkbook](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IWorkbook.html) and [IWorksheet](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IWorksheet.html) interface respectively. This method accepts object of [PrintOutOptions](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.html) class as a parameter. In the background, `PrintOut` method uses DsPdf to print workbook to a printer. Hence, you need to reference [DS.Documents.Imaging.Windows](https://developer.mescius.com/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Imaging.Windows/GrapeCity.Documents.Imaging.Windows.html) to implement the feature.

>type=note
> **Note**:
>
> * The `PrintOut` method works only on the Windows environment.
> * To print in other environments, you can export the document to PDF and then take a print of the converted document. For information on exporting a spreadsheet to PDF, see [Export to PDF](/document-solutions/dot-net-excel-api/docs/online/ManageFileOperations/ExporttoaPDFFile).

## Print Options

DsExcel.NET provides [PrintOutOptions](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.html) class that contains various properties and events to set printing options such as printer name, number of copies, double-sided printing, first and last page to be printed, and selecting the printer paper source (input tray), etc. The following table lists all available properties:

| Property | Description |
| -------- | ----------- |
| [ActivePrinter](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.ActivePrinter.html) | Name of the target printer. Must match the printer name exactly as registered in the system. |
| [Copies](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.Copies.html) | Number of copies to print. |
| [Collate](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.Collate.html) | When printing multiple copies, true collates pages (1-2-3, 1-2-3); false groups them (1-1, 2-2, 3-3). |
| [Duplex](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.Duplex.html) | Double-sided printing mode. Only effective when the printer supports duplex printing. |
| [From](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.From.html) | Index of the first page to print (1-based). |
| [To](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.To.html) | Index of the last page to print (1-based). |
| [PaperSourceName](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.PaperSourceName.html) | By default, when printing a workbook or worksheet, DsExcel .NET uses the printer's driver-default paper source(input tray). If your printer has multiple trays loaded with different paper types or sizes, you can use the [PaperSourceName](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.PaperSourceName.html) property of [PrintOutOptions](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.html) to specify which tray to use. The name is matched case-insensitively against the paper sources reported by the target printer driver.<ul><li>If PaperSourceName is null (the default), the printer uses its default paper source.</li><li>If the specified name is not found for the target printer, an ArgumentException is thrown.</li></ul> |
| [PrintBackgroundPicture](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.PrintBackgroundPicture.html) | Indicates whether the worksheet's background image will be printed on the page. |
| [PrintTransparentCell](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.PrintTransparentCell.html) | Indicates whether the transparency of the cell's background color is preserved when printing. |
| [ShrinkToFitSettings](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.ShrinkToFitSettings.html) | Provides settings for performing "shrink to fit" on wrapped text during printing. |

To print a document with specified printing options, you need to create an instance of the [PrintOutOptions](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.html) class, define the options for that instance and pass that instance while calling the [PrintOut](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IWorkbook.PrintOut.html) method.
The following example demonstrates how to configure print options to match your printer's capabilities and your printing requirements.

```csharp
// Create a workbook and set data.
var workbook = new Workbook();
IWorksheet worksheet = workbook.Worksheets[0];

object[,] data = new object[,]
{
    { "Name",    "City",       "Birthday",                 "Eye color", "Weight", "Height" },
    { "Richard", "New York",   new DateTime(1968, 6, 8),   "Blue",      67,       165 },
    { "Nia",     "New York",   new DateTime(1972, 7, 3),   "Brown",     62,       134 },
    { "Jared",   "New York",   new DateTime(1964, 3, 2),   "Hazel",     72,       180 },
    { "Natalie", "Washington", new DateTime(1972, 8, 8),   "Blue",      66,       163 },
    { "Damon",   "Washington", new DateTime(1986, 2, 2),   "Hazel",     76,       176 },
    { "Angela",  "Washington", new DateTime(1993, 2, 15),  "Brown",     68,       145 }
};
worksheet.Range["A1:F7"].Value = data;
worksheet.Range["A:F"].ColumnWidth = 12;
worksheet.Tables.Add(worksheet.Range["A1:F7"], true);

var options = new PrintOutOptions();

// Set the name of the target printer.
options.ActivePrinter = "Gestetner MP C3503 PCL 6";

// Print 3 copies, collated (1-2-3, 1-2-3, 1-2-3).
options.Copies = 3;
options.Collate = true;

//  Print on double sides vertically.
options.Duplex = Duplex.Vertical;

// Print only pages 1 through 4.
options.From = 1;
options.To = 4;

// Use Tray 2 as the paper source.
// Use the standard .NET System.Drawing.Printing.PrinterSettings API to query available tray names for your printer.
options.PaperSourceName = "Tray 2";

// Print the workbook.
workbook.PrintOut(options);

// Save the workbook.
workbook.Save("printworkbook.xlsx");
```

>type=note
> **Note:** 
> Before setting [PaperSourceName](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.PrintOutOptions.PaperSourceName.html), you can query the available paper source names for a specific printer using the standard .NET [System.Drawing.Printing.PrinterSettings](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.printing.printersettings?view=windowsdesktop-10.0) API:
>
> ```csharp
> var settings = new System.Drawing.Printing.PrinterSettings();
> settings.PrinterName = "Gestetner MP C3503 PCL 6";
> Console.WriteLine("Available paper sources:");
> foreach (System.Drawing.Printing.PaperSource ps in settings.PaperSources)
> {
>     Console.WriteLine($"  {ps.SourceName} (Kind: {ps.Kind})");
> }
> ```