Komma igång

Installation

Installera Aspose Cells via NuGet

NuGet är det enklaste sättet att ladda ner och installera Aspose.Cells for C++.

  1. Skapa ett Microsoft Visual Studio-projekt för C++.
  2. Inkludera headerfilen “Aspose.Cells.h”.
  3. Öppna Microsoft Visual Studio och pakethanteraren NuGet.
  4. Sök efter “aspose.cells.cpp” för att hitta den önskade Aspose.Cells for C++.
  5. Klicka på “Installera”, Aspose.Cells for C++ kommer att laddas ner och refereras i ditt projekt.

Installera Aspose Cells via NuGet

Du kan också ladda ner den från nuget-webbsidan för aspose.cells: Aspose.Cells for C++ NuGet-paket

Fler steg för detaljer

En demo för att använda Aspose.Cells for C++ på Windows

  1. Ladda ner Aspose.Cells for C++ från följande sida: Ladda ner Aspose.Cells for C++ (Windows)
  2. Packa upp paketet och du hittar ett exempel som visar hur man använder Aspose.Cells for C++.
  3. Öppna example.sln med Visual Studio 2017 eller en högre version
  4. main.cpp: denna fil visar hur man kodar för att testa Aspose.Cells for C++

En demo för att använda Aspose.Cells for C++ på Linux

  1. Ladda ner Aspose.Cells for C++ från följande sida: Ladda ner Aspose.Cells for C++ (Linux)
  2. Packa upp paketet och du hittar ett exempel som visar hur man använder Aspose.Cells for C++ för Linux.
  3. Säkerställ att du är i sökvägen där exemplet finns.
  4. Kör “cmake -S example -B example/build -DCMAKE_BUILD_TYPE=Release”
  5. Kör “cmake –build example/build”

En demo för att använda Aspose.Cells for C++ på Mac OS

  1. Ladda ner Aspose.Cells for C++ från följande sida: Ladda ner Aspose.Cells for C++ (MacOS)
  2. Packa upp paketet och du hittar ett exempel som visar hur man använder Aspose.Cells for C++ för MacOS.
  3. Säkerställ att du är i sökvägen där exemplet finns.
  4. Kör “cmake -S example -B example/build -DCMAKE_BUILD_TYPE=Release”
  5. Kör “cmake –build example/build”

Skapa Hello World-applikationen

Följande steg skapar Hello World-applikationen med Aspose.Cells API:

  1. Skapa en instans av klassen Workbook.
  2. Om du har en licens, tillämpa den. Om du använder utvärderingsversionen, hoppa över licensrelaterade kodrader.
  3. Åtkomst till valfri cell i ett kalkylblad i Excel-filen.
  4. Infoga orden “Hej Världen!” i en åtkomstcell.
  5. Generera den modifierade Microsoft Excel-filen.

Implementeringen av ovanstående steg visas i exemplen nedan.

Kodexempel: Skapa en ny arbetsbok

Följande exempel skapar en ny arbetsbok från grunden, infogar “Hej Världen!” i cell A1 på första kalkylbladet och sparar Excel-filen.

#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();
}

Kodexempel: Öppna en befintlig fil

Följande exempel öppnar en befintlig Microsoft Excel-mallfil, hämtar en cell och kontrollerar värdet i cell 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();
}