البرمجة

تنسيق الأرقام العشرية في Excel

To export double values with a comma as a grouping symbol in Excel, you can use a library like Apache POI in Java. Here’s a basic example of how you can achieve this:

java
import org.apache.poi.ss.usermodel.*; import java.io.FileOutputStream; import java.io.IOException; import java.util.Locale; public class ExcelExport { public static void main(String[] args) { Workbook workbook = null; try { workbook = WorkbookFactory.create(true); // create a new workbook Sheet sheet = workbook.createSheet("Sheet1"); // create a sheet // create a cell style with custom format CellStyle style = workbook.createCellStyle(); style.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("#,##0.00")); // create a cell and set the value with the custom format Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellValue(100000000.00); cell.setCellStyle(style); // write the workbook to a file try (FileOutputStream fileOut = new FileOutputStream("output.xlsx")) { workbook.write(fileOut); } } catch (IOException e) { e.printStackTrace(); } finally { if (workbook != null) { try { workbook.close(); } catch (IOException e) { e.printStackTrace(); } } } } }

This code creates an Excel workbook with a single cell containing the value 100000000.00 formatted with commas as grouping symbols. Note that you might need to adjust the locale settings to ensure that the comma is used as the grouping symbol and the dot as the decimal separator, depending on your system’s locale settings.

المزيد من المعلومات

لتصدير القيم العشرية بفاصلة كفاصلة تجميع في إكسل، يمكنك استخدام مكتبة Apache POI في جافا. يجب أن تكون المكتبة مضافة إلى مشروعك كمتغير تابع (dependency) في Maven أو Gradle. هنا مثال آخر يوضح كيفية تحقيق ذلك:

java
import org.apache.poi.ss.usermodel.*; import java.io.FileOutputStream; import java.io.IOException; import java.util.Locale; public class ExcelExport { public static void main(String[] args) { Workbook workbook = null; try { workbook = WorkbookFactory.create(true); // إنشاء جدول بيانات جديد Sheet sheet = workbook.createSheet("Sheet1"); // إنشاء ورقة بيانات // إنشاء نمط للخلية بتنسيق مخصص CellStyle style = workbook.createCellStyle(); style.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("#,##0.00")); // إنشاء خلية وتعيين القيمة بالتنسيق المخصص Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellValue(100000000.00); cell.setCellStyle(style); // كتابة جدول البيانات إلى ملف try (FileOutputStream fileOut = new FileOutputStream("output.xlsx")) { workbook.write(fileOut); } } catch (IOException e) { e.printStackTrace(); } finally { if (workbook != null) { try { workbook.close(); } catch (IOException e) { e.printStackTrace(); } } } } }

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

مقالات ذات صلة

زر الذهاب إلى الأعلى

هذا المحتوى محمي من النسخ لمشاركته يرجى استعمال أزرار المشاركة السريعة أو تسخ الرابط !!