How to disable gridlines in Excel using open xml C#?

后端 未结 2 361
不思量自难忘°
不思量自难忘° 2021-01-14 18:41

I want to disable GridLines in excel and put custom borders to excel cells using open xml in C#

I have tried with below code but is throwing exception when i open th

2条回答
  •  走了就别回头了
    2021-01-14 19:04

    I tried this way but it was failing but able to identify what is missing. By default when creating a spreadsheet from scratch, there is no default workbook view. So need to create new workbook view.

    spreadSheet.WorkbookPart.Workbook = new Workbook(new BookViews(new WorkbookView()));
    

    Then create sheet view.

    worksheetPart.Worksheet = new Worksheet(new SheetViews(new SheetView(){WorkbookViewId=0,ShowGridLines=new BooleanValue(false)}), new SheetData());
    

    NOTE: When create columns in the excel workbook, the elements should be created in a sequence. The sequence is

    • Sheet Views
    • Sheet View Formatting
    • Columns
    • Sheet Data

    Enjoy Open XML SDK but Microsoft does not provide very powerfull documentation.

提交回复
热议问题