Skip to content
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

When I update a cell, how do I make it preserve the style it had? #47

Open
MiniSuperDev opened this issue Apr 22, 2023 · 1 comment
Open

Comments

@MiniSuperDev
Copy link

For example I have a cell with a blue background, when I update using decoder.updateCell('Sheet1', 0, 0, 1337); the cell data is updated but the style of the cell is eliminated (the background in white/none).
Thank you

@aaltynbek
Copy link

aaltynbek commented Apr 12, 2024

Hello here, I've updated code of library for this
in xlsx.dart updated method _replaceCell, then updated _createCell for catching this style
`
static XmlElement _replaceCell(XmlElement row, XmlElement? lastCell,
int columnIndex, int rowIndex, dynamic value) {
var index = lastCell == null ? 0 : row.children.indexOf(lastCell);
int? styleId = lastCell?.getAttribute('s') != null
? int.tryParse(lastCell!.getAttribute('s')!)
: null;

var cell = _createCell(columnIndex, rowIndex, value, styleId: styleId);

row.children
  ..removeAt(index)
  ..insert(index, cell);
return cell;

}

static XmlElement _createCell(int columnIndex, int rowIndex, dynamic value,
{int? styleId}) {
var attributes = [
XmlAttribute(
XmlName('r'), '${numericToLetters(columnIndex + 1)}${rowIndex + 1}'),
XmlAttribute(XmlName('t'), 'inlineStr'),
];
if (styleId != null) {
attributes.add(XmlAttribute(XmlName('s'), styleId.toString()));
}

var children = value == null
    ? <XmlElement>[]
    : <XmlElement>[
        XmlElement(XmlName('is'), [], [
          XmlElement(XmlName('t'), [], [XmlText(value.toString())])
        ]),
      ];
return XmlElement(XmlName('c'), attributes, children);

}
`

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

No branches or pull requests

3 participants