HtmlService表不支持换行符和电子表格中的超链接 [英] HtmlService table not supporting line breaks and hyperlinks from spreadsheet

查看:106
本文介绍了HtmlService表不支持换行符和电子表格中的超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在撰写Google Apps脚本,使用HtmlService将电子表格中的数据显示到HTML表格中。但我面临两个挑战:


  1. 如果电子表格单元格的值有换行符,则表格显示为单行。

  2. 如果电子表格单元格有超链接,例如链接到Google云端硬盘文件时,它在表格单元格中显示为纯文本。

我尝试将电子表格单元格值编写为< a href =文件的url>文件名称< / a> ,但仍然将表格读取为纯文本而不进行超链接。
以下是HTML代码。



如何以HTML表格中的换行符显示电子表格单元格值?还有如何在电子表格单元格中为表格创建超链接?

 < table cellspacing =0style =width: 700px; background-color:#fdfbc4; table-layout:fixed; word-wrap:break-word> 
<? for(var l = 0; 1< data_labels.length -1; l ++){?>
< tr>
< td> <?= data_labels [1]?> < / TD> < td> <?= data [1]?>< / td>
< / tr>
<? }?>

< / table>


解决方案

显示换行符/空格的简单解决方案>
使用html标签< pre>数据在这里被复制< / pre>

然后,您可以将css类应用到pre元素来更改预定义的字体。
$ b HTML预格式化文本(< pre>)表示预格式化文本。该元素中的文本通常以非比例字体显示,与文件中的文本布局完全相同。此元素中的空白区域显示为键入。


I am writing Google Apps Script to display data from spreadsheet into HTML table using HtmlService. But I faced below two challenges:

  1. If spreadsheet cell value has line breaks into it, table shows it as single line.
  2. If spreadsheet cell has hyperlink e.g. Link to Google Drive file, it shows it as plain text in table cell.

I tried writing spreadsheet cell value as <a href="url of file">File Name</a>, but still table read it as plain text without making hyperlink. Below is the HTML code.

How can I display spreadsheet cell values as it is with line breaks in HTML table? Also how to create hyperlinks in table for urls in spreadsheet cells?

    <table cellspacing="0" style="width:700px; background-color:#fdfbc4; table-layout:fixed; word-wrap: break-word ">
   <? for(var l=0; l< data_labels.length -1 ; l++){ ?>
       <tr>         
         <td> <?= data_labels[l] ?> </td> <td > <?= data[l] ?></td>        
       </tr>
   <? } ?>

   </table>

解决方案

A simple solution to show line breaks/spaces
use the html tag <pre>Data retreived here</pre>
You can then apply a css class to the pre element to change the predefined font.

The HTML Preformatted Text (<pre>) represents preformatted text. Text within this element is typically displayed in a non-proportional font exactly as it is laid out in the file. Whitespaces inside this element are displayed as typed.

这篇关于HtmlService表不支持换行符和电子表格中的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆