Excel, OpenOffice, Json, Csv ve Html Dosyalarını C++ ile Yükleme ve Yönetme
Contents
[
Hide
]
Aspose.Cells for C++ ile, örneğin veri almak veya geliştirme sürecini hızlandırmak için tasarımcı şablonu kullanmak gibi, Excel dosyalarını oluşturmak, açmak ve yönetmek oldukça basittir.
Yeni Bir Çalışma Kitabı Oluşturma
Aşağıdaki örnek sıfırdan yeni bir çalışma kitabı oluşturur.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
try
{
// Create a License object
License license;
// Set the license of Aspose.Cells to avoid the evaluation limitations
license.SetLicense(srcDir + u"Aspose.Cells.lic");
}
catch (const std::exception& ex)
{
std::cerr << ex.what() << std::endl;
}
// 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(srcDir + u"MyBook_out.xlsx");
Aspose::Cells::Cleanup();
return 0;
}
Bir Dosya Açma ve Kaydetme
Aspose.Cells for C++ ile Excel dosyalarını açmak, kaydetmek ve yönetmek oldukça basittir.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Path of input Excel file
U16String inputFilePath = srcDir + u"Book1.xlsx";
// Path of output Excel file
U16String outputFilePath = outDir + u"dest.xlsx";
// Create a Workbook object and open an Excel file using its file path
Workbook workbook1(inputFilePath);
// Adding new sheet
WorksheetCollection sheets = workbook1.GetWorksheets();
Worksheet sheet = sheets.Add(u"MySheet");
// Setting active sheet
sheets.SetActiveSheetIndex(1);
// Setting values
Cells cells = sheet.GetCells();
// Setting text
cells.Get(u"A1").PutValue(u"Hello!");
// Setting number
cells.Get(u"A2").PutValue(1000);
// Setting Date Time
Cell cell = cells.Get(u"A3");
Date currentDate;
currentDate.year = 2023; // Replace with actual current year
currentDate.month = 10; // Replace with actual current month
currentDate.day = 5; // Replace with actual current day
currentDate.hour = 12; // Replace with actual current hour
currentDate.minute = 30; // Replace with actual current minute
currentDate.second = 0; // Replace with actual current second
cell.PutValue(currentDate);
// Setting style for date
Style style = cell.GetStyle();
style.SetNumber(14);
cell.SetStyle(style);
// Setting formula
cells.Get(u"A4").SetFormula(u"=SUM(A1:A3)");
// Saving the workbook to disk
workbook1.Save(outputFilePath);
std::cout << "Workbook saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
Gelişmiş Konular
- Dosyaları Açmanın Farklı Yolları
- İş kitabı yüklerken Tanımlanmış İsimleri Filtreleme
- İş kitabı veya çalışma sayfası yüklerken Nesneleri Filtreleme
- Şablon dosyasından iş kitabı yüklerken veri türüne göre filtreleme
- Excel Dosyasını Yüklerken Uyarılar Alın
- Grafikleri Olmadan Kaynak Excel Dosyasını Yükleme
- Bir Çalışma Kitabındaki Belirli Çalışma Sayfalarını Yükleme
- Belirtilen Yazıcı Kağıt Boyutuyla Çalışma Kitabını Yükle
- Farklı Microsoft Excel Sürümlerini Açma
- Farklı Biçimlerde Dosyaları Açma
- Büyük Veri Setlerine Sahip Büyük Dosyalarla Çalışırken Bellek Kullanımını Optimize Etme
- Apple Inc. Tarafından Geliştirilen Sayılar Tablosunu Aspose.Cells Kullanarak Oku
- Çok Uzun Süren İşlemler veya Dönüşümler İçin InterruptMonitor Kullanarak Durdur
- LightCells API’sını Kullanma
- CSV’yi JSON’a dönüştür
- Excel’i JSON’a dönüştürmek
- JSON’ı CSV’ye dönüştür
- JSON’u Excel’e dönüştürmek
- Excel’i Html’e dönüştürmek