使用Google Java API设置单元格背景颜色和文本大小 [英] Set cell background color and text size using Google Java API
问题描述
我想设置电子表格单元格背景颜色和文本大小。我使用这个Java代码将文本设置到单元格中,但是我找不到如何设置样式的解决方案。
I want to set Spreadsheet cell background color and text size. I use this Java code to set the text into the cell but I can't find a solution how to set the style.
CellData setUserEnteredValue = new CellData()
.setUserEnteredValue(new ExtendedValue()
.setStringValue("cell text"));
有没有解决方法?
Is there any solution?
推荐答案
AFAIK在Java Spreadsheet API中不可行,您必须使用Apps脚本;
https://developers.google.com/apps-script/reference / spreadsheet /
AFAIK this is not possible in the Java Spreadsheet API, you instead have to use the Apps Script; https://developers.google.com/apps-script/reference/spreadsheet/
从他们的文档中,如何设置背景;
From their documentation, how to set the background;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange("B2:D5");
range.setBackground("red");
和如何设置字体大小;
and how to set the font size;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("B2");
cell.setFontSize(20);
更新
请参阅下面的flo5783的回答,现在v4提供了执行此操作的功能。
Update See flo5783's answer below, v4 now offers the ability to do this.
这篇关于使用Google Java API设置单元格背景颜色和文本大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!