إضافة نص HTML غني داخل الخلية
Aspose.Cells يدعم تحويل HTML موجه من Microsoft Excel إلى تنسيق XLS/XLSX. يعني أن HTML الذي تم إنشاؤه بواسطة Microsoft Excel يمكن تحويله مرة أخرى إلى تنسيق XLS/XLSX باستخدام Aspose.Cells.
بالمثل، إذا كان هناك بعض HTML بسيط، يمكن لـ Aspose.Cells تحويله إلى Rich Text HTML. يوفر Aspose.Cells الخاصيةCell.setHtmlString() التي يمكن أن تأخذ مثل هذا HTML البسيط وتحويله إلى نص خلية منسق.
مثال
توضح اللقطة الشاشة التالية ملف Excel الناتج الذي تم إنشاؤه باستخدام Aspose.Cells. كما ترون، فإنه يظهر نص HTML متنسق الذي تم إضافته داخل الخلية A1 باستخدام خاصية Cell.setHtmlString().
هذا هو الكود النموذجي الذي أنشأ ملف Excel الناتج كما هو موضح داخل اللقطة الشاشة أعلاه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
String dataDir = Utils.getDataDir(AddImageHyperlinks.class); | |
// Instantiate a new workbook | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Insert a string value to a cell | |
worksheet.getCells().get("C2").setValue("Image Hyperlink"); | |
// Set the 4th row height | |
worksheet.getCells().setRowHeight(3, 100); | |
// Set the C column width | |
worksheet.getCells().setColumnWidth(2, 21); | |
// Add a picture to the C4 cell | |
int index = worksheet.getPictures().add(3, 2, 4, 3, dataDir + "aspose-logo.jpg"); | |
// Get the picture object | |
com.aspose.cells.Picture pic = worksheet.getPictures().get(index); | |
// Set the placement type | |
pic.setPlacement(PlacementType.FREE_FLOATING); | |
// Add an image hyperlink | |
pic.addHyperlink("http://www.aspose.com/"); | |
com.aspose.cells.Hyperlink hlink = pic.getHyperlink(); | |
// Specify the screen tip | |
hlink.setScreenTip("Click to go to Aspose site"); | |
// Save the Excel file | |
workbook.save(dataDir + "ImageHyperlink.xls"); |