Ihre erste Aspose.Cells Bewerbung - Hello World

Erstellen der Hello World-Anwendung

So erstellen Sie die Anwendung Hello World mit Aspose.Cells API:

  1. Erstellen Sie eine Instanz der**Arbeitsmappe**Klasse.
  2. Wenden Sie die Lizenz an:
  3. Wenn Sie eine Lizenz erworben haben, verwenden Sie die Lizenz in Ihrer Anwendung, um Zugriff auf die volle Funktionalität von Aspose.Cells zu erhalten
  4. Wenn Sie die Evaluierungsversion der Komponente verwenden (wenn Sie Aspose.Cells ohne Lizenz verwenden), überspringen Sie diesen Schritt.
  5. Erstellen Sie eine neue Microsoft Excel-Datei oder öffnen Sie eine vorhandene Datei, in der Sie Text hinzufügen/aktualisieren möchten.
  6. Greifen Sie auf eine beliebige Zelle eines Arbeitsblatts in der Excel-Datei Microsoft zu.
  7. Füge die Wörter einHello World! in eine zugegriffene Zelle.
  8. Generieren Sie die geänderte Excel-Datei Microsoft.

Die folgenden Beispiele veranschaulichen die obigen Schritte.

Erstellen einer Arbeitsmappe

Das folgende Beispiel erstellt eine neue Arbeitsmappe von Grund auf, schreibt die Wörter “Hello World!” in Zelle A1 auf dem ersten Arbeitsblatt und speichert die Datei.

Die generierte Tabelle

todo: Bild_alt_Text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreatingWorkbook.class);
// Creating a file input stream to reference the license file
FileInputStream fstream = new FileInputStream("Aspose.Cells.lic");
// Create a License object
License license = new License();
// Applying the Aspose.Cells license
license.setLicense(fstream);
// Instantiating a Workbook object that represents a Microsoft Excel
// file.
Workbook wb = new Workbook();
// Note when you create a new workbook, a default worksheet, "Sheet1", is by default added to the workbook. Accessing the
// first worksheet in the book ("Sheet1").
Worksheet sheet = wb.getWorksheets().get(0);
// Access cell "A1" in the sheet.
Cell cell = sheet.getCells().get("A1");
// Input the "Hello World!" text into the "A1" cell
cell.setValue("Hello World!");
// Save the Microsoft Excel file.
wb.save(dataDir + "MyBook.xls", FileFormatType.EXCEL_97_TO_2003);
wb.save(dataDir + "MyBook.xlsx");
wb.save(dataDir + "MyBook.ods");

Öffnen einer bestehenden Datei

Das folgende Beispiel öffnet eine vorhandene Microsoft Excel-Vorlagendatei mit dem Namenbook1.xlsSie schreibt die Worte “Hello World!” in Zelle A1 im ersten Arbeitsblatt und speichert die Arbeitsmappe als neue Datei.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(OpeningExistingFile.class);
// Creating a file input stream to reference the license file
FileInputStream fstream = new FileInputStream("Aspose.Cells.lic");
// Create a License object
License license = new License();
// Set the license of Aspose.Cells to avoid the evaluation limitations
license.setLicense(fstream);
// Instantiate a Workbook object that represents an Excel file
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Get the reference of "A1" cell from the cells of a worksheet
Cell cell = workbook.getWorksheets().get(0).getCells().get("A1");
// Set the "Hello World!" value into the "A1" cell
cell.setValue("Hello World!");
// Write the Excel file
workbook.save(dataDir + "HelloWorld.xls", FileFormatType.EXCEL_97_TO_2003);
workbook.save(dataDir + "HelloWorld.xlsx");
workbook.save(dataDir + "HelloWorld.ods");