Добавил еще ведущие нули к миллисекундам, если кому-то еще когда-то этот код понадобится
log = function (text, color, define){ var id, time, thread, logHtml, textLog; define = (typeof define == 'string') ? define.split(/[\s,.|:;]+/g) : define; if(typeof define === 'object' && define !== null){ if(Array.isArray(define)){ id = define.indexOf('id') > -1; time = define.indexOf('time') > -1; thread = define.indexOf('thread') > -1; } else{ id = define.id == true; time = define.time == true; thread = define.thread == true; } } else id = time = thread = true; id = id ? '<a href="action://action' + ScriptWorker.GetCurrentAction() + '" style="color:gray;">[' + ScriptWorker.GetCurrentAction() + ']</a>' : ''; time = time ? ' ' + getTime() : ''; thread = thread ? ' Поток №' + thread_number() : ''; logHtml = (id || time || thread) ? id + '<span style="color: white">' + time + thread + ' : </span>' : ''; logHtml += '<span style="color:' + (color ? color : 'white') + '">' + text + '</span>'; textLog = '[' + ScriptWorker.GetCurrentAction() + ']' + time + thread + ' : ' + text function getTime(){ var checkTime = function(i){ return (i < 10) ? "0" + i : i; }; var checkMilliSeconds = function(ms){ if (ms < 10) { return "00" + ms; } else if (ms < 100) { return "0" + ms; } else { return ms; } }; var d = new Date(); var hh = checkTime(d.getHours()); var mm = checkTime(d.getMinutes()); var ss = checkTime(d.getSeconds()); var ms = checkMilliSeconds(d.getMilliseconds()); return '[' + hh + ':' + mm + ':' + ss + '.' + ms + ']'; }; Logger.WriteHtml(logHtml, textLog); }Как изменить цвет ячейки в эксель/excel/xlsx/
-
Добрый день. Нашел на форуме, как производить запись данных в ячейку, но как при этом покрасить её в нужный цвет, так и не понял.
Вариант пробовал вот такой:
cell.style("fill", { type: "pattern", pattern: "darkDown", foreground: { rgb: "ff0000" }, background: { theme: 3, tint: 0.4 } });И вот такой:
cell.style("fill", "0000ff"); const fill = cell.style("fill"); /* fill is now set to: { type: "solid", color: { rgb: "0000ff" } } */И такой:
const RichText = require('xlsx-Populate').RichText; const cell = workbook.sheet(0).cell("A1"); // set a cell value to rich text cell.value(new RichText()); // add two rich text fragments cell.value() .add('hello ', { italic: true, bold: true }) .add('world!', { fontColor: 'FF0000' });Пробовал по разному, и прописывал пути к ячейке, и много ещё чего добавлял, удалял, но в итоге всегда получаю либо ошибку: ReferenceError: workbook is not defined
Либо ошибку: ReferenceError: cell is not defined
Отсюда вопрос:
Как в кубик nod.js, прописать код так, что бы разукрасить отдельную ячейку, с определенным текстом, либо текст я добавлю потом, если при этом форматирование не сотрется.
Хотелось бы увидеть пример полного когда, который в кубике должен быть.
Спасибо заранее! -
@green1987 Удалось самому решить вопрос.
для тек, кому нужно будет это, размещу пример кода, в котором показано как разукрасить фон ячейки.
Вариант 1 - сплошная заливка фона ячейки + пример занесения данных в ячейку, шрифтами, различного стиля, и цвета:const XlsxPopulate = require('xlsx-populate'); // Load a new blank workbook XlsxPopulate.fromBlankAsync() .then(workbook => { // цвет const RichText = require('xlsx-Populate').RichText; const cell = workbook.sheet(0).cell('A1'); // set a cell value to rich text cell.value(new RichText()); cell.style("fill", "0000ff"); const fill = cell.style("fill"); // add two rich text fragments cell.value() .add('hello ', { italic: true, bold: true }) .add('world!', { fontColor: 'FF0000' }); // цвет // Modify the workbook. workbook.sheet("Sheet1").cell("B1").value("This is neat!"); // Write to file. return workbook.toFileAsync("C:/content/out.xlsx"); });Вариант 2 - штрихованный фон ячейки + пример занесения данных в ячейку, шрифтами, различного стиля, и цвета:
const XlsxPopulate = require('xlsx-populate'); // Load a new blank workbook XlsxPopulate.fromBlankAsync() .then(workbook => { // цвет const RichText = require('xlsx-Populate').RichText; const cell = workbook.sheet(0).cell('A1'); // set a cell value to rich text cell.value(new RichText()); cell.style("fill", { type: "pattern", pattern: "darkDown", foreground: { rgb: "ff0000" }, background: { theme: 3, tint: 0.4 } }); // add two rich text fragments cell.value() .add('hello ', { italic: true, bold: true }) .add('world!', { fontColor: 'FF0000' }); // цвет // Modify the workbook. workbook.sheet("Sheet1").cell("B1").value("This is neat!"); // Write to file. return workbook.toFileAsync("C:/content/out.xlsx"); });