إعدادات الرقم
ضبط تنسيقات العرض Numbers والتواريخ
من الميزات القوية جدًا لبرنامج Microsoft Excel أنه يتيح للمستخدمين تعيين تنسيقات عرض القيم الرقمية والتواريخ. نحن نعلم أنه يمكن استخدام البيانات الرقمية لتمثيل قيم مختلفة بما في ذلك القيم العشرية والعملة والنسبة المئوية والكسر أو القيم المحاسبية ، إلخ. يتم عرض جميع هذه القيم الرقمية في تنسيقات مختلفة اعتمادًا على نوع المعلومات التي تمثلها. وبالمثل ، هناك العديد من التنسيقات التي يمكن عرض التاريخ أو الوقت بها. Aspose.Cells يدعم هذه الوظيفة ويسمح للمطورين بتعيين أي تنسيق عرض لرقم أو تاريخ.
ضبط تنسيقات العرض في Microsoft Excel
لتعيين تنسيقات العرض في Microsoft Excel:
- انقر بزر الماوس الأيمن فوق أي خلية.
- يختارشكل Cells. سيظهر مربع حوار يستخدم لتعيين تنسيقات العرض لأي نوع من القيمة.
في الجانب الأيسر من مربع الحوار ، هناك العديد من فئات القيم مثلعام, عدد, عملة, محاسبة, تاريخ, وقت, **النسبة المئوية،**الخ Aspose.Cells يدعم كل تنسيقات العرض هذه.
Aspose.Cells يوفر فصل دراسي ،دفتر العمل يمثل ملف Excel Microsoft. الدفتر العمل فئة تحتوي علىأوراق عمل مجموعة تسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطةورقة عمل صف دراسي. الورقة عمل فئة توفر أCells مجموعة. كل عنصر فيCells تمثل المجموعة كائنًا منCellصف دراسي.
يوفر Aspose.CellsGetStyle وSetStyle طرقCell صف دراسي. تُستخدم هذه الطرق للحصول على تنسيق الخلية وتعيينه. الأسلوبتوفر class بعض الخصائص المفيدة للتعامل مع تنسيقات عرض الأرقام والتواريخ.
استخدام تنسيقات الأرقام المضمنة
يقدم Aspose.Cells بعض تنسيقات الأرقام المضمنة لتكوين تنسيقات عرض الأرقام والتواريخ. يمكن تطبيق تنسيقات الأرقام المضمنة هذه باستخدام امتدادعدد ممتلكاتأسلوب موضوع. يتم إعطاء جميع تنسيقات الأرقام المضمنة قيمًا رقمية فريدة. يمكن للمطورين تعيين أي قيمة رقمية مطلوبة لملفعدد ممتلكاتأسلوبكائن لتطبيق تنسيق العرض. هذا النهج سريع. يتم سرد تنسيقات الأرقام المضمنة التي يدعمها Aspose.Cells أدناه.
قيمة | يكتب | تنسيق السلسلة |
---|---|---|
0 | عام | عام |
1 | عدد عشري | 0 |
2 | عدد عشري | 0.00 |
3 | عدد عشري | # ,##0 |
4 | عدد عشري | # ,##0.00 |
5 | عملة | $#,##0;$-#,##0 |
6 | عملة | $ # ، ## 0 ؛ [أحمر] $ - # ، ## 0 |
7 | عملة | $#,##0.00;$-#,##0.00 |
8 | عملة | $ # ، ## 0.00 ؛ [أحمر] $ - # ، ## 0.00 |
9 | النسبة المئوية | 0% |
10 | النسبة المئوية | 0.00% |
11 | علمي | 0.00E + 00 |
12 | جزء | # ?/? |
13 | جزء | # / |
14 | تاريخ | م / ي / س س س |
15 | تاريخ | د-ش ش-س ص |
16 | تاريخ | د ممممم |
17 | تاريخ | ش ش-س ص |
18 | وقت | ح: مم ص / م |
19 | وقت | h: mm: ss am / pm |
20 | وقت | همم |
21 | وقت | h: mm: ss |
22 | وقت | م / ي / س س س: مم |
37 | عملة | # ,##0;-#,##0 |
38 | عملة | # ، ## 0 ؛ [أحمر] - # ، ## 0 |
39 | عملة | # ,##0.00;-#,##0.00 |
40 | عملة | # ، ## 0.00 ؛ [أحمر] - # ، ## 0.00 |
41 | محاسبة | _ * #,##0_ ;_ * “_ ;_ @_ |
42 | محاسبة | _ $* #,##0_ ;_ $* “_ ;_ @_ |
43 | محاسبة | _ * #,##0.00_ ;_ * “??_ ;_ @_ |
44 | محاسبة | _ $* #,##0.00_ ;_ $* “??_ ;_ @_ |
45 | وقت | مم: ss |
46 | وقت | h: mm: ss |
47 | وقت | مم: ss.0 |
48 | علمي | ## 0.0E + 00 |
49 | نص | @ |
// 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 first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Adding the current system date to "A1" cell | |
worksheet.Cells["A1"].PutValue(DateTime.Now); | |
// Getting the Style of the A1 Cell | |
Style style = worksheet.Cells["A1"].GetStyle(); | |
// Setting the display format to number 15 to show date as "d-mmm-yy" | |
style.Number = 15; | |
// Applying the style to the A1 cell | |
worksheet.Cells["A1"].SetStyle(style); | |
// Adding a numeric value to "A2" cell | |
worksheet.Cells["A2"].PutValue(20); | |
// Getting the Style of the A2 Cell | |
style = worksheet.Cells["A2"].GetStyle(); | |
// Setting the display format to number 9 to show value as percentage | |
style.Number = 9; | |
// Applying the style to the A2 cell | |
worksheet.Cells["A2"].SetStyle(style); | |
// Adding a numeric value to "A3" cell | |
worksheet.Cells["A3"].PutValue(2546); | |
// Getting the Style of the A3 Cell | |
style = worksheet.Cells["A3"].GetStyle(); | |
// Setting the display format to number 6 to show value as currency | |
style.Number = 6; | |
// Applying the style to the A3 cell | |
worksheet.Cells["A3"].SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); |
استخدام تنسيقات الأرقام المخصصة
لتحديد سلسلة التنسيق المخصصة الخاصة بك لتعيين تنسيق العرض ، استخدم ملحقأسلوب أشياءالعادةخاصية. هذا النهج ليس بنفس سرعة استخدام التنسيقات المحددة مسبقًا ولكنه أكثر مرونة.
// 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(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Adding the current system date to "A1" cell | |
worksheet.Cells["A1"].PutValue(DateTime.Now); | |
// Getting the style of A1 cell | |
Style style = worksheet.Cells["A1"].GetStyle(); | |
// Setting the custom display format to show date as "d-mmm-yy" | |
style.Custom = "d-mmm-yy"; | |
// Applying the style to A1 cell | |
worksheet.Cells["A1"].SetStyle(style); | |
// Adding a numeric value to "A2" cell | |
worksheet.Cells["A2"].PutValue(20); | |
// Getting the style of A2 cell | |
style = worksheet.Cells["A2"].GetStyle(); | |
// Setting the custom display format to show value as percentage | |
style.Custom = "0.0%"; | |
// Applying the style to A2 cell | |
worksheet.Cells["A2"].SetStyle(style); | |
// Adding a numeric value to "A3" cell | |
worksheet.Cells["A3"].PutValue(2546); | |
// Getting the style of A3 cell | |
style = worksheet.Cells["A3"].GetStyle(); | |
// Setting the custom display format to show value as currency | |
style.Custom = "£#,##0;[Red]$-#,##0"; | |
// Applying the style to A3 cell | |
worksheet.Cells["A3"].SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); |