Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 在文档中创建一个表格,其中多个单元格位于另一个单元格的前面_Google Apps Script_Google Docs - Fatal编程技术网

Google apps script 在文档中创建一个表格,其中多个单元格位于另一个单元格的前面

Google apps script 在文档中创建一个表格,其中多个单元格位于另一个单元格的前面,google-apps-script,google-docs,Google Apps Script,Google Docs,我需要创建一个与图像中的表相等的表,我有排列中的数据 我只创建了简单的表 一个示例数据数组,以及到目前为止我的代码: employees=[{ 'factor':'Clientes', 'caracteristica':'Tipo de Persona', 'descripcion':'Posibilidad de que las personas naturales, juridicas..' },{ 'factor':'Clientes', 'caracteri

我需要创建一个与图像中的表相等的表,我有排列中的数据

我只创建了简单的表

一个示例数据数组,以及到目前为止我的代码:

employees=[{    
  'factor':'Clientes',
  'caracteristica':'Tipo de Persona',
  'descripcion':'Posibilidad de que las personas naturales, juridicas..'
},{
  'factor':'Clientes',
  'caracteristica':'Tipo de Regimen',
  'descripcion':'Posibilidad de que los clientes incluidos...'
},{    
  'factor':'Clientes',
  'caracteristica':'Actividad Economica',
  'descripcion':'Posibilidad de que los clientes...'
},{
  'factor':'Productos y/o Servicios',
  'caracteristica':'Servicios',  
  'descripcion':'Posibilidad de que los distintos servicios ofrecidos '
},{
  'factor':'Productos y/o Servicios',
  'caracteristica':'Canales de distribucion',  
  'descripcion':'Posibilidad de que los canales....'
},{
  'factor':'Zona Geografica',
  'caracteristica':'Zona de Frontera',  
  'descripcion':'Presencia en Zonas de frontera con incidencias............'
},{
  'factor':'Zona Geografica',
  'caracteristica':'Zona de Produccion de Hoja de Coca',  
  'descripcion':'Presencia en Zonas para la produccion de hoja de coca.........'
},{
  'factor':'Zona Geografica',
  'caracteristica':'Zona de Minera',  
  'descripcion':'Presencia en Zonas con actividades...'
}];

function funcion2(employees) {
  var doc = DocumentApp.openById('some id');
  var nombre = ''
  var body = doc.getBody();
  var header = body.appendParagraph("Anexo 01");
  header.setAlignment(DocumentApp.HorizontalAlignment.CENTER)
    .editAsText().setFontSize(12);

  var header2 = body.appendParagraph("IDENTIFICACIÓN DE LOS RIESGOS DE LAFT Y RIESGOS ASOCIADOS");
  header2.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
  body.appendParagraph("");
  var section = body.appendParagraph("Para identificar los riesgos de LAFT y riesgos asociados, de acuerdo con la clasificación y caracterización " + nombre + "-" + descripcion);
  section.setAlignment(DocumentApp.HorizontalAlignment.JUSTIFY);
  body.appendParagraph("");

  var tableCliente = body.appendTable();
  var tr1 = tableCliente.appendTableRow();
  var tb = tr1.appendTableCell("CLIENTE").setBackgroundColor("#84cdff");

  var table = body.appendTable();
  for (var i = 0; i < employees.length; i++) {
    if (employees[i].factor == "CLIENTES") {
      var tr=table.appendTableRow();
      var tb = tr.appendTableCell(employees[i].caracteristica).setWidth(90);
      var tb = tr.appendTableCell(employees[i].descripcion);
    }
  }
}
employees=[{
“因素”:“客户”,
“性格特征”:“人格特征”,
“描述”:“自然人、法人的地位”
},{
“因素”:“客户”,
“caracteristica”:“Tipo de currency”,
“描述”:“包括客户在内的所有客户的职位……”
},{    
“因素”:“客户”,
“caracteristica”:“经济活动”,
“描述”:“客户的位置……”
},{
“因素”:“产品/服务”,
“caracteristica”:“Servicios”,
‘描述’:‘提供维修服务的位置’
},{
“因素”:“产品/服务”,
"特征":"分配运河",,
‘描述’:‘运河的位置·························
},{
‘因素’:‘地理地带’,
“caracteristica”:“Zona de Frontera”,
‘描述’:‘前线交通事故现场……’
},{
‘因素’:‘地理地带’,
“特色”:“古柯生产区”,
‘描述’:‘古柯生产区的现状……’
},{
‘因素’:‘地理地带’,
“caracteristica”:“Zona de Minera”,
“描述”:“活动区域的展示……”
}];
职能职能2(员工){
var doc=DocumentApp.openById('some id');
var nombre=“”
var body=doc.getBody();
var表头=正文附录段落(“Anexo 01”);
标题.设置对齐(文档页.水平对齐.中心)
.editAsText().setFontSize(12);
var header2=主体。附录段落(“LAFT Y RIESGOS ASOCIADOS的识别”);
头部2.设置校准(文档页水平校准中心);
正文。附录第段(“”);
var section=正文附录段落(“第三段,分类和特征描述”);
第.SETALIGNIZE节(文档页:水平对齐.对齐);
正文。附录第段(“”);
var tableCliente=body.appendTable();
var tr1=tableCliente.appendTableRow();
var tb=tr1.appendTableCell(“客户”).setBackgroundColor(“84cdff”);
var table=body.appendTable();
对于(变量i=0;i
我不确定您为什么要使用脚本来执行此操作。我认为在页面编辑器中创建表要简单得多

  • 打开一个空白文档
  • 从主菜单中选择“插入”、“表格”,然后指定3列9行
  • 在第一行的所有三列中键入标题
  • 在所有其他行的第二列和第三列中键入内容
  • 在第一列中,选择第二、第三和第四个单元格;右键单击并选择“合并单元格”
  • 在第1列中,选择第5和第6个单元格;右键单击并选择“合并单元格”
  • 在第1列中,选择第7、第8和第9个单元格;右键单击并选择“合并单元格”
  • 在第1列的三个合并单元格中输入内容
  • 选择任意单元格,单击鼠标右键,选择“表属性”。在“单元格垂直对齐”下,选择“中间”
  • 选择第1行并更改背景颜色以适合

脚本选项

OP希望通过脚本创建一个表,它的一个特性是在第一列中合并某些“公共”单元格。OP的代码一直到表的标题

在谷歌文档中创建表格时,没有太多的资源可供使用。此外,很明显,对表的引用强调了“按行”方面,基于列的事件/命令供不应求

表内容的构造有两个选项。在这段代码中,我遵循了OP的方法,通过对象循环并使用内容逐步更新表。另一种方法是构建一个新的数组,然后根据该数组构建表,构建方式与Google中描述的方式大致相同

员工=[{
‘因素’:‘客户’,
“Caratractica”:“Tipo de Persona”,
“描述”:“自然人、法人的地位”
}, {
‘因素’:‘客户’,
“caracteristica”:“Tipo de Regulation”,
“描述”:“包括客户在内的客户的职位……”
}, {
‘因素’:‘客户’,
“caracteristica”:“经济活动”,
“描述”:“客户的位置……”
}, {
“因素”:“产品/服务”,
“caracteristica”:“Servicios”,
‘描述’:‘为客户提供服务的职位’
}, {
“因素”:“产品/服务”,
"特征":"分配运河",,
‘描述’:‘运河码头……’
}, {
‘因素’:‘地理地带’,
“caracteristica”:“Zona de Frontera”,
‘描述’:‘前线交通事故现场……’
}, {
‘因素’:‘地理地带’,
“特色”:“古柯生产区”,
‘描述’:‘古柯生产区的现状……’
}, {
‘因素’:‘地理地带’,
“caracteristica”:“Zona de Minera”,
“描述”:“活动区域内的展示……”
}];
功能so5501193401(){
//定义在标题行中添加单元格时将使用的标题单元格样式
//背景色,文本粗体,白色
var headerStyle={};
headerStyle[DocumentApp.Attribute.BACKGROUND_COLOR]=“84cdff”;
headerStyle[DocumentApp.Attribute.BOLD]=true;
headerStyle[DocumentApp.Attribute.FOREGROUND_COLOR]='#FFFFFF';
//风格
employees = [{
  'factor': 'Clientes',
  'caracteristica': 'Tipo de Persona',
  'descripcion': 'Posibilidad de que las personas naturales, juridicas..'
}, {
  'factor': 'Clientes',
  'caracteristica': 'Tipo de Regimen',
  'descripcion': 'Posibilidad de que los clientes incluidos...'
}, {
  'factor': 'Clientes',
  'caracteristica': 'Actividad Economica',
  'descripcion': 'Posibilidad de que los clientes...'
}, {
  'factor': 'Productos y/o Servicios',
  'caracteristica': 'Servicios',
  'descripcion': 'Posibilidad de que los distintos servicios ofrecidos '
}, {
  'factor': 'Productos y/o Servicios',
  'caracteristica': 'Canales de distribucion',
  'descripcion': 'Posibilidad de que los canales....'
}, {
  'factor': 'Zona Geografica',
  'caracteristica': 'Zona de Frontera',
  'descripcion': 'Presencia en Zonas de frontera con incidencias............'
}, {
  'factor': 'Zona Geografica',
  'caracteristica': 'Zona de Produccion de Hoja de Coca',
  'descripcion': 'Presencia en Zonas para la produccion de hoja de coca.........'
}, {
  'factor': 'Zona Geografica',
  'caracteristica': 'Zona de Minera',
  'descripcion': 'Presencia en Zonas con actividades...'
}];

function so5501193401() {

  //define header cell style which we will use while adding cells in header row
  //Background color, text bold, white
  var headerStyle = {};
  headerStyle[DocumentApp.Attribute.BACKGROUND_COLOR] = '#84cdff';
  headerStyle[DocumentApp.Attribute.BOLD] = true;
  headerStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = '#FFFFFF';

  //Style for the cells other than header row
  var cellStyle = {};
  cellStyle[DocumentApp.Attribute.BOLD] = false;
  cellStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = '#000000';

  //By default, each paragraph had space after, so we will change the paragraph style to add zero space
  //we will use it later
  var paraStyle = {};
  paraStyle[DocumentApp.Attribute.SPACING_AFTER] = 0;
  paraStyle[DocumentApp.Attribute.LINE_SPACING] = 1;

  //setup the document reference
  var docid = "<<insert document id as a string>>";
  var doc = DocumentApp.openById(docid);
  var body = doc.getBody();

  // build the document introduction
  var header = body.appendParagraph("Anexo 01");
  header.setAlignment(DocumentApp.HorizontalAlignment.CENTER).editAsText().setFontSize(12);
  var header2 = body.appendParagraph("IDENTIFICACIÓN DE LOS RIESGOS DE LAFT Y RIESGOS ASOCIADOS");
  header2.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
  body.appendParagraph("");
  var section = body.appendParagraph("Para identificar los riesgos de LAFT y riesgos asociados, de acuerdo con la clasificación y caracterización");
  section.setAlignment(DocumentApp.HorizontalAlignment.JUSTIFY);
  body.appendParagraph("");

  // variables for the loop
  var factortext = "";
  var factorcounter = 0

  // build the header row of the table
  var table = body.appendTable();
  var tr = table.appendTableRow();
  var col1title = "Factores de riesgo";
  var col2title = "Caracteristica";
  var col3title = "Descripcion del Riesgo de LAFT";
  var th = tr.appendTableCell(col1title);
  th.setAttributes(headerStyle);
  var th = tr.appendTableCell(col2title);
  th.setAttributes(headerStyle);
  var th = tr.appendTableCell(col3title);
  th.setAttributes(headerStyle);

  // create a loop to work through the 'employees' object
  for (var i = 0; i < employees.length; i++) {

    // add a row and define the cell contents
    var tr = table.appendTableRow();
    var factorname = employees[i].factor;
    var caraname = employees[i].caracteristica;
    var descname = employees[i].descripcion;

    //establish if this is the first row or not
    if (factorcounter != 0) {
      // Logger.log("DEBUG: i: "+i+", record#"+(i+1));//DEBUG
      var factorname = employees[i].factor;
      // Logger.log("DEBUG: factor: "+factorname);//DEBUG

      // establish if this is the continuation or beginning of a new factor group
      if (factortext != factorname) { // this is a new group
        var td = tr.appendTableCell(factorname);
        td.setAttributes(cellStyle);
      } else {
        var td = tr.appendTableCell("");
      }

      factortext = factorname;
    }

    // establish if this is the first row of the table
    if (factorcounter == 0) {
      // Logger.log("DEBUG: i: "+i+", record#1");//DEBUG
      var factorname = employees[i].factor;
      factortext = factorname;
      //Logger.log("DEBUG: factor: "+factorname);//DEBUG
      var td = tr.appendTableCell(factorname);
      td.setAttributes(cellStyle);
    }

    // increment the factor counter
    factorcounter++;

    // insert the characttics and description
    var td = tr.appendTableCell(caraname);
    td.setAttributes(cellStyle);
    var td = tr.appendTableCell(descname);
    td.setAttributes(cellStyle);

  }

}