Ajout de texte enrichi HTML dans la cellule avec C++
Contents
[
Hide
]
Aspose.Cells prend en charge la conversion de HTML orienté Microsoft Excel en format XLS/XLSX. Cela signifie que le HTML généré par Microsoft Excel peut être converti en format XLS/XLSX en utilisant Aspose.Cells.
De même, s’il y a un HTML simple, Aspose.Cells peut le convertir en HTML Rich Text. Aspose.Cells fournit la méthode Cell::GetHtmlString qui peut prendre un HTML simple et le convertir en texte de cellule formaté.
L’exemple de code ci-dessous vous montre comment ajouter du texte enrichi HTML dans la cellule. Veuillez consulter la capture d’écran du fichier Excel de sortie.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Create a new workbook
Workbook workbook;
// Get the first worksheet
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Access cell A1
Cell cell = worksheet.GetCells().Get(u"A1");
// Set HTML formatted text in the cell
cell.SetHtmlString(u"<Font Style=\"FONT-WEIGHT: bold;FONT-STYLE: italic;TEXT-DECORATION: underline;FONT-FAMILY: Arial;FONT-SIZE: 11pt;COLOR: #ff0000;\">This is simple HTML formatted text.</Font>");
// Save the workbook
workbook.Save(outDir + u"output_out.xlsx");
std::cout << "HTML formatted text added to cell A1 successfully!" << std::endl;
Aspose::Cells::Cleanup();
}