Erste Schritte

Installation

Installieren Sie Aspose.Cells über NuGet

NuGet ist der einfachste Weg, um Aspose.Cells for .NET herunterzuladen und zu installieren.

  1. Öffnen Sie Microsoft Visual Studio und den NuGet-Paket-Manager.
  2. Suchen Sie nach “aspose.cells”, um die gewünschte Aspose.Cells for .NET zu finden.
  3. Klicken Sie auf “Installieren”, Aspose.Cells for .NET wird heruntergeladen und in Ihr Projekt eingebunden. Aspose.Cells über NuGet installieren

Sie können es auch von der NuGet-Webseite für aspose.cells herunterladen: Aspose.Cells for .NET NuGet-Paket

Weitere Schritte für Details

Aspose.Cells auf Windows installieren

  1. Laden Sie Aspose.Cells.msi von der folgenden Seite herunter: Aspose.Cells.msi herunterladen
  2. Doppelklicken Sie auf das Aspose Cells msi und folgen Sie den Anweisungen, um es zu installieren:

Aspose.Cells auf Windows installieren

Weitere Schritte für Details

Aspose.Cells auf Linux installieren

In diesem Beispiel verwende ich Ubuntu, um zu zeigen, wie Sie Aspose.Cells auf Linux verwenden können.

  1. Erstellen Sie eine .netcore-Anwendung namens “AsposeCellsTest”.
  2. Öffnen Sie die Datei “AsposeCellsTest.csproj” und fügen Sie die folgenden Zeilen für Aspose.Cells-Paketverweise ein:
      <ItemGroup>
        <PackageReference Include="Aspose.Cells" Version="24.7" />
      </ItemGroup>
  3. Öffnen Sie das Projekt mit VSCode auf Ubuntu: Aspose.Cells auf Linux installieren
  4. Führen Sie den Test mit folgendem Code aus:
    // 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 For .NetStandard kann Ihre Anforderung auf Linux unterstützen.

Gilt für: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 und höhere Versionen.

Aspose.Cells auf MAC OS installieren

In diesem Beispiel verwende ich macOS High Sierra, um zu zeigen, wie man Aspose.Cells auf MAC OS verwendet.

  1. Erstellen Sie eine .netcore-Anwendung namens “AsposeCellsTest”.
  2. Öffnen Sie die Anwendung mit Visual Studio für Mac und installieren Sie dann Aspose.Cells über NuGet: Aspose Cells auf macOS installieren
  3. Führen Sie den Test mit folgendem Code aus:
    // 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");
  4. Wenn Sie zeichenbezogene Funktionen verwenden müssen, installieren Sie bitte libgdiplus in macOS. Siehe: Wie installiert man libgdiplus in macOS

Hinweis: Aspose.Cells For .NetStandard kann Ihre Anforderung auf MAC OS unterstützen.

Gilt für: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 und höhere Versionen.

Run Aspose Cells in Docker

Verwendung der Grafikbibliothek auf Nicht-Windows-Plattformen mit Net6

Aspose.Cells für Net6 verwendet jetzt SkiaSharp als Grafikbibliothek, wie in offizieller Erklärung von Microsoft empfohlen. Für weitere Details zur Verwendung von Aspose.Cells mit NET6 siehe Wie führt man Aspose.Cells for .Net6 aus.

Erstellen der Hello World-Anwendung

Die folgenden Schritte erstellen die Hello World-Anwendung unter Verwendung der Aspose.Cells API:

  1. Wenn Sie eine Lizenz haben, dann wenden Sie diese an. Wenn Sie die Evaluierungsversion verwenden, überspringen Sie die Lizenz-bezogenen Codezeilen.
  2. Erstellen Sie eine Instanz der Workbook-Klasse, um eine neue Excel-Datei zu erstellen oder eine vorhandene Excel-Datei zu öffnen.
  3. Greifen Sie auf eine beliebige Zelle einer Arbeitsmappe in der Excel-Datei zu.
  4. Fügen Sie die Worte Hallo Welt! in eine zugängliche Zelle ein.
  5. Generieren Sie die modifizierte Microsoft Excel-Datei.

Die Implementierung der obigen Schritte wird in den folgenden Beispielen demonstriert.

Codesample: Erstellen einer neuen Arbeitsmappe

Im folgenden Beispiel wird ein neues Arbeitsblatt von Grund auf erstellt, „Hello World!“ in Zelle A1 im ersten Arbeitsblatt eingefügt und als Excel-Datei gespeichert.

// 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");

Codesample: Öffnen einer vorhandenen Datei

Im folgenden Beispiel wird eine vorhandene Microsoft Excel-Vorlagendatei „Sample.xlsx“ geöffnet, „Hello World!“ in Zelle A1 im ersten Arbeitsblatt eingefügt und als Excel-Datei gespeichert.

// 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();