Veri Eklemek ve Almak

Hücrelere Veri Eklemek

Aspose.Cells, bir Microsoft Excel dosyasını temsil eden Workbook sınıfını sağlar. Workbook sınıfı, Excel dosyasındaki her çalışma sayfasına erişim sağlar. Bir çalışma sayfası, Worksheet sınıfı tarafından temsil edilir. Worksheet sınıfı, Cells koleksiyonunu sağlar. Cells içindeki her öğe, Cell sınıfının bir nesnesini temsil eder.

Aspose.Cells, geliştiricilere hücrelere veri eklemek için Cell sınıfının PutValue yöntemini çağırarak veri eklemeyi sağlar. Aspose.Cells, PutValue yönteminin aşırı yüklenmiş sürümlerini sunar, bu sayede geliştiriciler farklı türde verileri hücrelere ekleyebilir. PutValue yönteminin bu aşırı yüklenmiş sürümlerini kullanarak, bir hücreye mantıksal, string, double, tamsayı veya tarih/zaman vs. gibi farklı türde veriler eklemek mümkündür.

Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input
U16String dirPath(u"");
//Path of output
U16String outPath(u"");
//Path of input excel file
U16String sampleData = dirPath + u"sampleData.xlsx";
//Path of output excel file
U16String outputData = outPath + u"outputData.xlsx";
//Read input excel file
Workbook workbook(sampleData);
//Accessing the second worksheet in the Excel file
Worksheet worksheet = workbook.GetWorksheets().Get(1);
//Adding a string value to the cell
worksheet.GetCells().Get(u"A1").PutValue(u"Hello World");
//Adding a double value to the cell
worksheet.GetCells().Get(u"A2").PutValue(20.5);
//Adding an integer value to the cell
worksheet.GetCells().Get(u"A3").PutValue(15);
//Adding a boolean value to the cell
worksheet.GetCells().Get(u"A4").PutValue(true);
//Setting the display format of the date
Cell cell = worksheet.GetCells().Get(u"A5");
Style style = cell.GetStyle();
style.SetNumber(15);
cell.SetStyle(style);
//Save the workbook
workbook.Save(outputData);
Aspose::Cells::Cleanup();

Verimliliği Artırma

Eğer PutValue yöntemini kullanarak bir çalışma sayfasına büyük miktarda veri eklerseniz, verileri hücrelere önce satır bazında ardından sütun bazında eklemeniz gerekmektedir. Bu yaklaşım, uygulamalarınızın verimliliğini büyük ölçüde arttırır.

Hücrelerden Veri Alın

Aspose.Cells, bir Microsoft Excel dosyasını temsil eden Workbook sınıfını sağlar. Workbook sınıfı, dosyadaki çalışma sayfalarına erişim sağlar. Bir çalışma sayfası, Worksheet sınıfı tarafından temsil edilir. Worksheet sınıfı, Cells koleksiyonunu sağlar. Koleksiyondaki her öğe, Cell sınıfının bir nesnesini temsil eder.

Cell sınıfı, geliştiricilere hücrelerden veri almak için verilerin veri türlerine göre alınmasına izin veren birkaç yöntem sağlar. Bu yöntemler şunları içerir:

Bir alan doldurulmadığında, GetDoubleValue veya GetFloatValue hücreleri bir istisna fırlatır.

Hücrede bulunan verinin türü ayrıca Cell sınıfının GetType metodunu kullanarak kontrol edilebilir. Aslında, Cell sınıfının GetType metodu, önceden tanımlanmış değerlerin listelendiği CellValueType numaralandırmasına dayanmaktadır:

Hücre Değer Türleri Açıklama
CellValueType_IsBool Hücre değerinin Boolean olduğunu belirtir.
CellValueType_IsDateTime Hücre değerinin tarih/saat olduğunu belirtir.
CellValueType_IsNull Boş bir hücreyi temsil eder.
CellValueType_IsNumeric Hücre değerinin sayısal olduğunu belirtir.
CellValueType_IsString Hücre değerinin dize olduğunu belirtir.
CellValueType_IsUnknown Hücre değerinin bilinmeyen olduğunu belirtir.
Ayrıca, yukarıda önceden tanımlanmış hücre değer türlerini, her hücrede bulunan verinin Türü ile karşılaştırmak için de kullanabilirsiniz.
Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input
U16String dirPath(u"");
//Path of output
U16String outPath(u"");
//Path of input excel file
U16String sampleData = dirPath + u"sampleData.xlsx";
//Read input excel file
Workbook workbook(sampleData);
//Accessing the third worksheet in the Excel file
Worksheet worksheet = workbook.GetWorksheets().Get(2);
//Get cells from sheet
Cells cells = worksheet.GetCells();
//Variable declarations
U16String strVal;
Date dateVal;
double dblVal;
bool boolVal;
Enumerator<Cell> enCell = cells.GetEnumerator();
while (enCell.MoveNext())
{
Cell cell = enCell.GetCurrent();
switch (cell.GetType())
{
//Evaluating the data type of the cell data for string value
case CellValueType::IsString:
std::cout <<"Cell Value Type Is String." << std::endl;
strVal = cell.GetStringValue();
break;
//Evaluating the data type of the cell data for double value
case CellValueType::IsNumeric:
std::cout <<"Cell Value Type Is Numeric." << std::endl;
dblVal = cell.GetDoubleValue();
break;
//Evaluating the data type of the cell data for boolean value
case CellValueType::IsBool:
std::cout <<"Cell Value Type Is Bool." << std::endl;
boolVal = cell.GetBoolValue();
break;
//Evaluating the data type of the cell data for date/time value
case CellValueType::IsDateTime:
std::cout <<"Cell Value Type Is DateTime." << std::endl;
dateVal = cell.GetDateTimeValue();
break;
//Evaluating the unknown data type of the cell data
case CellValueType::IsUnknown:
cell.GetStringValue();
break;
default:
break;
}
}
Aspose::Cells::Cleanup();