Create Excel (XLSX) or PDF file on Linux or macOS
GemBox.Spreadsheet provides support for .NET Standard 2.0, a cross-platform specification of .NET APIs, which is why it can be used on non-Windows platforms like Linux and macOS.
The following example shows how you can create an Excel workbook and a PDF file using GemBox.Spreadsheet on Linux (Ubuntu).

Prerequisites
- Install Visual Studio Code.
- Install C# for Visual Studio Code extension.
- Install .NET Core SDK on Ubuntu.
After installing the requirements listed above you can follow these steps that show how you can easily use a Visual Studio Code (VS Code) to create a simple Console project and a C# code that generates a XLSX file.
1. Open a project folder
- Open VS Code.
- Click "Open Folder" on the EXPLORER panel.
- Select the folder you want your console project to be in, for instance a folder named GemBoxExample.

2. Create a new console project
- Open Integrated Terminal in VS Code by clicking "View" > "Terminal" or using CTRL + ` shortcut.
- In the terminal window execute following command:
dotnet new console
- This command will create a code file (Program.cs) and a project file (GemBoxExample.csproj) inside the opened folder.

3. Edit project files
-
Add a reference to GemBox.Spreadsheet and its dependencies in GemBoxExample.csproj file:
<ItemGroup> <PackageReference Include="GemBox.Spreadsheet" Version="*" /> <PackageReference Include="System.Drawing.Common" Version="*" /> <!-- Required if PDF file is digitally signed. --> <PackageReference Include="System.Security.Cryptography.Pkcs" Version="*" /> </ItemGroup>
libgdiplus
library which must be installed on a non-Windows system.
To install it on Linux use the following command:sudo apt-get install libgdiplus
To install it on macOS use Homebrew with the following command:brew install mono-libgdiplus
-
Edit C# code in Program.cs file:
using GemBox.Spreadsheet; class Program { static void Main() { // If using Professional version, put your serial key below. SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY"); var workbook = new ExcelFile(); var worksheet = workbook.Worksheets.Add("Hello World"); worksheet.Cells[0, 0].Value = "English:"; worksheet.Cells[0, 1].Value = "Hello"; worksheet.Cells[1, 0].Value = "Russian:"; // Using UNICODE string. worksheet.Cells[1, 1].Value = new string(new char[] { '\u0417', '\u0434', '\u0440', '\u0430', '\u0432', '\u0441', '\u0442', '\u0432', '\u0443', '\u0439', '\u0442', '\u0435' }); worksheet.Cells[2, 0].Value = "Chinese:"; // Using UNICODE string. worksheet.Cells[2, 1].Value = new string(new char[] { '\u4f60', '\u597d' }); worksheet.Cells[4, 0].Value = "In order to see Russian and Chinese characters you need to have appropriate fonts on your PC."; worksheet.Cells.GetSubrangeAbsolute(4, 0, 4, 7).Merged = true; workbook.Save("Output.xlsx"); workbook.Save("Output.pdf"); } }
4. Run the console project
- In the terminal window execute following command:
dotnet run
- This command will run your Console application and create an Excel workbook (Output.xlsx) and a PDF file (Output.pdf) that you open in any Excel and PDF applications.

Limitations on Linux or macOS
The .NET Standard version of GemBox.Spreadsheet has full functionality of .NET Framework version, but with few rendering limitations (unsupported features):
- Printing workbooks.
- Saving workbooks to XPS and image formats.
- Calling
ConvertToImageSource
andConvertToXpsDocument
methods.
Want more?
Like it?
Published: December 10, 2019 | Modified: December 4, 2020 | Author: Damir Stipinović