إدارة بيانات ملفات Excel.

إضافة البيانات إلى Cells

Aspose.Cells يوفر فصل دراسي ،دفتر العمل ، يمثل ملف Excel Microsoft. الدفتر العمل فئة تحتوي علىأوراق عمل مجموعة تسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطةورقة عمل صف دراسي. الورقة عمل فئة توفر أCells مجموعة. كل عنصر فيCells تمثل المجموعة كائنًا منCellصف دراسي.

Aspose.Cells يسمح للمطورين بإضافة بيانات إلى الخلايا في أوراق العمل عن طريق استدعاءCell صف دراسي'ضع القيمة طريقة. يوفر Aspose.Cells إصدارات محملة بشكل زائد منضع القيمة طريقة تتيح للمطورين إضافة أنواع مختلفة من البيانات إلى الخلايا. استخدام هذه الإصدارات المحملة بشكل زائد منضع القيمةطريقة ، من الممكن إضافة قيم منطقية أو سلسلة أو مزدوجة أو عدد صحيح أو تاريخ / وقت ، إلخ إلى الخلية.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Adding a string value to the cell
worksheet.Cells["A1"].PutValue("Hello World");
// Adding a double value to the cell
worksheet.Cells["A2"].PutValue(20.5);
// Adding an integer value to the cell
worksheet.Cells["A3"].PutValue(15);
// Adding a boolean value to the cell
worksheet.Cells["A4"].PutValue(true);
// Adding a date/time value to the cell
worksheet.Cells["A5"].PutValue(DateTime.Now);
// Setting the display format of the date
Style style = worksheet.Cells["A5"].GetStyle();
style.Number = 15;
worksheet.Cells["A5"].SetStyle(style);
// Saving the Excel file
workbook.Save(dataDir + "output.out.xls");

تحسين الكفاءة

إذا كنت تستخدمضع القيمةطريقة لوضع كمية كبيرة من البيانات في ورقة عمل ، يجب إضافة قيم إلى الخلايا ، أولاً بالصفوف ثم بالأعمدة. يعمل هذا الأسلوب على تحسين كفاءة تطبيقاتك بشكل كبير.

استرجاع البيانات من Cells

Aspose.Cells يوفر فصل دراسي ،دفتر العمل يمثل ملف Excel Microsoft. الدفتر العمل فئة تحتوي علىأوراق عمل مجموعة تسمح بالوصول إلى أوراق العمل الموجودة في الملف. يتم تمثيل ورقة العمل بواسطةورقة عمل صف دراسي. الورقة عمل فئة توفر أCells مجموعة. كل عنصر فيCells تمثل المجموعة كائنًا منCellصف دراسي.

الCellيوفر class العديد من الخصائص التي تسمح للمطورين باسترداد القيم من الخلايا وفقًا لأنواع البيانات الخاصة بهم. تشمل هذه الخصائص:

عندما لا يتم ملء أحد الحقول ، فإن الخلايا ذاتضعف القيمة أوFloatValueيرمي استثناء.

يمكن أيضًا التحقق من نوع البيانات الموجودة في خلية باستخدامCell صف دراسي'يكتب خاصية. في الواقع، فإنCell صف دراسي'يكتب الممتلكات على أساسCellValueTypeالتعداد الذي تم سرد قيمه المحددة مسبقًا أدناه:

Cell أنواع القيمة وصف
IsBool تحدد أن قيمة الخلية منطقية.
IsDateTime يحدد أن قيمة الخلية هي التاريخ / الوقت.
باطل يمثل خلية فارغة.
هو رقم تحدد أن قيمة الخلية رقمية.
IsString تحدد أن قيمة الخلية عبارة عن سلسلة.
غير معروف يحدد أن قيمة الخلية غير معروفة.

يمكنك أيضًا استخدام أنواع قيم الخلايا المحددة مسبقًا للمقارنة بنوع البيانات الموجودة في كل خلية.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Opening an existing workbook
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Accessing first worksheet
Worksheet worksheet = workbook.Worksheets[0];
foreach (Cell cell1 in worksheet.Cells)
{
// Variables to store values of different data types
string stringValue;
double doubleValue;
bool boolValue;
DateTime dateTimeValue;
// Passing the type of the data contained in the cell for evaluation
switch (cell1.Type)
{
// Evaluating the data type of the cell data for string value
case CellValueType.IsString:
stringValue = cell1.StringValue;
Console.WriteLine("String Value: " + stringValue);
break;
// Evaluating the data type of the cell data for double value
case CellValueType.IsNumeric:
doubleValue = cell1.DoubleValue;
Console.WriteLine("Double Value: " + doubleValue);
break;
// Evaluating the data type of the cell data for boolean value
case CellValueType.IsBool:
boolValue = cell1.BoolValue;
Console.WriteLine("Bool Value: " + boolValue);
break;
// Evaluating the data type of the cell data for date/time value
case CellValueType.IsDateTime:
dateTimeValue = cell1.DateTimeValue;
Console.WriteLine("DateTime Value: " + dateTimeValue);
break;
// Evaluating the unknown data type of the cell data
case CellValueType.IsUnknown:
stringValue = cell1.StringValue;
Console.WriteLine("Unknown Value: " + stringValue);
break;
// Terminating the type checking of type of the cell data is null
case CellValueType.IsNull:
break;
}
}

موضوعات مسبقة