This project has moved. For the latest updates, please go here.
1
Vote

copying font from one cell to another doesn't function

description

I want to copy the style from one cell to another.

My code:
_ws.Cells[rowTarget, icol].Style.Font = _ws.Cells[rowSource, icol].Style.Font;
_ws.Cells[rowTarget, icol].Style.Fill = _ws.Cells[rowSource, icol].Style.Fill;
_ws.Cells[rowTarget, icol].Style.Border = _ws.Cells[rowSource, icol].Style.Border;
_ws.Cells[rowTarget, icol].Style.HorizontalAlignment = _ws.Cells[rowSource, icol].Style.HorizontalAlignment;
_ws.Cells[rowTarget, icol].Style.Indent = _ws.Cells[rowSource, icol].Style.Indent;
_ws.Cells[rowTarget, icol].Style.Numberformat = _ws.Cells[rowSource, icol].Style.Numberformat;
_ws.Cells[rowTarget, icol].Style.TextRotation = _ws.Cells[rowSource, icol].Style.TextRotation;
_ws.Cells[rowTarget, icol].Style.VerticalAlignment = _ws.Cells[rowSource, icol].Style.VerticalAlignment;
_ws.Cells[rowTarget, icol].Style.WrapText = _ws.Cells[rowSource, icol].Style.WrapText;

After executing
_ws.Cells[rowTarget, icol].Style.Font = _ws.Cells[rowSource, icol].Style.Font;

I notice that the font hasn't changed.
_ws.Cells[rowSource, icol] has been formatted using Excel. The file is an xlsx file.

I have tried to copy the style using StyleId or StyleName, neither work.

comments