2017-04-14 101 views
0

您如何将背景颜色设置为透明,使用Google Docs API。我可以将背景设置为特定颜色,即“#aa00aa”。但是,我不确定如何将其设置为透明。例如,假设您拥有:Google Docs API将透明字体背景设置为

function myTypes() { 
    var selection = DocumentApp.getActiveDocument().getSelection(); 
    if (selection) { 
    var elements = selection.getRangeElements(); 
    for (var i = 0; i < elements.length; i++) { 
     var element = elements[i]; 

     // Only modify elements that can be edited as text; skip images and other non-text elements. 
     if (element.getElement().editAsText) { 
      var text = element.getElement().editAsText(); 

      // Edit the selected part of the element, or the full element if it's completely selected. 
      if (element.isPartial()) { 
       text.setFontSize(element.getStartOffset(), element.getEndOffsetInclusive(), 10); 
       text.setFontFamily(element.getStartOffset(), element.getEndOffsetInclusive(), "Consolas"); 
       text.setForegroundColor(element.getStartOffset(), element.getEndOffsetInclusive(), "#cc0cc"); 
       text.setBackgroundColor(element.getStartOffset(), element.getEndOffsetInclusive(), "#aa00aa"); 
      } else { 
       text.setFontSize(10); 
       text.setFontFamily("Consolas"); 
       text.setForegroundColor("#cc00cc"); 
       text.setBackgroundColor("#aa00aa"); 
      } 
     } 
    }} 
} 

回答

0

我发现使用可以使用术语“空”而不加引号。

text.setBackgroundColor(null); 
1

对我而言,使用rgba代码(例如,

rgba(255, 255, 255, 1); 

您可以设置最后一个标准的透明度; 0代表完全透明,1代表不透明。因此,您应该采取以下措施来使您的背景变得透明:

text.setBackgroundColor("rgba(0, 0, 0, 0)");