Skip to content

如何设置单个单元格样式 #729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zccoding opened this issue Feb 2, 2025 · 6 comments
Open

如何设置单个单元格样式 #729

zccoding opened this issue Feb 2, 2025 · 6 comments

Comments

@zccoding
Copy link

zccoding commented Feb 2, 2025

在X-Spreadsheet版本:1.1.9里面,有大佬知道如何设置指定(知道行和列)单元格的样式么(比如背景颜色之类的)?

@zccoding
Copy link
Author

zccoding commented Feb 2, 2025

已解决,请忽略

@gogocomeon
Copy link

怎么解决的

@gogocomeon
Copy link

.loadData({
rows: {
0: { cells: { 0: { text: 'A1', style: 0 },1: { text: 'B1', style: 0 },2: { text: 'C1', style: 0 },3: { text: 'D1', style: 0 },4: { text: 'E1', style: 0 },5: { text: 'F1', style: 0 },6: { text: 'G1', style: 0 },7: { text: 'H1', style: 0 } } },
},
styles: [
{
bgcolor: '#94d1fa'
},{
bgcolor: '#d00cee'
}]})

@yuan1003
Copy link

yuan1003 commented Apr 1, 2025

在X-Spreadsheet版本:1.1.9里面,有大佬知道如何设置指定(知道行和列)单元格的样式么(比如背景颜色之类的)?
大佬 咋解决的

@zccoding
Copy link
Author

zccoding commented Apr 2, 2025

在X-Spreadsheet版本:1.1.9里面,有大佬知道如何设置指定(知道行和列)单元格的样式么(比如背景颜色之类的)?
大佬 咋解决的

我是vue2哈,下面相关代码:
var bgcolor_ix = this.spreadsheet.datas[0].addStyle({ "bgcolor": bgcolor });
var errcell = this.spreadsheet.datas[0].getCell(cell.row, cell.col);
errcell.style = bgcolor_ix;
this.spreadsheet.reRender();

@zccoding
Copy link
Author

zccoding commented Apr 2, 2025

怎么解决的
可以试试这个:
this.highlightCell(this.highlightedCells[0], '#c4dace'); // 高亮当前单元格
highlightCell (cell, bgcolor) {
var bgcolor_ix = this.spreadsheet.datas[0].addStyle({ "bgcolor": bgcolor });
var errcell = this.spreadsheet.datas[0].getCell(cell.row, cell.col);
if (!errcell) {
this.spreadsheet.cellText(cell.row, cell.col, '');
errcell = this.spreadsheet.datas[0].getCell(cell.row, cell.col);
}

  errcell.style = bgcolor_ix;
  this.spreadsheet.reRender();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants