html - 如何让cfspreadsheet渲染html

标签 html coldfusion coldfusion-9 cfspreadsheet

我正在尝试使用 cfspreadsheet 创建一个 excel 文件。在其中一列中,我有 html 代码,但由于某种原因,在 excel 文件中,html 没有呈现它只是纯文本。例如。 <b>blabla</b>而不是加粗。

你知道解决这个问题的方法吗?

最佳答案

原因是 cfspreadsheet 是基于兴趣点 does not support html content .

作为user1450455 mentions ,您可以使用任何内置的格式化函数(例如 SpreadsheetFormatCell)来格式化整个单元格。

  sheet = spreadSheetNew();
  spreadSheetFormatCell( sheet, {bold=true} , 1, 1 );
  spreadSheetSetCellValue( sheet, "blablah", 1, 1 );

如果您要创建 cells with multiple formats (即加粗一些字符而不是其他字符)只有通过创建 RichTextString 才能使用基础 POI 库.所以它需要低得多的代码。

<cfscript>
    sheet     = spreadSheetNew();
    workbook  = sheet.getWorkBook();
    helper    = workbook.getCreationHelper();
    richText  = helper.createRichTextString("ColdFusion");

    // make first few characters bold ie "Cold"
    firstFont = workbook.createFont();
    firstFont.setBoldweight( firstFont.BOLDWEIGHT_BOLD );
    richText.applyFont( 0, 4, firstFont );

    // make next characters red ie "Fusion"
    secondFont = workbook.createFont();
    secondFont.setColor( secondFont.COLOR_RED );
    richText.applyFont( 4, 10, secondFont );

    // create cell via CF and apply formats
    // note, in POI indexes are base 0
    spreadSheetSetCellValue( sheet, "", 2, 1);
    cellA2 = workbook.getSheetAt(0).getRow(1).getCell(0);
    cellA2.setCellValue( richText );
</cfscript>

关于html - 如何让cfspreadsheet渲染html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13166522/

相关文章:

javascript 代码不工作。可能将它错误地附加到 html 页面

css - 如何让 3 个 div 显示在一行中,如果我调整浏览器大小则不会换行?

php - Ajax序列化;无法在 PHP 中使用 'read' 变量

JavaScript 在 Chrome 扩展 HTML 桌面通知中不起作用

mysql - ColdFusion 数据库设置

coldfusion - 使用应用程序范围的 UDF 扩展 ColdFusion

solr - Solr 和 Verity 中相同文件的上下文不一致

jdbc - Jaybird JDBC 3.0 - 连接超时

coldfusion - 如何测试事务中执行的查询没有错误?

mysql - 读取 MySQL 数据库中存储为 BLOB 的 Word DOC