Google sheets 谷歌电子表格中的换行符未在谷歌图表表中输出

Google sheets 谷歌电子表格中的换行符未在谷歌图表表中输出,google-sheets,google-visualization,google-spreadsheet-api,Google Sheets,Google Visualization,Google Spreadsheet Api,除了一个我找不到简单方法解决的小格式问题外,这段代码工作得非常好。作为数据源的google电子表格在列中有换行符。但是,在表中,它们似乎只是由空格格式化的。我曾尝试在数据表中使用Allowthml选项(在将换行符转换为标记后),但这会删除所有格式,使表看起来很糟糕。我也尝试过“Formatter”类,但它似乎更倾向于字段的串联,并且遵循相同的无html规则 任何人都知道我这里缺少的东西,可以让换行符在表中正确显示,而不破坏格式。我只想简单地将换行符添加到字段中,以便它们正确显示 您可以将其复制/

除了一个我找不到简单方法解决的小格式问题外,这段代码工作得非常好。作为数据源的google电子表格在列中有换行符。但是,在表中,它们似乎只是由空格格式化的。我曾尝试在数据表中使用Allowthml选项(在将换行符转换为
标记后),但这会删除所有格式,使表看起来很糟糕。我也尝试过“Formatter”类,但它似乎更倾向于字段的串联,并且遵循相同的无html规则

任何人都知道我这里缺少的东西,可以让换行符在表中正确显示,而不破坏格式。我只想简单地将换行符添加到字段中,以便它们正确显示

您可以将其复制/粘贴到jsLint中,它将运行并向您展示我所说的内容

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('visualization', '1', {packages: ['table']});
</script>
<script type="text/javascript">


function drawVisualization() {

  var opts = {dataType:'jsonp'};

  var query = new google.visualization.Query('https://docs.google.com/spreadsheet/pub?key=0AiEVKSSB6IaqdDZBTGJqV0lLZEV3YS0teXZkOWR4M3c&output=html', opts);

  query.setQuery("select * ");

  // Send the query with a callback function.
  query.send(handleQueryResponse);
}

function handleQueryResponse(response) {  
  // Create and populate the data table.
  var data = response.getDataTable();

    // Create and draw the visualization.
  visualization = new google.visualization.Table(document.getElementById('table'));
  visualization.draw(data, null);
}
google.setOnLoadCallback(drawVisualization);

load('visualization','1',{packages:['table']});
函数drawVisualization(){
var opts={dataType:'jsonp'};
var query=new google.visualization.query('https://docs.google.com/spreadsheet/pub?key=0AiEVKSSB6IaqdDZBTGJqV0lLZEV3YS0teXZkOWR4M3c&output=html",选择),;
query.setQuery(“选择*”);
//使用回调函数发送查询。
发送(handleQueryResponse);
}
函数handleQueryResponse(响应){
//创建并填充数据表。
var data=response.getDataTable();
//创建并绘制可视化。
可视化=新的google.visualization.Table(document.getElementById('Table');
可视化。绘制(数据,空);
}
setOnLoadCallback(drawVisualization);


这可能是一个有点老套的解决方案,但是使用JavaScript方法来解决这个问题怎么样?我还添加了少量CSS,以便新表具有底部垂直对齐(就像原始电子表格一样)


load('visualization','1',{packages:['table']});
函数drawVisualization(){
var opts={dataType:'jsonp'};
var query=new google.visualization.query('https://docs.google.com/spreadsheet/pub?key=0AiEVKSSB6IaqdDZBTGJqV0lLZEV3YS0teXZkOWR4M3c&output=html",选择),;
query.setQuery(“选择*”);
//使用回调函数发送查询。
发送(handleQueryResponse);
}
函数handleQueryResponse(响应){
//创建并填充数据表。
var data=new google.visualization.DataTable(
response.getDataTable().toJSON().split(\\n”).join(
); var opts={'allowtml':true}; //创建并绘制可视化。 可视化=新的google.visualization.Table(document.getElementById('Table'); 可视化。绘制(数据、选项); } setOnLoadCallback(drawVisualization); .google可视化表格td{ 垂直对齐:底部对齐; }
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('visualization', '1', {packages: ['table']});
</script>
<script type="text/javascript">

function drawVisualization() {
  var opts = {dataType:'jsonp'};
  var query = new google.visualization.Query('https://docs.google.com/spreadsheet/pub?key=0AiEVKSSB6IaqdDZBTGJqV0lLZEV3YS0teXZkOWR4M3c&output=html', opts);

  query.setQuery("select * ");

  // Send the query with a callback function.
  query.send(handleQueryResponse);
}

function handleQueryResponse(response) {
  // Create and populate the data table.
  var data = new google.visualization.DataTable(
        response.getDataTable().toJSON().split("\\n").join("<br />"));

  var opts = {'allowHtml': true};

  // Create and draw the visualization.
  visualization = new google.visualization.Table(document.getElementById('table'));
  visualization.draw(data, opts);
}

google.setOnLoadCallback(drawVisualization);

</script>

<style type="text/css">
.google-visualization-table-td{
    vertical-align: bottom;
}
</style>
<div id="table"></div>