Getting Started

  • 8 min to read
Important

You need a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.

Perform the following steps to get started with the non-visual spreadsheet component:

  1. Start Visual Studio and create a new Console Application (.NET Framework) project.

  2. Add references to the following libraries:

    • DevExpress.Charts.v19.2.Core.dll
    • DevExpress.Data.v19.2.dll
    • DevExpress.DataAccess.v19.2.dll
    • DevExpress.Docs.v19.2.dll
    • DevExpress.Office.v19.2.Core.dll
    • DevExpress.Pdf.v19.2.Core.dll
    • DevExpress.Printing.v19.2.Core.dll
    • DevExpress.Sparkline.v19.2.Core.dll
    • DevExpress.Spreadsheet.v19.2.Core.dll
    • DevExpress.XtraCharts.v19.2.dll
  3. Paste the code below in the Main method of the Program.cs file (Main procedure of the Module1.vb file for Visual Basic).

    using DevExpress.Spreadsheet;
    // ...
    
    static void Main(string[] args)
    {
        // Create a new workbook.
        Workbook workbook = new Workbook();
    
        // Access the first worksheet in the workbook.
        Worksheet worksheet = workbook.Worksheets[0];
    
        // Set the unit of measurement.
        workbook.Unit = DevExpress.Office.DocumentUnit.Point;
    
        workbook.BeginUpdate();
        try
        {
            // Create a multiplication table.
            worksheet.Cells["A1"].Value = "*";
            for (int i = 1; i < 11; i++)
            {
                // Create the header column.
                worksheet.Columns["A"][i].Value = i;
                // Create the header row.
                worksheet.Rows["1"][i].Value = i;
            }
    
            // Multiply values of header cells.
            worksheet.Range["B2:K11"].Formula = "=B$1*$A2";
    
            // Obtain the data range.
            CellRange tableRange = worksheet.GetDataRange();
    
            // Specify the row height and column width.
            tableRange.RowHeight = 40;
            tableRange.ColumnWidth = 40;
    
            // Align the table content.
            tableRange.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            tableRange.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
    
            // Fill the header cells.
            CellRange headerCells = worksheet.Range.Union(worksheet.Range["A1:K1"], worksheet.Range["A2:A11"]);
            headerCells.FillColor = Color.FromArgb(0xf7, 0x9b, 0x77);
            headerCells.Font.Bold = true;
    
            // Fill cells that contain multiplication results.
            worksheet.Range["B2:K11"].FillColor = Color.FromArgb(0xfe, 0xf2, 0xe4);
        }
        finally
        {
            workbook.EndUpdate();
        }
    
        // Save the document file under the specified name.
        workbook.SaveDocument("TestDoc.xlsx", DocumentFormat.OpenXml);
    
        // Export the document to PDF.
        workbook.ExportToPdf("TestDoc.pdf");
    
        // Open the PDF document using the default viewer.
        System.Diagnostics.Process.Start("TestDoc.pdf");
    
        // Open the XLSX document using the default application.
        System.Diagnostics.Process.Start("TestDoc.xlsx");
    }
    
  4. Run the project.

The image below shows the result.

Getting_started

  1. Start Visual Studio and create a new Console Application (.NET Core) project.

  2. Install the DevExpress.Document.Processor NuGet package.

  3. Paste the code below in the Main method of the Program.cs file (Main procedure of the Module1.vb file for Visual Basic).

    using DevExpress.Spreadsheet;
    using System.Diagnostics;
    // ...
    
    static void Main(string[] args)
    {
        // Create a new workbook.
        Workbook workbook = new Workbook();
    
        // Access the first worksheet in the workbook.
        Worksheet worksheet = workbook.Worksheets[0];
    
        // Set the unit of measurement.
        workbook.Unit = DevExpress.Office.DocumentUnit.Point;
    
        workbook.BeginUpdate();
        try
        {
            // Create a multiplication table.
            worksheet.Cells["A1"].Value = "*";
            for (int i = 1; i < 11; i++)
            {
                // Create the header column.
                worksheet.Columns["A"][i].Value = i;
                // Create the header row.
                worksheet.Rows["1"][i].Value = i;
            }
    
            // Multiply values of header cells.
            worksheet.Range["B2:K11"].Formula = "=B$1*$A2";
    
            // Obtain the data range.
            CellRange tableRange = worksheet.GetDataRange();
    
            // Specify the row height and column width.
            tableRange.RowHeight = 40;
            tableRange.ColumnWidth = 40;
    
            // Align the table content.
            tableRange.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            tableRange.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
    
            // Fill the header cells.
            CellRange headerCells = worksheet.Range.Union(worksheet.Range["A1:K1"], worksheet.Range["A2:A11"]);
            headerCells.FillColor = Color.FromArgb(0xf7, 0x9b, 0x77);
            headerCells.Font.Bold = true;
    
            // Fill cells that contain multiplication results.
            worksheet.Range["B2:K11"].FillColor = Color.FromArgb(0xfe, 0xf2, 0xe4);
        }
        finally
        {
            workbook.EndUpdate();
        }
    
        // Save the document file under the specified name.
        workbook.SaveDocument("TestDoc.xlsx", DocumentFormat.OpenXml);
    
        // Export the document to PDF.
        workbook.ExportToPdf("TestDoc.pdf");
    
        // Open the PDF document using the default viewer.
        Process.Start(new ProcessStartInfo("TestDoc.pdf") { UseShellExecute = true });
    
        // Open the XLSX document using the default application.
        Process.Start(new ProcessStartInfo("TestDoc.xlsx") { UseShellExecute = true });
    }
    
  4. Run the project.

The image below shows the result.

Getting_started

  1. Start Visual Studio and create a new Console Application (.NET Core) project.

  2. Install the DevExpress.WindowsDesktop.Document.Processor NuGet package.

  3. Right-click the project in the Solution Explorer and select Edit Project File.

    Spreadsheet_Console_NetCore_3_Edit_Project_File

    Change the project's SDK attribute to Microsoft.NET.Sdk.WindowsDesktop and set the UseWindowsForms option to true.

    <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp3.0</TargetFramework>
        <UseWindowsForms>true</UseWindowsForms>
      </PropertyGroup>
    </Project>
    
  4. Paste the code below in the Main method of the Program.cs file (Main procedure of the Module1.vb file for Visual Basic).

    using DevExpress.Spreadsheet;
    using System.Diagnostics;
    // ...
    
    static void Main(string[] args)
    {
        // Create a new workbook.
        Workbook workbook = new Workbook();
    
        // Access the first worksheet in the workbook.
        Worksheet worksheet = workbook.Worksheets[0];
    
        // Set the unit of measurement.
        workbook.Unit = DevExpress.Office.DocumentUnit.Point;
    
        workbook.BeginUpdate();
        try
        {
            // Create a multiplication table.
            worksheet.Cells["A1"].Value = "*";
            for (int i = 1; i < 11; i++)
            {
                // Create the header column.
                worksheet.Columns["A"][i].Value = i;
                // Create the header row.
                worksheet.Rows["1"][i].Value = i;
            }
    
            // Multiply values of header cells.
            worksheet.Range["B2:K11"].Formula = "=B$1*$A2";
    
            // Obtain the data range.
            CellRange tableRange = worksheet.GetDataRange();
    
            // Specify the row height and column width.
            tableRange.RowHeight = 40;
            tableRange.ColumnWidth = 40;
    
            // Align the table content.
            tableRange.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            tableRange.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
    
            // Fill the header cells.
            CellRange headerCells = worksheet.Range.Union(worksheet.Range["A1:K1"], worksheet.Range["A2:A11"]);
            headerCells.FillColor = Color.FromArgb(0xf7, 0x9b, 0x77);
            headerCells.Font.Bold = true;
    
            // Fill cells that contain multiplication results.
            worksheet.Range["B2:K11"].FillColor = Color.FromArgb(0xfe, 0xf2, 0xe4);
        }
        finally
        {
            workbook.EndUpdate();
        }
    
        // Save the document file under the specified name.
        workbook.SaveDocument("TestDoc.xlsx", DocumentFormat.OpenXml);
    
        // Export the document to PDF.
        workbook.ExportToPdf("TestDoc.pdf");
    
        // Open the PDF document using the default viewer.
        Process.Start(new ProcessStartInfo("TestDoc.pdf") { UseShellExecute = true });
    
        // Open the XLSX document using the default application.
        Process.Start(new ProcessStartInfo("TestDoc.xlsx") { UseShellExecute = true });
    }
    
  5. Run the project.

The image below shows the result.

Getting_started

See Also