Iniziare
Installazione
Installa Aspose Cells tramite NuGet
NuGet è il modo più semplice per scaricare e installare Aspose.Cells for C++.
- Crea un progetto Microsoft Visual Studio per C++.
- Includi il file di intestazione “Aspose.Cells.h”.
- Apre Microsoft Visual Studio e il gestore dei pacchetti NuGet.
- Cerca “aspose.cells.cpp” per trovare il desiderato Aspose.Cells for C++.
- Fai clic su “Installa”, verrà scaricato e referenziato nel tuo progetto il Aspose.Cells for C++.
Puoi anche scaricarlo dalla pagina web di NuGet per aspose.cells: Pacchetto NuGet Aspose.Cells for C++
Ulteriori passaggi per i dettagli
Un esempio per l’uso di Aspose.Cells for C++ su Windows
- Scarica Aspose.Cells for C++ dalla seguente pagina: Scarica Aspose.Cells for C++(Windows)
- Decomprimi il pacchetto e troverai un esempio su come utilizzare il Aspose.Cells for C++.
- Apri il file example.sln con Visual Studio 2017 o versioni successive
- main.cpp: questo file mostra come codificare per testare il Aspose.Cells for C++
Un esempio per l’uso di Aspose.Cells for C++ su Linux
- Scarica Aspose.Cells for C++ dalla seguente pagina: Scarica Aspose.Cells for C++(Linux)
- Decomprimi il pacchetto e troverai un esempio su come utilizzare il Aspose.Cells for C++ per Linux.
- Assicurati di trovarti nel percorso in cui si trova l’esempio.
- Esegui “cmake -S example -B example/build -DCMAKE_BUILD_TYPE=Release”
- Esegui “cmake –build example/build”
Un esempio per l’uso di Aspose.Cells for C++ su Mac OS
- Scarica Aspose.Cells for C++ dalla seguente pagina: Scarica Aspose.Cells for C++ (MacOS)
- Decomprimi il pacchetto e troverai un esempio su come utilizzare Aspose.Cells for C++ per MacOS.
- Assicurati di trovarti nel percorso in cui si trova l’esempio.
- Esegui “cmake -S example -B example/build -DCMAKE_BUILD_TYPE=Release”
- Esegui “cmake –build example/build”
Creazione dell’applicazione Hello World
I passi seguenti creano l’applicazione Hello World utilizzando l’API Aspose.Cells:
- Crea un’istanza della classe Workbook.
- Se hai una licenza, applicala. Se stai utilizzando la versione di valutazione, salta le righe di codice relative alla licenza.
- 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 viene creato un nuovo workbook da zero, inserisce “Hello World!” nella cella A1 del primo foglio di lavoro e salva il file di Excel.
#include "Aspose.Cells.h" | |
using namespace Aspose::Cells; | |
int main(void) | |
{ | |
Aspose::Cells::Startup(); | |
try | |
{ | |
// Create a License object | |
License license; | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
license.SetLicense(u"Aspose.Cells.lic"); | |
// Instantiate a Workbook object that represents Excel file. | |
Workbook wb; | |
// When you create a new workbook, a default "Sheet1" is added to the workbook. | |
Worksheet sheet = wb.GetWorksheets().Get(0); | |
// Access the "A1" cell in the sheet. | |
Cell cell = sheet.GetCells().Get(u"A1"); | |
// Input the "Hello World!" text into the "A1" cell | |
cell.PutValue(u"Hello World!"); | |
// Save the Excel file. | |
wb.Save(u"MyBook_out.xlsx"); | |
} | |
catch (const CellsException& ex) | |
{ | |
std::cout << ex.GetErrorMessage().ToUtf8() << std::endl; | |
} | |
Aspose::Cells::Cleanup(); | |
} |
Esempio di codice: Apertura di un file esistente
Nell’esempio seguente viene aperto un modello di file di Excel esistente, viene presa una cella e viene controllato il valore nella cella A1.
#include "Aspose.Cells.h" | |
using namespace Aspose::Cells; | |
/*Check result*/ | |
#define EXPECT_TRUE(condition) \ | |
if (condition) printf("--%s,line:%d -> Ok --\n", __FUNCTION__, __LINE__); \ | |
else printf("--%s,line:%d->>>> Failed!!!! <<<<--\n", __FUNCTION__, __LINE__); | |
int main(void) | |
{ | |
Aspose::Cells::Startup(); | |
try | |
{ | |
// Create a License object | |
License license; | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
//license.SetLicense(u"Aspose.Cells.lic"); | |
// Instantiate a Workbook object that represents Excel file. | |
Workbook wb;//(u"MyBook_out.xlsx"); | |
// When you create a new workbook, a default "Sheet1" is added to the workbook. | |
Worksheet sheet = wb.GetWorksheets().Get(0); | |
// Access the "A1" cell in the sheet. | |
Cell cell = sheet.GetCells().Get(u"A1"); | |
U16String strRet = cell.GetStringValue(); | |
//check value | |
EXPECT_TRUE(strRet == u"Hello World!"); | |
// Save the Excel file. | |
wb.Save(u"MyBook_out.xlsx"); | |
} | |
catch (const CellsException& ex) | |
{ | |
std::cout << ex.GetErrorMessage().ToUtf8() << std::endl; | |
} | |
Aspose::Cells::Cleanup(); | |
} |