Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
35
How to read one Excel and output to another Excel keeping partial formatting?
posted

Hi,

Is there a way to read from one Excel with Infragistics and output the same data to another Excel, while keeping the exact same formatting as the original? For example, if part of the text has strikethrough (see above, circle added by me) or some of the text is black and some is red, how do I end up with the same visual effect in the new spreadsheet I'm writing to? Thanks!

Alex

Parents Reply
  • 22852
    Offline posted in reply to Alex Bratu

    Alex,

    The cell's value in this scenario is a FormattedString and to apply that to another cell you would first need to clone the FormattedString.  For example the following will duplicate the FormattedString in the third row of the file in the sample I provided:

    static void Main(string[] args)
    {
        Workbook wb = Workbook.Load("Book1.xlsx");
        FormattedString formattedString = wb.Worksheets[0].Rows[0].Cells[0].Value as FormattedString;
        wb.Worksheets[0].Rows[2].Cells[0].Value = formattedString.Clone();
        wb.Save("output.xlsx");
    }

    If you want to dynamically create the Formatted String, you you would pass the string to format into the constructor for FormattedString and use GetFont to get the FormattedStringFont object where you can set the Strikeout to true:

    wb.Worksheets[0].Rows[4].Cells[0].Value = newFormattedString;
    FormattedStringFont formattedFont = newFormattedString.GetFont(35, 6);
    formattedFont.Strikeout = ExcelDefaultableBoolean.True;

    Let us know if you have any questions.

Children