Posted 11 December 2023, 12:30 pm EST - Updated 11 December 2023, 12:33 pm EST
Hello SpreadJS community,
I hope you’re all doing well. I’m currently working with SpreadJS, and I’ve encountered an issue while trying to merge cell styles using the example provided in the documentation https://developer.mescius.com/spreadjs/docs/features/cells/styles.
I’ve followed the steps outlined in the documentation, but it seems that the two styles never merge as expected. When I log the styles of the cell, only the last style is listed.
Here’s the code snippet I’m using:
on file load
const estilosProjecao: GC.Spread.Sheets.Style[] = [
montarEstiloGlobalCelulaNormalProjecao(),
montarEstiloGlobalLancamentoProcessadoProjecao(),
];
estilosProjecao.forEach((estilo) => {
workbook.addNamedStyle(estilo);
});
function montarEstiloGlobalCelulaNormalProjecao(estiloPersonalizado?: EstiloPersonalizado): GC.Spread.Sheets.Style {
const estilo = new GC.Spread.Sheets.Style();
estilo.locked = false;
estilo.foreColor = '#000';
estilo.backColor = '#fff';
estilo.vAlign = GC.Spread.Sheets.VerticalAlign.center;
estilo.name = EnumEstilosProjecao.celulaNormal;
estilo.applyFill = false;
if (estiloPersonalizado) {
atualizarEstiloComEstiloPersonalizado(estilo, estiloPersonalizado);
}
return estilo;
}
function montarEstiloGlobalLancamentoProcessadoProjecao(): GC.Spread.Sheets.Style {
const estilo = new GC.Spread.Sheets.Style();
estilo.locked = false;
estilo.foreColor = COR_LANCAMENTO_PROCESSADO_FONTE;
estilo.backColor = COR_LANCAMENTO_PROCESSADO_FUNDO;
estilo.vAlign = GC.Spread.Sheets.VerticalAlign.center;
estilo.name = EnumEstilosProjecao.lancamentoProcessado;
estilo.applyAlignment = false;
return estilo;
}
on a button click
console.log('estilos: ', pagina.getNamedStyles()); //allways empty :(
const celula = pagina.getCell(info.row, info.col);
celula.setStyleName(EnumEstilosProjecao.lancamentoProcessado);
console.log('estilo adiconado:', pagina.getStyle(info.row, info.col, GC.Spread.Sheets.SheetArea.viewport));
the text on the example implies that i can use the font of one named styles and the aligment of another, yet it wont work
pagina.getNamedStyles() allways return empty, I even verify if the styles exist, and if they don’t I add then back up (for older files, that don’t have the style names yet)