Iniziare
Installazione
Installa Aspose.Cells tramite NuGet
NuGet è il modo più semplice per scaricare e installare Aspose.Cells for .NET.
- Apri Microsoft Visual Studio e il gestore dei pacchetti NuGet.
- Cerca “aspose.cells” per trovare il Aspose.Cells for .NET desiderato.
- Fai clic su “Installa”, Aspose.Cells for .NET verrà scaricato e referenziato nel tuo progetto.
Puoi anche scaricarlo dalla pagina web di NuGet per aspose.cells: Pacchetto NuGet Aspose.Cells for .NET
Ulteriori dettagli passo passo
Installa Aspose.Cells su Windows
- Scarica Aspose.Cells.msi dalla seguente pagina: Scarica Aspose.Cells.msi
- Fai doppio clic su Aspose Cells msi e segui le istruzioni per installarlo:
Ulteriori dettagli passo passo
Installa Aspose.Cells su Linux
In questo esempio, uso Ubuntu per mostrare come iniziare a utilizzare Aspose.Cells su Linux.
- Crea un’applicazione .NET Core, chiamata “AsposeCellsTest”.
- Apri il file “AsposeCellsTest.csproj” e aggiungi le seguenti righe come riferimenti al pacchetto Aspose.Cells:
<ItemGroup> <PackageReference Include="Aspose.Cells" Version="24.7" /> </ItemGroup>
- Apri il progetto con VSCode su Ubuntu:
- esegui il test con il codice seguente:
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 la tua richiesta su Linux.
Si applica a: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 e versioni avanzate.
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 .NET Core, chiamata “AsposeCellsTest”.
- Apri l’applicazione con Visual Studio for Mac, quindi installa Aspose Cells tramite NuGet:
- esegui il test con il codice seguente:
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 hai bisogno di utilizzare funzionalità relative ai disegni, installa libgdiplus su macOS, vedi: Come installare libgdiplus su macOS
Nota: Aspose.Cells per .NetStandard può supportare la tua richiesta su MAC OS.
Si applica a: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 e versioni avanzate.
Run 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 nella dichiarazione ufficiale di Microsoft. Per ulteriori dettagli sull’utilizzo di Aspose.Cells con NET6, consulta Come eseguire Aspose.Cells per .Net6.
Creazione dell’applicazione Hello World
I passi seguenti creano l’applicazione Hello World utilizzando l’API Aspose.Cells:
- Se hai una licenza, quindi applicala. Se stai utilizzando la versione di valutazione, salta le righe di codice relative alla licenza.
- Crea un’istanza della classe Workbook per creare un nuovo file Excel, o apri un file Excel esistente.
- Accedi a qualsiasi cella desiderata di un foglio di lavoro nel file di Excel.
- Inserisci le parole Hello World! in una cella accessibile.
- Genera il file modificato di Microsoft Excel.
L’implementazione dei passaggi sopra è dimostrata negli esempi seguenti.
Esempio di codice: Creazione di un nuovo workbook
Nell’esempio seguente si crea un nuovo workbook da zero, si inserisce “Hello World!” nella cella A1 nel primo foglio di lavoro e si 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 esistente di Microsoft Excel “Sample.xlsx”, inserisce “Ciao mondo!” 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(); |