When copying from another program to excel onlyoffice, the data is copied to cells, not in date and number format
wrote a macro for converting with a call to the combination of keys ctrl + Q and made an autorun for this macro:
(function()
{
var oWorksheet = Api.GetActiveSheet();// Получаем текущий лист
var range_date = oWorksheet.GetRange("C2:C6000"); // Объявляем переменную приравниваем ее к отбору по ячейке для даты
var range_number = oWorksheet.GetRange("D2:E6000"); // Объявляем переменную приравниваем ее к отбору по ячейке для числа
document.onkeydown=function(e){
var button = button || window.event; // для IE, чтобы закрыть объект-событие окна IE
if(button.ctrlKey && button.which == 81) { // при нажатии на ctrl + Q
alert('Макрос по кнопке!');
// цикл по ячейкам дата
range_date.ForEach(x => {
x.SetNumberFormat("d/m/yy"); // изменяем формат ячейки на дата
});
// цикл по ячейкам число
range_number.ForEach(x => {
var value_number = x.GetValue(); // Объявляем переменную приравнивается к замене
if(value_number === null || value_number === ""){ // если переменная равна 0 и пустая
return; // пропускаем
}
else{ // если нет приводим ее к числовому формату
//console.log("ДО " + value_number);
value_number = value_number.replace(/\s/g, ""); // переменная приравнивается к замене пробела на пусто
//console.log("Убираем пробел " + value_number);
value_number = value_number.replace(/,/g, "."); // переменная приравнивается к замене запятой на точку
//console.log("Меняем запятую на точку " + value_number);
value_number = Number(value_number); // переменная приравнивается к числовому значению
//console.log(value_number);
x.SetValue(value_number); // выводим переменную
//console.log("Получаем: " + value_number);
x.SetNumberFormat("0.00"); // изменяем формат ячейки на числовой и форматируем под определенный вид числа
}
});
Api.Save();
return false;
}
};
})();
when you press ctrl + Q, the browser freezes for a few seconds and works, but the data on the sheet is not automatically updated cleanly solved the problem Api.Avtosave (); after the macro runs, you can scroll and the data will be corrected, is there any way to automatically update the data? except for updating the sheet?
If you run a macro without a button, then everything works almost instantly
tell me how correct the code is and how you can make the loop go through only the cells in which there is information, I tried to do this:
(function()
{
var oWorksheet = Api.GetActiveSheet();// Получаем текущий лист
var startRow = 2;
var endRow = 1000;
var column = "C";
var count = 1; // для проверки сколько строк пройдет
for(var i = startRow; i < endRow; ++i) {
var range = oWorksheet.GetRange(column + i);
if(range.GetValue() !== null && range.GetValue() !== "") {
count += 1;
range.SetNumberFormat("dd/mm/yyyy");
console.log("Cтрока № " + count + " " + range);
}
else {
break;
}
}
alert('Макрос закончил');
})();
but only after updating the sheet by F5, correct date data appears
macro excel
Re: macro excel
Hi!
Dear Kristofer,
Pl tell me how you run the macros. Did you run it via embedded editor in the Plugin section or the another way?
Dear Kristofer,
Pl tell me how you run the macros. Did you run it via embedded editor in the Plugin section or the another way?