Einstieg
Installation
Installieren Sie Aspose.Cells bis NuGet
NuGet ist der einfachste Weg, Aspose.Cells for .NET herunterzuladen und zu installieren.
- Öffnen Sie Microsoft Visual Studio und NuGet Paket-Manager.
- Suchen Sie nach “aspose.cells”, um die gewünschte Aspose.Cells for .NET zu finden.
- Klicken Sie auf „Installieren“, Aspose.Cells for .NET wird heruntergeladen und in Ihrem Projekt referenziert.
Sie können es auch von der nuget-Webseite für aspose.cells herunterladen: Aspose.Cells for .NET NuGet Paket
Installieren Sie Aspose.Cells unter Windows
- Laden Sie Aspose.Cells.msi von der folgenden Seite herunter: Laden Sie Aspose.Cells.msi herunter
- Doppelklicken Sie auf die MSI-Datei Aspose Cells und befolgen Sie die Anweisungen zur Installation:
Installieren Sie Aspose.Cells unter Linux
In diesem Beispiel verwende ich Ubuntu, um zu zeigen, wie man mit der Verwendung von Aspose.Cells unter Linux beginnt.
- Erstellen Sie eine .netcore-Anwendung namens „AsposeCellsTest“.
- Öffnen Sie die Datei “AsposeCellsTest.csproj”, fügen Sie die folgenden Zeilen für Aspose.Cells-Paketverweise hinzu:
<ItemGroup> <PackageReference Include="Aspose.Cells" Version="22.12" /> </ItemGroup>
- Öffnen Sie das Projekt mit VSCode auf Ubuntu:
- Test mit folgendem Code ausführen:
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");
Hinweis: Aspose.Cells für .NetStandard kann Ihre Anforderung unter Linux unterstützen.
Gilt für: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 und erweiterte Version.
Installieren Sie Aspose.Cells unter MAC OS
In diesem Beispiel verwende ich macOS High Sierra, um zu zeigen, wie man mit der Verwendung von Aspose.Cells unter MAC OS beginnt.
- Erstellen Sie eine .netcore-Anwendung namens „AsposeCellsTest“.
- Öffnen Sie die Anwendung mit Visual Studio für Mac und installieren Sie dann Aspose Cells bis NuGet:
- Test mit folgendem Code ausführen:
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"); - Wenn Sie zeichnungsbezogene Funktionen verwenden müssen, installieren Sie bitte libgdiplus in macOS, siehe: So installieren Sie libgdiplus unter macOS
Hinweis: Aspose.Cells für .NetStandard kann Ihre Anforderung auf MAC OS unterstützen.
Gilt für: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 und erweiterte Version.
Aspose Cells in Docker ausführen
So verwenden Sie die Grafikbibliothek auf Nicht-Windows-Plattformen mit Net6
Aspose.Cells für Net6 verwendet jetzt SkiaSharp als Grafikbibliothek, wie in empfohlenoffizielle Erklärung von Microsoft . Weitere Einzelheiten zur Verwendung von Aspose.Cells mit NET6 finden Sie unterSo führen Sie Aspose.Cells für .Net6 aus.
Erstellen der Hello World-Anwendung
Die folgenden Schritte erstellen die Hello World-Anwendung unter Verwendung der Aspose.Cells API:
- Wenn Sie eine Lizenz haben, dannWende es an. Wenn Sie die Evaluierungsversion verwenden, überspringen Sie die lizenzbezogenen Codezeilen.
- Erstellen Sie eine Instanz derArbeitsmappe Klasse, um eine neue Excel-Datei zu erstellen, oder öffnen Sie eine vorhandene Excel-Datei.
- Greifen Sie in der Excel-Datei auf eine beliebige Zelle eines Arbeitsblatts zu.
- Füge die Wörter einHello World! in eine zugegriffene Zelle.
- Generieren Sie die geänderte Excel-Datei Microsoft.
Die Implementierung der obigen Schritte wird in den folgenden Beispielen demonstriert.
Codebeispiel: Erstellen einer neuen Arbeitsmappe
Das folgende Beispiel erstellt eine neue Arbeitsmappe von Grund auf, fügt “Hello World!” in Zelle A1 im ersten Arbeitsblatt und speichert es als Excel-Datei.
// 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"); |
Codebeispiel: Öffnen einer vorhandenen Datei
Das folgende Beispiel öffnet eine vorhandene Microsoft Excel-Vorlagendatei “Sample.xlsx”, fügt “Hello World!” in Zelle A1 im ersten Arbeitsblatt und speichert es als Excel-Datei.
// 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(); |