FlexGrid for WinForms

Exporting grid to Excel doesn’t show cell borders

  •  dotmist said 1 year, 5 months ago:

    I’m exporting C1FlexGrid (2011v3) to Microsoft Excel using SaveExcel() method.
    Everything works fine, but cell borders in exported file are missing.
    And when I manually change border style in grid I get no effect in exported Excel file.
    What can I do to show cell borders in exported file?

  •  Ashish Jindal16p said 1 year, 5 months ago:

    Hello,

    This is the default behaviour of the flexgrid control because the styles used in the Flexgrid are very much different from the in-built styles of Microsoft Excel and hence, the styles are not mapped or reflected when we export Excel file.

    Hope it clarifies.

    Regards
    Ashish

  •  dotmist said 1 year, 5 months ago:

    Hello,

    I’m not speaking about any special styled borders. I just want to see where one fixed cell ends and the other starts. Nothing more. But now exported grid looks like it has one big fixed cell with no separations. And it’s really annoying. May be there are any workarounds?

    Regards,
    Dmitry.

  •  Wolfgang Knauf7p said 1 year, 5 months ago:

    Hi Dmitry,

    one possible workaround is to open the excel file using e.g. the "C1Excel" component (hope that it is included in your license). Then you could add the styles yourself.

    Here is a full code snippet to add

    C1XLBook excelBook = new C1XLBook();
    excelBook.Load(filename);
    
    XLSheet sheet = excelBook.Sheets[0];
    
    //set Linestyle of one specific cell. Note: if the cell has no "Style" property, we have to create it.
    XLCell currentCell = sheet[row, col];
    if (currentCell.Style == null)
    {
      currentCell.Style = new XLStyle(sheet.Book);
    }
    
    currentCell.Style.BorderColorTop = Color.Black;
    currentCell.Style.BorderTop = XLLineStyleEnum.Thick;
    
    //Save excel file in Excel97-2003 format:
    excelBook.Save (filename, FileFormat.Biff8);
    

    Hope this helps

    Wolfgang

  •  dotmist said 1 year, 5 months ago:

    Hi Wolfgang,

    Thank you very much for your proposal. Now I’m using Microsoft Excel Interop library for exporting data. And my main goal is to exclude it and to use built-in grid component. But if I use C1XLBook then I’ll have to change one exporting library to another. And I’ll have to redistribute this extra library with my project. I can’t say it’s a good deal :)

    Regards,
    Dmitry

  •  Wolfgang Knauf7p said 1 year, 5 months ago:

    Hi Dmitry,

    I think that a pure C1FlexGrid excel export will do a lot of the work, but there will always be limitations. So there might be no way around creating the Excel file yourself.

    C1Excel has the big benefit that you don’t need an Office installed, and it is pure .NET code. So it is an improvement compared to the Interop dlls.
    But unfortunately C1Excel has also a few limitations (e.g. performance when creating really large grids with a lot of formulas, and it does not support all excel features). If you send me a mail (wknauf AT hg MINUS online DOT de), I can tell you the name of another .NET excel library (unfortunately very expensive).

    Best regards

    Wolfgang

  •  Ashish Jindal16p said 1 year, 5 months ago:

    Hello Dmitry,

    A possible workaround for displaying border lines of the header cells is to set the BackColor property of the Fixed style to transparent. This is because when we apply color on the header cells then it is applied on its borders as well and excel does not recognise them, thereby, it removes the border lines of header cells.

    Here is the sample code for same:

    Color tempColor = c1FlexGrid1.Styles.Fixed.BackColor;
                c1FlexGrid1.Styles.Fixed.BackColor = Color.Transparent;
                c1FlexGrid1.SaveExcel("test.xlsx",  C1.Win.C1FlexGrid.FileFlags.AsDisplayed  | C1.Win.C1FlexGrid.FileFlags.IncludeFixedCells | C1.Win.C1FlexGrid.FileFlags.OpenXml  );
                c1FlexGrid1.Styles.Fixed.BackColor= tempColor ;
    

    Hope it helps.

    Regards
    Ashish

  •  dotmist said 1 year, 5 months ago:

    @ashishjindal, thank you. I’ll try this method but may be this issue can be marked as a bug/feature for the next release?

  •  Ashish Jindal16p said 1 year, 5 months ago:

    Hello Dmitry,

    I have made an enhancement request to support exporting of border styles along with data in Excel to the developer, however, I cannot commit as to when/if it would be taken into consideration.

    Regards
    Ashish

  •  dotmist said 1 year, 5 months ago:

    Hello Ashish,

    Thank you very much for your participation. I’ll be waiting for the implementation of the issue.

    Regards,
    Dmitry

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.