Iniziare
Installazione
Installa da Aspose.Cells a NuGet
NuGet è il modo più semplice per scaricare e installare Aspose.Cells for .NET.
- Apri Microsoft Visual Studio e NuGet gestore pacchetti.
- Cerca “aspose.cells” per trovare il Aspose.Cells for .NET desiderato.
- Clicca su “Installa”, Aspose.Cells for .NET verrà scaricato e referenziato nel tuo progetto.
Puoi anche scaricarlo dalla pagina web nuget per aspose.cells: Aspose.Cells for .NET NuGet Confezione
Installa Aspose.Cells su Windows
- Scarica Aspose.Cells.msi dalla seguente pagina: Scarica Aspose.Cells.msi
- Fare doppio clic su Aspose Cells msi e seguire le istruzioni per installarlo:
Installa Aspose.Cells su Linux
In questo esempio, utilizzo Ubuntu per mostrare come iniziare a utilizzare Aspose.Cells su Linux.
- Crea un’applicazione .netcore, denominata “AsposeCellsTest”.
- Apri il file “AsposeCellsTest.csproj”, aggiungi le seguenti righe per i riferimenti al pacchetto Aspose.Cells:
<ItemGroup> <PackageReference Include="Aspose.Cells" Version="22.12" /> </ItemGroup>
- Apri il progetto con VSCode su Ubuntu:
- eseguire test con il seguente codice:
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");
Nota: Aspose.Cells Per .NetStandard può supportare le tue esigenze su Linux.
Si applica a: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 e versione avanzata.
Installa Aspose.Cells su MAC OS
In questo esempio, utilizzo macOS High Sierra per mostrare come iniziare a utilizzare Aspose.Cells su MAC OS.
- Crea un’applicazione .netcore, denominata “AsposeCellsTest”.
- Aprire l’applicazione con Visual Studio per Mac, quindi installare Aspose Cells tramite NuGet:
- eseguire il test con il seguente codice:
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"); - Se è necessario utilizzare funzionalità relative al disegno, installare libgdiplus in macOS, vedere: Come installare libgdiplus su macOS
Nota: Aspose.Cells per .NetStandard può supportare le tue esigenze su MAC OS.
Si applica a: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 e versione avanzata.
Esegui Aspose Cells in Docker
Come utilizzare la libreria grafica su piattaforme non Windows con Net6
Aspose.Cells per Net6 ora utilizza SkiaSharp come libreria grafica, come consigliato incomunicato ufficiale del Microsoft . Per ulteriori dettagli sull’utilizzo di Aspose.Cells con NET6, vedereCome eseguire Aspose.Cells per .Net6.
Creazione dell’applicazione Hello World
passaggi seguenti creano l’applicazione Hello World utilizzando Aspose.Cells API:
- Se hai una licenza, alloraapplicarlo. Se stai utilizzando la versione di valutazione, salta le righe di codice relative alla licenza.
- Crea un’istanza diCartella di lavoro class per creare un nuovo file Excel o aprire un file Excel esistente.
- Accedi a qualsiasi cella desiderata di un foglio di lavoro nel file Excel.
- Inserisci le paroleHello World! in una cella a cui si accede.
- Genera il file Excel Microsoft modificato.
L’implementazione dei passaggi precedenti è dimostrata negli esempi seguenti.
Esempio di codice: creazione di una nuova cartella di lavoro
L’esempio seguente crea una nuova cartella di lavoro da zero, inserisce “Hello World!” nella cella A1 nel primo foglio di lavoro e salva come file 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"); |
Esempio di codice: apertura di un file esistente
L’esempio seguente apre un file modello Excel Microsoft esistente “Sample.xlsx”, inserisce “Hello World!” nella cella A1 nel primo foglio di lavoro e salva come file 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(); |