【发布时间】:2021-07-20 11:01:56
【问题描述】:
我正在使用谷歌文档和驱动 API 生成一些报告。我想根据数字的高低动态设置表格单元格中的背景颜色,数字越低越红,数字越高越绿。
看看这个例子:
我可以像这样从我的节点服务更新数字:
const auth = new google.auth.GoogleAuth({
keyFile: 'credentials.json',
scopes: ['https://www.googleapis.com/auth/documents', 'https://www.googleapis.com/auth/drive']
});
// Create client instance for auth
const client = await auth.getClient();
const docs = google.docs({ version: 'v1', auth: client });
const drive = google.drive({ version: 'v3', auth: client });
const copyMetaData = {
name: `Some report`,
parents: ['1b78gdfgdf8gdiokkg4XG2-9WFWGGla'] // some folder id
};
const copiedFile = await drive.files.copy({
auth,
fileId: '1VMKs89fg9AGP1xs-1F545gKgkvf2Daza7UZMRsdf789', // some file id
requestBody: copyMetaData
});
const requests = [
['{{data-1}}', '447'],
['{{data-2}}', '378'],
['{{data-3}}', '102'],
['{{data-1-p}}', '91'],
['{{data-2-p}}', '78'],
['{{data-3-p}}', '23']
].map(update => {
const [handleBar, replaceText] = update;
return {
replaceAllText: {
containsText: {
text: handleBar,
matchCase: true
},
replaceText
}
};
我只是不知道如何设置背景颜色,甚至无法识别表格单元格。或者这是否可能,但这对我来说似乎是一个非常微不足道的用例,因为在所有谷歌的例子中他们正在生成发票,你很容易认为有人想要将负余额加粗和红色,但是但如果是正余额,例如黑色。
【问题讨论】:
标签: javascript google-drive-api google-docs google-docs-api