Getting Started
Installation
Install Aspose.Cells through NuGet
NuGet is the easiest way to download and install Aspose.Cells for .NET.
- Open Microsoft Visual Studio and NuGet package manager.
- Search “aspose.cells” to find the desired Aspose.Cells for .NET.
- Click on “Install”, Aspose.Cells for .NET will be downloaded and referenced in your project.
You can also download it from the nuget web page for aspose.cells: Aspose.Cells for .NET NuGet Package
Install Aspose.Cells on windows
- Download Aspose.Cells.msi from the following page: Download Aspose.Cells.msi
- Double-click the Aspose Cells msi and follow the instructions to install it:
Install Aspose.Cells on linux
In this example, I use Ubuntu to show how to start using Aspose.Cells on linux.
- Create a .netcore application, named “AsposeCellsTest”.
- Open file “AsposeCellsTest.csproj”, add the following lines into it for Aspose.Cells package references:
<ItemGroup> <PackageReference Include="Aspose.Cells" Version="23.4" /> </ItemGroup>
- Open the project with VSCode on Ubuntu:
- run test with the following code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET Aspose.Cells.Workbook wb1 = new Aspose.Cells.Workbook(); wb1.Worksheets.Add("linux"); wb1.Worksheets["linux"].Cells[0, 0].Value = "Using Aspose Cells on linux with VS Code."; wb1.Save("linux.xlsx");
Note: Aspose.Cells For .NetStandard can support your requirement on linux.
Applies to: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 and advanced version.
Install Aspose.Cells on MAC OS
In this example, I use macOS High Sierra to show how to start using Aspose.Cells on MAC OS.
- Create a .netcore application, named “AsposeCellsTest”.
- Open the application with Visual Studio for Mac, then install Aspose Cells through NuGet:
- run test with the following code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET Aspose.Cells.Workbook wb1 = new Aspose.Cells.Workbook(); wb1.Worksheets.Add("macOS"); wb1.Worksheets["macOS"].Cells[0, 0].Value = "Using Aspose Cells on macOS with Visual Studio For MAC."; wb1.Save("macOS.xlsx"); - If you need to use drawing-related features, please install libgdiplus in macOS, see: How to Install libgdiplus in macOS
Note: Aspose.Cells For .NetStandard can support your requirement on MAC OS.
Applies to: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 and advanced version.
Run Aspose Cells in Docker
How to use graphics library on non-windows platforms with Net6
Aspose.Cells for Net6 now uses SkiaSharp as the graphics library, as recommended in official statement of Microsoft. For more details about using Aspose.Cells with NET6, please see How to Run Aspose.Cells for .Net6.
Creating the Hello World Application
The steps below creates the Hello World application using the Aspose.Cells API:
- If you have a license, then apply it. If you are using the evaluation version, skip the license related code lines.
- Create an instance of the Workbook class to create a new Excel file, or open an existing Excel file.
- Access any desired cell of a worksheet in the Excel file.
- Insert the words Hello World! into a cell accessed.
- Generate the modified Microsoft Excel file.
The implementation of the above steps is demonstrated in the examples below.
Code Sample: Creating a New Workbook
The following example creates a new workbook from the scratch, inserts “Hello World!” into cell A1 in the first worksheet and saves as Excel file.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
try | |
{ | |
// Create a License object | |
License license = new License(); | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
license.SetLicense(dataDir + "Aspose.Cells.lic"); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Instantiate a Workbook object that represents Excel file. | |
Workbook wb = new Workbook(); | |
// When you create a new workbook, a default "Sheet1" is added to the workbook. | |
Worksheet sheet = wb.Worksheets[0]; | |
// Access the "A1" cell in the sheet. | |
Cell cell = sheet.Cells["A1"]; | |
// Input the "Hello World!" text into the "A1" cell | |
cell.PutValue("Hello World!"); | |
// Save the Excel file. | |
wb.Save(dataDir + "MyBook_out.xlsx"); |
Code Sample: Opening an Existing File
The following example opens an existing Microsoft Excel template file “Sample.xlsx”, inserts “Hello World!” into cell A1 in the first worksheet and saves as Excel file.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
try | |
{ | |
// Create a License object | |
License license = new License(); | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
license.SetLicense("Aspose.Cells.lic"); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "Sample.xlsx", FileMode.Open); | |
// Instantiate a Workbook object that represents the existing Excel file | |
Workbook workbook = new Workbook(fstream); | |
// Get the reference of "A1" cell from the cells collection of a worksheet | |
Cell cell = workbook.Worksheets[0].Cells["A1"]; | |
// Put the "Hello World!" text into the "A1" cell | |
cell.PutValue("Hello World!"); | |
// Save the Excel file | |
workbook.Save(dataDir + "HelloWorld_out.xlsx"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |