Commencer
Installation
Installez Aspose.Cells à NuGet
NuGet est le moyen le plus simple de télécharger et d’installer Aspose.Cells for .NET.
- Ouvrez Microsoft Visual Studio et le gestionnaire de packages NuGet.
- Recherchez “aspose.cells” pour trouver le Aspose.Cells for .NET souhaité.
- Cliquez sur “Installer”, Aspose.Cells for .NET sera téléchargé et référencé dans votre projet.
Vous pouvez également le télécharger à partir de la page Web nuget pour aspose.cells : Aspose.Cells for .NET NuGet Colis
Installez Aspose.Cells sur Windows
- Téléchargez Aspose.Cells.msi à partir de la page suivante : Télécharger Aspose.Cells.msi
- Double-cliquez sur le Aspose Cells msi et suivez les instructions pour l’installer :
Installez Aspose.Cells sur Linux
Dans cet exemple, j’utilise Ubuntu pour montrer comment commencer à utiliser Aspose.Cells sous Linux.
- Créez une application .netcore, nommée “AsposeCellsTest”.
- Ouvrez le fichier “AsposeCellsTest.csproj”, ajoutez-y les lignes suivantes pour les références de package Aspose.Cells :
<ItemGroup> <PackageReference Include="Aspose.Cells" Version="22.12" /> </ItemGroup>
- Ouvrez le projet avec VSCode sur Ubuntu :
- exécutez le test avec le code suivant :
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");
Remarque : Aspose.Cells pour .NetStandard peut prendre en charge vos besoins sous Linux.
S’applique à : NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 et version avancée.
Installez Aspose.Cells sur MAC OS
Dans cet exemple, j’utilise macOS High Sierra pour montrer comment commencer à utiliser Aspose.Cells sur MAC OS.
- Créez une application .netcore, nommée “AsposeCellsTest”.
- Ouvrez l’application avec Visual Studio pour Mac, puis installez Aspose Cells à NuGet :
- exécutez le test avec le code suivant :
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"); - Si vous avez besoin d’utiliser des fonctionnalités liées au dessin, veuillez installer libgdiplus dans macOS, voir : Comment installer libgdiplus dans macOS
Remarque : Aspose.Cells pour .NetStandard peut prendre en charge vos besoins sur MAC OS.
S’applique à : NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 et version avancée.
Exécuter Aspose Cells dans Docker
Comment utiliser la bibliothèque graphique sur des plates-formes non Windows avec Net6
Aspose.Cells pour Net6 utilise désormais SkiaSharp comme bibliothèque graphique, comme recommandé danscommuniqué du Microsoft . Pour plus de détails sur l’utilisation de Aspose.Cells avec NET6, veuillez consulterComment exécuter Aspose.Cells pour .Net6.
Création de l’application Hello World
Les étapes ci-dessous créent l’application Hello World en utilisant le Aspose.Cells API :
- Si vous avez une licence, alorsappliquez-le. Si vous utilisez la version d’évaluation, ignorez les lignes de code liées à la licence.
- Créer une instance deCahier class pour créer un nouveau fichier Excel ou ouvrir un fichier Excel existant.
- Accédez à n’importe quelle cellule souhaitée d’une feuille de calcul dans le fichier Excel.
- Insérez les motsHello World! dans une cellule accessible.
- Générez le fichier Excel Microsoft modifié.
La mise en œuvre des étapes ci-dessus est illustrée dans les exemples ci-dessous.
Exemple de code : création d’un nouveau classeur
L’exemple suivant crée un nouveau classeur à partir de zéro, insère “Hello World!” dans la cellule A1 de la première feuille de calcul et l’enregistre en tant que fichier Excel.
// 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"); |
Exemple de code : ouverture d’un fichier existant
L’exemple suivant ouvre un fichier de modèle Excel Microsoft existant “Sample.xlsx”, insère “Hello World!” dans la cellule A1 de la première feuille de calcul et l’enregistre en tant que fichier Excel.
// 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(); |