Başlarken
Kurulum
NuGet üzerinden Aspose Cells kurun
NuGet, Aspose.Cells for C++‘ı indirmenin ve yüklemenin en kolay yoludur.
- C++ için bir Microsoft Visual Studio projesi oluşturun.
- “Aspose.Cells.h” başlık dosyasını dahil edin.
- Microsoft Visual Studio ve NuGet paket yöneticisini açın.
- Aramak için “aspose.cells.cpp” yazın, istenen Aspose.Cells for C++‘i bulun.
- “Yükle”‘ye tıklayın, Aspose.Cells for C++ indirilecek ve projenizde referans olarak alınacaktır.
Aspose.Cells için nuget web sayfasından da indirebilirsiniz: Aspose.Cells for C++ NuGet Paketi
Windows’ta Aspose.Cells for C++ kullanımı için bir demo
- Aspose.Cells for C++‘yi aşağıdaki sayfadan indirin: Aspose.Cells for C++‘i İndir (Windows)
- Paketi açın ve Aspose.Cells for C++‘i nasıl kullanılacağına dair bir örnek bulacaksınız.
- Visual Studio 2017 veya daha yeni sürümü ile example.sln dosyasını açın
- main.cpp: Bu dosya Aspose.Cells for C++‘i test etmek için nasıl kod yazılacağını gösterir
Linux’ta Aspose.Cells for C++ kullanımı için bir demo
- Aspose.Cells for C++‘yi aşağıdaki sayfadan indirin: Aspose.Cells for C++‘i İndir (Linux)
- Paketi açın ve Aspose.Cells for C++‘i nasıl kullanılacağına dair bir örnek bulacaksınız.
- Örnek dosyasının bulunduğu dizinde olduğunuzdan emin olun.
- “cmake -S example -B example/build -DCMAKE_BUILD_TYPE=Release” komutunu çalıştırın
- “cmake -S example -B example/build -DCMAKE_BUILD_TYPE=Release” komutunu çalıştırın
Mac OS’ta Aspose.Cells for C++ kullanımı için bir demo
- Aspose.Cells for C++‘yi aşağıdaki sayfadan indirin: Aspose.Cells for C++‘i İndir (MacOS)
- Paketi açın ve Aspose.Cells for C++‘i nasıl kullanılacağına dair bir örnek bulacaksınız.
- Örnek dosyasının bulunduğu dizinde olduğunuzdan emin olun.
- “cmake -S example -B example/build -DCMAKE_BUILD_TYPE=Release” komutunu çalıştırın
- “cmake -S example -B example/build -DCMAKE_BUILD_TYPE=Release” komutunu çalıştırın
Merhaba Dünya Uygulamasını Oluşturma
Aşağıdaki adımlar, Aspose.Cells API’sini kullanarak Merhaba Dünya uygulamasını oluşturur:
Aşağıdaki adımlar, Aspose.Cells API’sini kullanarak Hello World uygulamasını oluşturur:
- Workbook sınıfından bir örnek oluşturun. Eğer değerlendirme sürümünü kullanıyorsanız, lisansla ilgili kod satırlarını atlayın.
- Excel dosyasındaki istenen hücreye erişin.
- Hücreye erişildiğinde “Merhaba Dünya!” kelimesini ekleyin.
- Değiştirilmiş Microsoft Excel dosyasını oluşturun.
Yukarıdaki adımların uygulanışı aşağıdaki örneklerde gösterilmektedir.
Kod Örneği: Yeni Bir Workbook Oluşturma
Aşağıdaki örnek, baştan yeni bir çalışma kitabı oluşturur, ilk çalışma sayfasındaki A1 hücresine “Merhaba Dünya!” ekler ve Excel dosyasını kaydeder.
#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(); | |
} |
Kod Örneği: Mevcut Bir Dosyayı Açma
Aşağıdaki örnek, mevcut bir Microsoft Excel şablon dosyasını açar, bir hücre alır ve A1 hücresindeki değeri kontrol eder.
#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(); | |
} |